/* Совещания — спокойная читаемая вёрстка; тема по системе (prefers-color-scheme). */

:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-2: #f1f1ee;
  --text: #1f2328;
  --muted: #646a73;
  --line: #e2e2dd;
  --accent: #2f6fdb;
  --accent-soft: #e6eefc;
  --on-accent: #ffffff;
  --mark: #fff2b3;
  --ok: #1e7a3e;
  --ok-soft: #e5f4ea;
  --err: #b42318;
  --err-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel: #1f2023;
    --panel-2: #26282c;
    --text: #e6e6e3;
    --muted: #9aa0a8;
    --line: #34363b;
    --accent: #7aa7ff;
    --accent-soft: #233148;
    --on-accent: #0d1420;
    --mark: #5a4b12;
    --ok: #6fd08f;
    --ok-soft: #1c3324;
    --err: #ff8a80;
    --err-soft: #3d1f1d;
    --warn: #f2c46b;
    --warn-soft: #3a2f17;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }

button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  line-height: 1.3;
}
button:hover { background: var(--panel-2); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--err); }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
.linkbtn:hover { background: none; text-decoration: underline; }
.iconbtn { display: inline-flex; align-items: center; padding: 6px; border-radius: 8px; color: var(--muted); }
.iconbtn:hover { background: var(--panel-2); color: var(--text); }

input[type=text], input[type=password], input[type=date], textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.small { font-size: 14px; }
.err { color: var(--err); }
.ok { color: var(--ok); }

/* ── шапка ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; color: var(--text); }
.crumb { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spacer { flex: 1; }

/* ── вход ──────────────────────────────────────────────────────────────── */
.login {
  max-width: 360px; margin: 14vh auto 0; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.login h1 { margin: 0 0 6px; font-size: 22px; }
.login button { width: 100%; margin-top: 14px; }
.login .msg { min-height: 1.6em; margin-top: 10px; font-size: 14px; }

/* ── блокноты ──────────────────────────────────────────────────────────── */
.page { max-width: 1040px; margin: 0 auto; padding: 24px 16px 48px; }
.page h1 { font-size: 24px; margin: 0 0 18px; font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 6px;
  min-height: 132px; padding: 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; text-align: left;
}
.card:hover { border-color: var(--accent); background: var(--panel); }
.card .name { font-weight: 600; font-size: 17px; word-break: break-word; }
.card .meta { color: var(--muted); font-size: 14px; }
.card .actions { margin-top: auto; display: flex; gap: 4px; }
.card .actions button { padding: 3px 8px; font-size: 13px; border-color: transparent; background: none; color: var(--muted); }
.card .actions button:hover { color: var(--text); background: var(--panel-2); }
.card.new { align-items: center; justify-content: center; color: var(--accent); border-style: dashed; font-weight: 500; }
.newform { display: flex; gap: 8px; width: 100%; }

/* ── блокнот ───────────────────────────────────────────────────────────── */
.nb { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.pane-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); min-height: 52px;
}
.pane-head h2 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.sources { background: var(--panel); border-right: 1px solid var(--line); }
.src-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.src {
  display: flex; gap: 6px; align-items: flex-start;
  padding: 10px; border-radius: 8px; cursor: pointer;
}
.src:hover, .src.active { background: var(--panel-2); }
.src .body { flex: 1; min-width: 0; }
.src .title { word-break: break-word; line-height: 1.4; }
.src .date { color: var(--muted); font-size: 13px; }
.src .error { color: var(--err); font-size: 13px; margin-top: 2px; word-break: break-word; }
.src .del { border: 0; background: none; color: var(--muted); padding: 2px 6px; visibility: hidden; }
.src:hover .del, .src .del:focus { visibility: visible; }
@media (hover: none) { .src .del { visibility: visible; } }
.badge {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px;
  background: var(--panel-2); color: var(--muted); margin-left: 4px; white-space: nowrap;
}
.badge.ready { background: var(--ok-soft); color: var(--ok); }
.badge.error { background: var(--err-soft); color: var(--err); }
.badge.indexing, .badge.queued { background: var(--warn-soft); color: var(--warn); }
.empty { padding: 24px 16px; color: var(--muted); font-size: 15px; }

