:root {
  --bg: #0e0f12;
  --card: #17191f;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f1ea;
  --muted: #9a9588;
  --gold: #e2c48a;
  --gold-dim: #c4a56a;
  --danger: #ff8b7a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --drawer-w: 280px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 Manrope, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(226, 196, 138, 0.08), transparent 55%),
    var(--bg);
}
[hidden] { display: none !important; }
.screen { min-height: 100dvh; padding: 20px 18px 28px; }
.eyebrow {
  margin: 0;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--gold);
  font-weight: 600;
}
h1 {
  margin: 6px 0 0;
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}
h2 { margin: 0; font-size: 1.2rem; font-weight: 650; }
.hint, .meta { color: var(--muted); font-size: 0.92rem; }

/* ---------- Пароль ---------- */
.pin-wrap { position: relative; max-width: 360px; margin: 18vh auto 0; text-align: center; }
.pin-wrap h1 { margin-bottom: 8px; }
.pin { display: flex; justify-content: center; gap: 10px; margin: 28px 0 8px; }
.pin i {
  width: 52px; height: 64px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; font-size: 1.4rem; color: var(--gold);
}
.pin i.on::after {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--gold);
}
#pin {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%;
  border: 0; caret-color: transparent;
}

/* ---------- Каркас ---------- */
.app-shell { position: relative; min-height: 100dvh; }
.main {
  display: flex; flex-direction: column; min-height: 100dvh;
  max-width: 720px; margin: 0 auto; padding: 0 14px calc(14px + var(--safe-bot));
}

