/* BeeNotes — chat inbox (variant E). Light and dark share one set of tokens. */
:root {
  --bg: #fcfcfc;
  --surface: #ffffff;
  --bubble: #eeeeee;
  --input: #f0f0f0;
  --text: #1c1c1c;
  --strong: #111111;
  --muted: #555555;
  --faint: #6b6b6b;
  --line: #ececec;
  --line-strong: #dedede;
  --hover: #f3f3f3;
  --active: #ececec;
  --primary-bg: #1c1c1c;
  --primary-fg: #ffffff;
  --ok: #5f8a55;
  --wait: #b07c2e;
  --error: #943c32;
  --backdrop: #00000029;
  --shadow: #00000014;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #171717;
  --surface: #1f1f1f;
  --bubble: #262626;
  --input: #242424;
  --text: #ededed;
  --strong: #f5f5f5;
  --muted: #a3a3a3;
  --faint: #8f8f8f;
  --line: #2a2a2a;
  --line-strong: #3a3a3a;
  --hover: #202020;
  --active: #262626;
  --primary-bg: #ededed;
  --primary-fg: #171717;
  --ok: #7fa36f;
  --wait: #c9a061;
  --error: #e0aaa5;
  --backdrop: #00000099;
  --shadow: #00000040;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #171717; --surface: #1f1f1f; --bubble: #262626; --input: #242424; --text: #ededed; --strong: #f5f5f5;
    --muted: #a3a3a3; --faint: #8f8f8f; --line: #2a2a2a; --line-strong: #3a3a3a; --hover: #202020; --active: #262626;
    --primary-bg: #ededed; --primary-fg: #171717; --ok: #7fa36f; --wait: #c9a061; --error: #e0aaa5;
    --backdrop: #00000099; --shadow: #00000040; color-scheme: dark;
  }
}

/* Base */
:root { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-synthesis: none; -webkit-text-size-adjust: 100%; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button, input, textarea, select, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; background: transparent; padding: 0; }
button:disabled { color: var(--faint); cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--muted); outline-offset: 3px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.small { font-size: 12px !important; }
.icon-button { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); border-radius: 8px; }
.icon-button:hover { color: var(--text); }
.primary-button { height: 40px; padding: 0 16px; border-radius: 8px; background: var(--primary-bg); color: var(--primary-fg); font-size: 14px; font-weight: 500; }

/* Layout: one column on phones, sidebar + main on desktop, + review column on wide screens */
.app { display: grid; grid-template-columns: minmax(0, 1fr); height: 100dvh; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100dvh; }
.content { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* Sidebar */
.sidebar { display: flex; flex-direction: column; gap: 2px; padding: 24px 14px 20px; background: var(--bg); border-right: 1px solid var(--line); min-height: 0; overflow-y: auto; }
.brand { font-size: 15px; font-weight: 600; letter-spacing: -0.3px; padding: 4px 10px 24px; }
.nav { display: grid; gap: 2px; }
.nav button { display: flex; justify-content: space-between; align-items: center; min-height: 38px; padding: 0 10px; border-radius: 6px; font-size: 13px; color: var(--muted); text-align: left; }
.nav button:hover { background: var(--hover); color: var(--text); }
.nav button.active { background: var(--active); color: var(--strong); font-weight: 600; }
.nav .count { color: var(--faint); font-weight: 400; font-size: 12px; }
.sidebar-foot { margin-top: auto; padding: 24px 10px 0; display: grid; gap: 4px; justify-items: start; font-size: 12px; color: var(--muted); }
.sidebar-foot button { min-height: 32px; font-size: 12px; color: var(--muted); }
.sidebar-foot button:hover { color: var(--text); }
.sync { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--wait); }
.dot.ok { background: var(--ok); }
.scrim { position: fixed; inset: 0; background: var(--backdrop); z-index: 30; }

