:root {
  --paper: #EEF1F5;
  --sheet: #FFFFFF;
  --ink: #1C2533;
  --muted: #5E687A;
  --line: #D5DBE4;
  --copy: #2E4A9E;          /* carbon-copy blue: translations, active things */
  --copy-soft: #E3E9F7;
  --stamp: #B42318;         /* deleted */
  --stamp-soft: #FCEDEB;
  --mine: #E8EDF6;
  --ok: #2F7A4D;
  --warn: #9A5B00;
  --sans: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "PT Serif", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12161D; --sheet: #1A2029; --ink: #E4E8EF; --muted: #98A2B3; --line: #2C3442;
    --copy: #9DB2F2; --copy-soft: #22304F; --stamp: #F2867C; --stamp-soft: #3A1E1C; --mine: #20283A;
    --ok: #7CC79A; --warn: #E3B05C; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12161D; --sheet: #1A2029; --ink: #E4E8EF; --muted: #98A2B3; --line: #2C3442;
  --copy: #9DB2F2; --copy-soft: #22304F; --stamp: #F2867C; --stamp-soft: #3A1E1C; --mine: #20283A;
  --ok: #7CC79A; --warn: #E3B05C; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 15px/1.45 var(--sans); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--copy); }
:focus-visible { outline: 2px solid var(--copy); outline-offset: 2px; }
.muted { color: var(--muted); }
.err { color: var(--stamp); min-height: 1.4em; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.45rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }

.btn { border: 1px solid var(--line); background: var(--sheet); border-radius: 8px; padding: .5em 1em; cursor: pointer; }
.btn.primary { background: var(--copy); border-color: var(--copy); color: #fff; font-weight: 500; }
:root[data-theme="dark"] .btn.primary { color: #12161D; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #12161D; } }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--stamp); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--copy); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
input, select { border: 1px solid var(--line); background: var(--sheet); border-radius: 8px; padding: .5em .7em; min-width: 0; }
label { display: grid; gap: .3em; margin: 0 0 .8em; color: var(--muted); font-size: .92rem; }
label input, label select { color: var(--ink); font-size: 1rem; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(360px, 100%); background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; padding: 28px 24px; }
.login-box h1 { font-size: 1.5rem; }
.login-box .btn { width: 100%; margin-top: .4em; }

/* frame */
.app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 24px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--sheet); }
.brand { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; padding: 14px 10px 12px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--copy); font-weight: 500; }
.banner { padding: 8px 16px; background: var(--stamp-soft); color: var(--stamp); border-bottom: 1px solid var(--line); font-size: .92rem; }
.banner.warn { background: var(--copy-soft); color: var(--ink); }
main { flex: 1; min-height: 0; }
.view { height: 100%; }
.page { overflow-y: auto; padding: 24px 16px 48px; max-width: 860px; margin: 0 auto; }

/* chats */
.chats { display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--sheet); }
.list-head { padding: 10px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.search-hit { padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list li { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.chat-list li:hover { background: var(--paper); }
.chat-list li.on { background: var(--copy-soft); }
.chat-list .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list .d { color: var(--muted); font-size: .8rem; }
.chat-list .p { grid-column: 1 / -1; color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list .del { color: var(--stamp); font-size: .8rem; }
.grp { color: var(--muted); font-weight: 400; font-size: .8rem; margin-left: .3em; }

.pane { display: flex; flex-direction: column; min-height: 0; }
.pane .empty { margin: auto; color: var(--muted); }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--sheet); flex-wrap: wrap; }
.pane-head .title { font-weight: 600; font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-head .sub { color: var(--muted); font-size: .85rem; font-weight: 400; }
.back { display: none; }
.thread { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; color: var(--muted); font-size: .82rem; margin: 10px 0 4px; }

.msg { max-width: min(640px, 86%); background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px 6px; align-self: flex-start; position: relative; }
.msg.me { align-self: flex-end; background: var(--mine); }
.msg .who { font-size: .82rem; font-weight: 600; color: var(--copy); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .tr { font-family: var(--serif); font-style: italic; color: var(--copy); border-left: 2px solid var(--copy); padding-left: 8px; margin-top: 5px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.msg .meta { display: flex; gap: 10px; justify-content: flex-end; align-items: baseline; font-size: .75rem; color: var(--muted); margin-top: 3px; flex-wrap: wrap; }
.msg .quote { font-size: .85rem; color: var(--muted); border-left: 2px solid var(--line); padding-left: 6px; margin-bottom: 4px; }
.msg .label { color: var(--muted); font-size: .88rem; }
.msg img.media, .msg video.media { display: block; max-width: 100%; max-height: 360px; border-radius: 6px; margin: 2px 0 4px; }
.msg img.sticker { max-width: 120px; }
.msg audio { width: min(300px, 100%); display: block; margin: 2px 0; }
.msg .edits { font-size: .85rem; color: var(--muted); margin-top: 4px; border-top: 1px dashed var(--line); padding-top: 4px; }
.msg .edits s { text-decoration-color: var(--muted); }

/* the one loud element: a deletion stamp */
.msg.deleted { border-color: var(--stamp); background: var(--stamp-soft); }
.stamp { display: inline-block; color: var(--stamp); border: 2px solid var(--stamp); border-radius: 4px; padding: 0 6px; font-weight: 700; font-size: .8rem;
         transform: rotate(-3deg); margin: 2px 0 4px; letter-spacing: .01em; }
.msg.mine-del { border-style: dashed; }

.more { align-self: center; margin-bottom: 8px; }

/* deleted feed / search results */
.feed { display: flex; flex-direction: column; gap: 10px; }
.feed .msg { max-width: none; align-self: stretch; }
.feed .src { font-size: .85rem; margin-bottom: 4px; }

/* summaries */
.sum-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.sum-head h2 { margin: 0 auto 0 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--sheet); padding: .45em .9em; cursor: pointer; }
.seg button.on { background: var(--copy); color: #fff; }
.sum-list { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.sum { background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.sum h3 { display: flex; justify-content: space-between; gap: 10px; font-size: 1rem; margin-bottom: 6px; }
.sum h3 .n { color: var(--muted); font-weight: 400; font-size: .85rem; white-space: nowrap; }
.sum .txt { white-space: pre-wrap; line-height: 1.55; max-width: 72ch; }
.sum .txt .wait { font-weight: 600; }

/* numbers, settings */
.box { background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 0 0 16px; }
.num { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.num .ph { font-weight: 600; font-size: 1.1rem; }
.dot { display: inline-block; width: .6em; height: .6em; border-radius: 50%; background: var(--muted); margin-right: .35em; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--stamp); } .dot.wait { background: var(--warn); }
.code { font: 600 2rem/1.2 var(--sans); letter-spacing: .12em; color: var(--copy); margin: 10px 0; }
ol.steps { padding-left: 1.3em; margin: .4em 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row label { flex: 1 1 180px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.check { display: flex; gap: .5em; align-items: center; color: var(--ink); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 16px; border-radius: 8px; z-index: 9; }

.drawer { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); display: flex; justify-content: flex-end; z-index: 5; }
.drawer > div { width: min(520px, 100%); height: 100%; background: var(--paper); overflow-y: auto; padding: 16px; }

@media (max-width: 760px) {
  .top { gap: 10px; padding: 0 8px; }
  .brand { display: none; }
  .chats { grid-template-columns: 1fr; }
  .chats.open .list { display: none; }
  .chats:not(.open) .pane { display: none; }
  .back { display: inline-block; }
  .thread { padding: 10px 8px; }
  .msg { max-width: 92%; }
  .page { padding: 16px 12px 40px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