/* ---------- Шапка ---------- */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + var(--safe-top)) 0 12px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.top-title { flex: 1; min-width: 0; }
.top-title h1 { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title .eyebrow { font-size: 0.6rem; }
.icon-btn {
  width: 42px; height: 42px; flex: none; border: 1px solid var(--line);
  background: var(--card); color: var(--gold); border-radius: 12px;
  font-size: 1.15rem; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:active { background: #22252c; }

/* ---------- Боковое меню ---------- */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--drawer-w);
  background: #12141a; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 20;
  padding: calc(14px + var(--safe-top)) 12px calc(14px + var(--safe-bot));
  transform: translateX(-100%); transition: transform 0.22s ease;
}
.drawer:not([hidden]) { transform: translateX(0); }
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 15;
}
.drawer-head { margin-bottom: 12px; }
.new-chat {
  width: 100%; height: 46px; border: 1px solid rgba(226, 196, 138, 0.35);
  background: rgba(226, 196, 138, 0.08); color: var(--gold);
  border-radius: 12px; font: inherit; font-weight: 650; cursor: pointer;
}
.new-chat:active { background: rgba(226, 196, 138, 0.16); }
.drawer-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.16em;
  color: var(--muted); margin: 8px 4px;
}
.drawer-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.drawer-empty { color: var(--muted); font-size: 0.88rem; padding: 8px 4px; }
.session-item {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  padding: 9px 10px; cursor: pointer; color: var(--text); font: inherit;
}
.session-item:active { background: #1c1f26; }
.session-item.on { background: #22252c; border-color: var(--line); }
.session-title { font-weight: 600; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-preview { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-date { font-size: 0.7rem; color: var(--muted); opacity: 0.7; }
.drawer-foot { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 8px; }
.drawer-link {
  width: 100%; text-align: left; background: transparent; border: 0;
  color: var(--gold-dim); font: inherit; font-weight: 600; padding: 10px 6px;
  border-radius: 10px; cursor: pointer;
}
.drawer-link:active { background: #1c1f26; }

/* ---------- Композатор и главная ---------- */
.composer { display: flex; gap: 8px; align-items: center; }
.composer input {
  flex: 1; min-width: 0; height: 48px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); border-radius: 14px;
  padding: 0 14px; font: inherit; outline: none;
}
.composer input:focus { border-color: rgba(226, 196, 138, 0.45); }
.composer input:disabled { opacity: 0.6; }
.composer button, .file-btn {
  height: 48px; border: 0; border-radius: 14px; font: inherit; font-weight: 650; cursor: pointer;
}
.composer button { background: var(--gold); color: #1a1408; padding: 0 16px; }
.file-btn {
  width: 48px; display: grid; place-items: center; background: var(--card);
  color: var(--gold); border: 1px solid var(--line); font-size: 1.2rem;
}
.ingest { margin-bottom: 10px; }
.home { padding-top: 6px; }
.home-hint { color: var(--muted); font-size: 0.9rem; margin-top: 18px; text-align: center; }
.status { color: var(--muted); margin: 8px 0 0; font-size: 0.88rem; }
.status.error { color: var(--danger); }

/* ---------- Вкладки ---------- */
.tabs {
  display: flex; gap: 6px; margin: 16px 0 12px; padding: 4px;
  background: var(--card); border-radius: 14px; border: 1px solid var(--line);
}
.tabs button {
  flex: 1; height: 36px; border: 0; background: transparent; color: var(--muted);
  border-radius: 11px; font: inherit; font-weight: 600; cursor: pointer;
}
.tabs button.on { background: #22252c; color: var(--text); }

.prose, .transcript {
  white-space: pre-wrap; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px; margin: 0;
}
.prose.empty { color: var(--muted); }
.transcript {
  font-size: 0.86rem; color: #d8d3c8;
  max-height: calc(100dvh - 240px); overflow: auto;
}
.row-actions { display: flex; gap: 8px; margin-top: 12px; }
.ghost {
  background: transparent; color: var(--gold-dim); border: 1px solid var(--line);
  border-radius: 12px; height: 40px; padding: 0 12px; font: inherit; font-weight: 600; cursor: pointer;
}

/* ---------- Чат ---------- */
.chat-panel {
  display: flex; flex-direction: column; min-height: calc(100dvh - 230px);
}
.chat {
  flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px;
}
.bubble {
  max-width: 92%; padding: 10px 12px; border-radius: 14px; white-space: pre-wrap;
  background: var(--card); border: 1px solid var(--line); line-height: 1.5;
}
.bubble.user { align-self: flex-end; background: #2a2418; border-color: rgba(226, 196, 138, 0.2); }
.bubble.assistant { align-self: flex-start; }
.bubble.thinking { color: var(--muted); }
.chat-panel .composer { margin-top: auto; }
button:disabled { opacity: 0.55; }
.meta { margin: 0 0 10px; }

/* ---------- Модальные окна ---------- */
.modal-screen {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  display: flex; flex-direction: column;
}
.modal {
  display: flex; flex-direction: column; min-height: 100dvh;
  max-width: 720px; margin: 0 auto; width: 100%;
  padding: calc(14px + var(--safe-top)) 14px calc(18px + var(--safe-bot));
}
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.modal-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 10px 12px; font: inherit; outline: none; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: rgba(226, 196, 138, 0.45); }
.field textarea { font-size: 0.86rem; line-height: 1.45; min-height: 90px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.primary {
  height: 46px; border: 0; border-radius: 12px; background: var(--gold); color: #1a1408;
  font: inherit; font-weight: 650; padding: 0 20px; cursor: pointer;
}

/* --- TG Panel Styles --- */
.tg-panel { display: flex; flex-direction: column; gap: 14px; }
.tg-step { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.tg-step h3 { margin: 0 0 4px; font-size: 1.05rem; }
.tg-step .hint { margin: 0 0 12px; font-size: 0.85rem; }
.tg-step .composer { margin-top: 4px; }

.tg-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tg-header h3 { margin: 0; font-size: 1.1rem; }
.tg-user { font-size: 0.8rem; color: var(--muted); }

.tg-source-selector { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.tg-mode-tabs { display: flex; background: #111318; border-bottom: 1px solid var(--line); }
.tg-mode-tabs button { flex: 1; height: 40px; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.tg-mode-tabs button.on { color: var(--gold); background: var(--card); }
.tg-mode-content { padding: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tg-mode-content .composer { flex: 1; min-width: 200px; }
.tg-mode-content .file-btn { width: auto; padding: 0 12px; }
.tg-mode-content input[type="number"] { width: 70px; text-align: center; }

.tg-dialogs-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.tg-dialogs-toolbar input[type="search"] { flex: 1; min-width: 160px; height: 36px; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 10px; padding: 0 10px; font: inherit; }
.tg-dialogs-toolbar .toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; cursor: pointer; }

.tg-dialogs-list { max-height: 40vh; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.tg-dialog-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.tg-dialog-item:hover { border-color: rgba(226,196,138,0.3); background: #16181e; }
.tg-dialog-item.selected { border-color: var(--gold); background: #231f12; }
.tg-dialog-item input[type="checkbox"] { accent-color: var(--gold); width: 18px; height: 18px; }
.tg-dialog-info { flex: 1; min-width: 0; }
.tg-dialog-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-dialog-meta { font-size: 0.75rem; color: var(--muted); display: flex; gap: 10px; }
.tg-dialog-type { text-transform: uppercase; font-size: 0.65rem; letter-spacing: 0.05em; padding: 1px 6px; border-radius: 4px; background: #22252c; color: var(--gold-dim); }
.tg-dialog-type.channel { background: #1a2a1a; }
.tg-dialog-type.group { background: #2a1a1a; }

.tg-messages-preview { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.tg-messages-preview h4 { margin: 0 0 10px; font-size: 0.9rem; }
.tg-messages-list { max-height: 25vh; overflow: auto; margin-bottom: 10px; }
.tg-msg-item { font-size: 0.8rem; padding: 6px 8px; border-radius: 8px; background: var(--bg); margin-bottom: 4px; border-left: 3px solid transparent; }
.tg-msg-item:hover { border-left-color: var(--gold-dim); }
.tg-msg-date { color: var(--muted); font-size: 0.7rem; margin-right: 8px; }
.tg-msg-text { color: var(--text); white-space: pre-wrap; word-break: break-word; }
.tg-actions { display: flex; gap: 8px; }
.tg-actions .primary { background: var(--gold); color: #1a1408; border: 0; border-radius: 10px; height: 40px; padding: 0 16px; font: inherit; font-weight: 650; cursor: pointer; flex: 1; }
.tg-actions .ghost { flex: 1; }

.tg-analysis { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.tg-analysis-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #111318; }
.tg-analysis-header h4 { margin: 0; font-size: 0.9rem; }
.tg-analysis-text { padding: 16px; }

.tg-chat { display: flex; flex-direction: column; min-height: 40vh; background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.tg-chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.tg-chat .composer { padding: 12px 16px; border-top: 1px solid var(--line); background: #111318; }

.primary:disabled { opacity: 0.55; }