.chat-log { flex: 1; overflow-y: auto; padding: 20px 16px; }
.chat-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg-user {
  align-self: flex-end; max-width: 85%;
  background: var(--accent-soft); padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap; word-break: break-word;
}
.msg-bot { align-self: stretch; }
.msg-bot .text { white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.msg-bot.failed .text { color: var(--err); }
.flag {
  font-size: 14px; padding: 6px 10px; border-radius: 8px; margin-bottom: 8px;
  background: var(--warn-soft); color: var(--warn);
}
.fn {
  display: inline-block; vertical-align: super; font-size: 11px; line-height: 1;
  padding: 2px 5px; margin: 0 1px; border-radius: 6px; border: 0;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.fn:hover, .fn.on { background: var(--accent); color: var(--on-accent); }
.cites { list-style: none; padding: 0; margin: 10px 0 0; font-size: 14px; }
.cites li { margin: 2px 0; }
.cites button { border: 0; background: none; padding: 2px 0; color: var(--muted); text-align: left; }
.cites button:hover { color: var(--text); background: none; }
.cites .nolink { color: var(--muted); }
details.unverified { margin-top: 10px; font-size: 14px; color: var(--muted); }
details.unverified summary { cursor: pointer; }
details.unverified li { margin: 4px 0; }
.thinking { color: var(--muted); font-style: italic; }

.composer { border-top: 1px solid var(--line); padding: 12px 16px; background: var(--bg); }
.composer form { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 180px; resize: none; }

/* карточка цитаты */
.cite-card {
  position: fixed; z-index: 30; width: min(420px, calc(100vw - 24px));
  max-height: 60vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px;
}
.cite-card .head { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.cite-card .line { margin: 6px 0; line-height: 1.5; }
.cite-card .who { color: var(--muted); font-size: 13px; }
.cite-card .foot { display: flex; justify-content: space-between; margin-top: 10px; gap: 8px; }

/* просмотр источника — поверх чата */
.viewer {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column;
  background: var(--panel);
}
.viewer .doc { flex: 1; overflow-y: auto; padding: 12px 0 40px; }
.viewer .ln { display: flex; gap: 12px; padding: 1px 16px; line-height: 1.6; }
.viewer .ln .no { flex: 0 0 3em; text-align: right; color: var(--muted); font-size: 13px; user-select: none; padding-top: 2px; }
.viewer .ln .tx { flex: 1; white-space: pre-wrap; word-break: break-word; min-height: 1.6em; }
.viewer .ln.hl { background: var(--mark); }
.viewer .sub { color: var(--muted); font-size: 14px; }

.tabs { display: none; }

/* диалог добавления */
dialog {
  width: min(560px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text); padding: 20px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h3 { margin: 0 0 8px; font-size: 18px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 6px 0 4px; }
.seg button { border: 0; border-radius: 0; padding: 6px 14px; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.row { display: flex; gap: 12px; }
.row > div { flex: 1; min-width: 0; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; align-items: center; }
.dlg-foot .msg { flex: 1; font-size: 14px; }

/* настройки */
.group {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; max-width: 720px;
}
.group h2 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.group .state { font-size: 13px; color: var(--muted); margin-left: 6px; font-weight: normal; }
.group .state.set { color: var(--ok); }
.group .btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.result { margin-top: 10px; font-size: 14px; padding: 6px 10px; border-radius: 8px; word-break: break-word; }
.result.ok { background: var(--ok-soft); }
.result.err { background: var(--err-soft); }
.token-out { display: flex; gap: 8px; margin-top: 10px; }
.token-out input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px;
  max-width: calc(100vw - 32px);
}

/* ── телефон: колонки → вкладки ────────────────────────────────────────── */
@media (max-width: 799px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .nb { display: flex; flex-direction: column; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
  .tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel); }
  .tabs button {
    flex: 1; border: 0; border-radius: 0; background: none; padding: 11px 0;
    color: var(--muted); border-bottom: 2px solid transparent;
  }
  .tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
  .nb .pane { flex: 1; }
  .nb[data-tab=chat] .sources, .nb[data-tab=sources] .chat { display: none; }
  .sources { border-right: 0; }
  .pane-head.chat-head h2 { display: none; }
  .chat-log { padding: 14px 12px; }
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .msg-user { max-width: 92%; }
  .page { padding: 18px 12px 40px; }
  .row { flex-direction: column; gap: 0; }
  .cite-card { left: 12px !important; right: 12px; bottom: 12px; top: auto !important; width: auto; }
}