/* Header */
.main-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 8px 6px 8px 16px; border-bottom: 1px solid var(--line); }
.view-toggle { flex: 1; min-width: 0; display: grid; justify-items: start; padding: 4px 0; text-align: left; }
.view-title { display: inline-flex; align-items: center; gap: 6px; font-size: 17px; font-weight: 600; letter-spacing: -0.3px; }
.status-line { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
/* On phones the section switcher is the visible title; the h1 stays for screen readers. */
.head-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.head-title h1 { margin: 0; font-size: 15px; font-weight: 600; }
.search { display: none; align-items: center; gap: 8px; color: var(--faint); }
.search input { border: 0; background: transparent; color: var(--text); font-size: 14px; padding: 8px 0; width: 100%; outline-offset: 4px; }
.search input::placeholder { color: var(--faint); }
.app.search-open .search { display: flex; order: 10; flex-basis: 100%; padding: 4px 10px 6px 0; }

/* Notices */
.notices { padding: 0 16px; }
.notices:empty { display: none; }
#notice { font-size: 12px; line-height: 1.6; color: var(--muted); padding: 10px 0; white-space: pre-wrap; }
#notice.error { color: var(--error); }
#pending, #conflicts { font-size: 12px; color: var(--muted); padding: 10px 0; border-bottom: 1px solid var(--line); max-height: 30vh; overflow-y: auto; }
#pending summary, #conflicts summary { cursor: pointer; }
#pending p, #conflicts p { margin: 6px 0 0; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
#conflicts h3 { font-size: 13px; font-weight: 500; margin: 0 0 6px; color: var(--text); }
#conflicts button { text-decoration: underline; text-underline-offset: 3px; margin-top: 8px; font-size: 12px; }
.search-scope { font-size: 11px; color: var(--muted); margin: 8px 0 0; }
.search-scope:empty { display: none; }

/* Chat feed */
.feed { max-width: 760px; min-height: 100%; margin: 0 auto; padding: 16px 12px 10px; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; }
.day { align-self: center; font-size: 11px; color: var(--faint); margin: 12px 0 6px; }
.msg { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-bottom: 6px; }
.bubble { max-width: min(82%, 560px); background: var(--bubble); border-radius: 18px 18px 4px 18px; padding: 8px 13px 6px; text-align: left; color: var(--text); font-size: 15px; line-height: 1.45; }
button.bubble:hover { filter: brightness(0.98); }
.bubble-text { display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 1px; font-size: 11px; color: var(--faint); }
.checks { stroke-width: 1.5; }
.under { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 2px 14px; max-width: 92%; padding-right: 6px; font-size: 12px; color: var(--muted); }
.under button { font-size: 12px; min-height: 28px; }
.under .moved { color: var(--text); }
.under .undo { color: var(--faint); }
.under .undo:hover, .under .moved:hover { text-decoration: underline; text-underline-offset: 3px; }
.question { flex-basis: 100%; text-align: right; margin: 0; line-height: 1.5; }
.question button { color: var(--text); text-decoration: underline; text-underline-offset: 3px; min-height: 0; }
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; width: min(92%, 420px); }
.chip { height: 36px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); font-size: 12px; color: var(--text); }
.chip:hover { border-color: var(--muted); }
.empty { color: var(--faint); font-size: 13px; line-height: 1.6; text-align: center; padding: 32px 16px; margin: 0; }

