/* Яша — веб-интерфейс.
   Тёплая палитра под характер бота: не «корпоративный ассистент», а домашний
   дух. Мобильный первым делом — чаще всего сюда заходят с телефона. */

:root {
  --bg: #f4f1ec;
  --bg-soft: #ece7df;
  --card: #fffdfa;
  --ink: #241f1a;
  --ink-soft: #6d635a;
  --line: #ddd5c9;
  --accent: #b4591f;
  --accent-ink: #fff;
  --me: #e5dcd955;
  --shadow: 0 1px 2px rgb(36 31 26 / 8%), 0 8px 24px rgb(36 31 26 / 6%);
  --radius: 16px;
}

:root[data-theme="dark"] {
  --bg: #14161c;
  --bg-soft: #1b1e26;
  --card: #1f232c;
  --ink: #e9e5df;
  --ink-soft: #9a9289;
  --line: #2c313c;
  --accent: #e0873f;
  --accent-ink: #1a1207;
  --me: #2a2f3a;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

/* ───────────────────────────── вход ───────────────────────────── */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px 24px;
  text-align: center;
}

.login-mark { font-size: 44px; line-height: 1; }
.login-card h1 { margin: 12px 0 0; font-size: 24px; font-weight: 650; }
.login-sub { margin: 4px 0 24px; color: var(--ink-soft); font-size: 14px; }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.field input {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.primary {
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 11px;
}
.primary:disabled { opacity: .55; cursor: default; }

.login-error {
  margin: 14px 0 0;
  font-size: 14px;
  color: #d9483b;
}

/* ───────────────────────────── каркас ───────────────────────────── */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100dvh;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who .mark { font-size: 26px; }
.who strong { display: block; font-size: 15px; font-weight: 650; }
.who small { display: block; font-size: 12px; color: var(--ink-soft); }

.bar-actions { display: flex; gap: 2px; }

.icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 17px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}
.icon:hover { background: var(--bg-soft); color: var(--ink); }
.icon[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ───────────────────────────── лента ───────────────────────────── */

.feed {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { max-width: min(78ch, 92%); }
.msg.user { align-self: flex-end; }
.msg.bot, .msg.system { align-self: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--me);
  border-color: transparent;
  border-bottom-right-radius: 6px;
}
.msg.bot .bubble { border-bottom-left-radius: 6px; }
.msg.system .bubble {
  background: transparent;
  border-style: dashed;
  color: var(--ink-soft);
  font-size: 14px;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9em;
  background: var(--bg-soft);
  padding: 1px 5px;
  border-radius: 5px;
}
.bubble pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: 10px;
  overflow-x: auto;
}
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--accent); }

.stamp {
  margin: 3px 4px 0;
  font-size: 11px;
  color: var(--ink-soft);
}
.msg.user .stamp { text-align: right; }

.shot {
  display: block;
  margin-top: 8px;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.msg audio { margin-top: 8px; width: 100%; max-width: 320px; }

.chip {
  display: inline-block;
  margin: 4px 4px 0 0;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border-radius: 20px;
}

/* курсор набора у стримящегося ответа */
.typing::after {
  content: "▍";
  margin-left: 1px;
  opacity: .5;
  animation: blink 1.1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.status {
  padding: 0 18px 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ─────────────────────────── поле ввода ─────────────────────────── */

.composer {
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.composer-row { display: flex; align-items: flex-end; gap: 4px; }

#input {
  flex: 1;
  min-height: 40px;
  max-height: 40vh;
  padding: 9px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  outline: none;
  resize: none;
}
#input:focus { border-color: var(--accent); }

.send {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  font-size: 19px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
}
.send:disabled { opacity: .4; cursor: default; }

.icon.recording {
  background: #d9483b;
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .55; } }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 8px; }
.att {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  font-size: 13px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.att button { color: var(--ink-soft); padding: 0 4px; }

/* ──────────────────────── напоминалки ──────────────────────── */

.sheet {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  display: grid;
  place-items: end center;
  z-index: 20;
}
.sheet-card {
  width: 100%;
  max-width: 560px;
  max-height: 82dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
}
@media (min-width: 560px) {
  .sheet { place-items: center; }
  .sheet-card { border-radius: var(--radius); }
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 17px; }

.cron-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.cron {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.cron-body { flex: 1; min-width: 0; }
.cron-when {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--accent);
}
.cron-text { font-size: 14px; overflow-wrap: anywhere; }
.cron-off { opacity: .5; }

.sheet-hint { margin: 0; font-size: 13px; color: var(--ink-soft); }
.empty { padding: 20px 0; text-align: center; color: var(--ink-soft); font-size: 14px; }