/* Section lists */
.list { max-width: 760px; margin: 0 auto; padding: 8px 16px 24px; }
.row-wrap { display: flex; align-items: flex-start; gap: 14px; border-bottom: 1px solid var(--line); }
.row-wrap.done .row-title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
.check { appearance: none; -webkit-appearance: none; width: 20px; height: 20px; margin: 16px 0 0; border: 1.5px solid var(--faint); border-radius: 50%; flex-shrink: 0; cursor: pointer; display: grid; place-content: center; }
.check:checked { background: var(--muted); border-color: var(--muted); }
.check:checked::after { content: ""; width: 8px; height: 4px; border-left: 2px solid var(--bg); border-bottom: 2px solid var(--bg); transform: translateY(-1px) rotate(-45deg); }
.row { flex: 1; min-width: 0; display: grid; gap: 3px; padding: 14px 0; text-align: left; }
.row-title { font-size: 15px; font-weight: 500; line-height: 1.45; overflow-wrap: anywhere; }
.row:hover .row-title { text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 4px; }
.row-preview { font-size: 13px; line-height: 1.55; color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-meta { font-size: 12px; color: var(--faint); }
.done-group { margin-top: 18px; font-size: 12px; color: var(--faint); }
.done-group summary { cursor: pointer; padding: 10px 0; }

/* Review bar and composer */
.review-bar { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 0 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.review-bar-go { color: var(--text); font-weight: 500; }
.composer { border-top: 1px solid var(--line); padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; }
.privacy select { appearance: none; -webkit-appearance: none; height: 40px; max-width: 86px; border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 0 6px; cursor: pointer; }
.composer textarea { flex: 1; min-width: 0; min-height: 40px; max-height: 200px; border: 0; border-radius: 20px; background: var(--input); color: var(--text); resize: none; padding: 9px 16px; font-size: 16px; line-height: 1.4; outline-offset: 2px; }
.composer textarea::placeholder { color: var(--faint); }
.send { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-bg); color: var(--primary-fg); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send svg { stroke-width: 2; }

/* Review («Разобрано сегодня») */
.review { display: none; flex-direction: column; min-height: 0; background: var(--bg); }
.review-head { display: flex; align-items: center; gap: 4px; padding: 10px 16px 10px 4px; border-bottom: 1px solid var(--line); }
.review-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.3px; outline: none; }
.review-head h2 span { color: var(--muted); font-weight: 400; }
.review-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.review-list { flex: 1; overflow-y: auto; padding: 0 16px; }
.review-item { padding: 12px 0 4px; border-bottom: 1px solid var(--line); }
.review-item:last-child { border-bottom: 0; }
.quote { margin: 0 0 4px; font-size: 12px; line-height: 1.5; color: var(--faint); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.review-title { margin: 0; font-size: 15px; font-weight: 500; line-height: 1.4; overflow-wrap: anywhere; }
.review-question { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.review-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.review-actions { display: flex; gap: 16px; }
.review-actions button { min-height: 40px; font-size: 12px; color: var(--text); }
.review-actions .muted { color: var(--faint); }
.review-foot { padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.review-foot .primary-button { width: 100%; height: 46px; }
.app.review-open .review { display: flex; position: fixed; inset: 0; z-index: 25; }

/* Dialogs */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 16px 80px var(--shadow); width: min(560px, calc(100vw - 32px)); max-height: 90dvh; padding: 24px; }
dialog::backdrop { background: var(--backdrop); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.dialog-heading h2 { font-size: 19px; font-weight: 600; letter-spacing: -0.4px; margin: 0; }
.icon { font-size: 24px; line-height: 1; color: var(--muted); padding: 6px 4px 6px 12px; }
.dialog-notice { margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--error); }
dialog h3 { font-size: 13px; font-weight: 600; margin: 24px 0 8px; }
dialog p { font-size: 13px; line-height: 1.6; color: var(--muted); }
dialog label { display: block; margin: 16px 0 6px; font-size: 12px; color: var(--muted); }
dialog input:not([type=checkbox]), dialog select, dialog textarea { display: block; width: 100%; margin-top: 6px; padding: 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 14px; }
dialog .checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
dialog .checkbox input { accent-color: var(--text); width: 16px; height: 16px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px 20px; margin-top: 20px; }
.actions button { font-size: 13px; color: var(--muted); min-height: 36px; }
.actions button:hover { color: var(--text); }
.actions .primary, .actions .primary-button { color: var(--primary-fg); background: var(--primary-bg); border-radius: 8px; padding: 0 16px; height: 38px; font-weight: 500; }

/* Settings: sign-in and devices */
.account { border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.account h3 { margin-top: 0; }
.account .who { margin: 0 0 12px; color: var(--text); }
.account .actions { justify-content: flex-start; margin-top: 12px; }
.account .actions .primary-button { color: var(--primary-fg); }
.google { display: inline-flex; align-items: center; justify-content: center; gap: 10px; height: 42px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500; text-decoration: none; }
.google:hover { border-color: var(--muted); }
.pair-row { display: flex; gap: 8px; align-items: center; }
.pair-row input { flex: 1; margin-top: 0 !important; font-size: 20px !important; letter-spacing: 4px; text-align: center; }
.pair-code { margin: 12px 0 4px; font-size: 32px; font-weight: 600; letter-spacing: 6px; color: var(--strong); font-variant-numeric: tabular-nums; }
.device-list { list-style: none; margin: 8px 0 0; padding: 0; }
.device-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.device-list .meta { color: var(--faint); font-size: 12px; }
.device-list button { font-size: 12px; color: var(--muted); min-height: 32px; }
.manual { margin-top: 18px; font-size: 13px; color: var(--muted); }
.manual summary { cursor: pointer; padding: 6px 0; }

/* Record detail: side sheet on desktop, full screen on phones */
#detail { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; padding: 12px 20px calc(24px + env(safe-area-inset-bottom)); }
.detail-meta { margin: 0; font-size: 12px; color: var(--muted); }
.text-input { border: 0 !important; padding: 0 !important; margin: 4px 0 0 !important; background: transparent !important; min-height: 56px; resize: none; font-size: 19px !important; font-weight: 500; letter-spacing: -0.2px; line-height: 1.45; overflow-y: auto; }
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--line); }
.fields label { margin: 10px 0 0; }
.fields .wide { grid-column: 1 / -1; }
.source.small { margin: 18px 0 0; color: var(--faint); }
.fields select { padding: 8px; font-size: 13px; }
.source .bubble { max-width: 100%; display: block; }
.source .bubble-meta { font-size: 11px; }
.proposal-result:empty { display: none; }
.proposal-result { margin-top: 12px; padding: 14px; border-radius: 8px; background: var(--hover); }
.proposal-result h3 { margin-top: 0; }
.proposal-result p { margin: 4px 0; }
#history:not(:empty) { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 8px; }
.history-entry { border-bottom: 1px solid var(--line); padding: 12px 0; }
.history-entry strong { font-size: 11px; font-weight: 500; color: var(--muted); }
.history-entry pre { white-space: pre-wrap; font-family: inherit; font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; margin: 6px 0; }
.history-entry button, .proposal-result button { font-size: 12px; color: var(--text); text-decoration: underline; text-underline-offset: 3px; min-height: 32px; }

/* Phones: off-canvas sections menu */
@media (max-width: 899px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 84vw); z-index: 31; transform: translateX(-100%); visibility: hidden; transition: transform .18s ease, visibility .18s; border-right: 1px solid var(--line); }
  .app.menu-open .sidebar { transform: none; visibility: visible; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
  .fields label:nth-child(3) { grid-column: 1 / -1; }
  .chip { height: 40px; }
}

/* Desktop */
@media (min-width: 900px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .mobile-only, .view-toggle, .scrim { display: none !important; }
  .main-head { padding: 18px 32px 14px; flex-wrap: nowrap; gap: 24px; }
  .head-title { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; white-space: normal; flex: 1; min-width: 0; }
  .search { display: flex; width: 220px; }
  .notices { padding: 0 32px; }
  .feed { padding: 20px 32px 12px; }
  .bubble { max-width: min(72%, 560px); }
  .list { padding: 8px 32px 32px; }
  .composer { padding: 12px 32px 20px; }
  #detail { width: 460px; margin: 0 0 0 auto; border-left: 1px solid var(--line); padding: 20px 28px 28px; }
  .review-head { padding: 18px 24px 14px; }
  .review-head h2 { font-size: 15px; }
  .review-list { padding: 0 24px; }
  .review-foot { padding: 12px 24px 20px; border-top: 0; }
}
@media (min-width: 1200px) {
  .app.with-review { grid-template-columns: 220px minmax(0, 1fr) 360px; }
  .app.with-review .review { display: flex; border-left: 1px solid var(--line); height: 100dvh; }
  .app.with-review .review-bar, .app.with-review #review-back { display: none !important; }
  .app.review-open .review { position: static; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
