/* Chat Desk — an interpreter's desk: English carries the line, the original sits beneath it as a gloss. */
:root {
  --bg: #e9edf1;
  --surface: #ffffff;
  --ink: #16202b;
  --muted: #677382;
  --gloss: #7d6a52;          /* the original-language line: warm, like pencil annotation */
  --line: #d6dce3;
  --accent: #2b59c3;         /* cobalt: actions and your own words */
  --accent-ink: #ffffff;
  --out: #dfe8fb;
  --in: #ffffff;
  --warn: #b5432c;
  --warn-bg: #fbe9e4;
  --ok: #2c7a4b;
  --hold-bg: #fff4d6;
  --shadow: 0 1px 2px rgba(22, 32, 43, .08);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gloss-font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c; --surface: #17202a; --ink: #e7ecf2; --muted: #93a0ae; --gloss: #c9b291;
    --line: #26323f; --accent: #6f95f2; --accent-ink: #0b1220; --out: #1f3156; --in: #1b2531;
    --warn: #f08a72; --warn-bg: #3a2019; --ok: #6fcf97; --hold-bg: #3a3116; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.4 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---- top bar: one tab per number */
.top { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--ink); color: #fff; }
@media (prefers-color-scheme: dark) { .top { background: #0a0f14; } }
.phones { display: flex; gap: 6px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.phone-tab { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; border: 0;
  background: rgba(255,255,255,.08); color: #cfd8e3; white-space: nowrap; font-size: 15px; }
.phone-tab.on { background: #fff; color: #16202b; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4cc38a; flex: none; }
.dot.off { background: #f06b52; }
.dot.warn { background: #f2b33d; }
.badge { min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 700; text-align: center; }
.icon-btn { border: 0; background: transparent; font-size: 20px; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; flex: none; }
.top .icon-btn { color: #fff; }
.icon-btn:hover { background: rgba(127,127,127,.12); }

/* ---- banners */
.banner { padding: 10px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); }
.banner.off { background: var(--warn-bg); color: var(--warn); }
.banner.hold { background: var(--hold-bg); }
.banner .spacer { flex: 1; }
.banner button { border: 1px solid currentColor; background: transparent; border-radius: 8px; padding: 4px 10px; font-size: 13px; }

/* ---- panes */
.panes { flex: 1; display: flex; min-height: 0; }
.list-pane { width: 100%; display: flex; flex-direction: column; background: var(--surface); position: relative; min-height: 0; }
.chat-pane { display: none; flex: 1; min-width: 0; flex-direction: column; min-height: 0; }
body.in-chat .list-pane { display: none; }
body.in-chat .chat-pane { display: flex; }
@media (min-width: 900px) {
  .list-pane { width: 360px; flex: none; border-right: 1px solid var(--line); }
  .chat-pane, body.in-chat .chat-pane { display: flex; }
  body.in-chat .list-pane { display: flex; }
  .back { display: none !important; }
}

.seg { display: flex; margin: 10px 12px 0; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.search { padding: 10px 12px; }
.search input { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  color: var(--ink); font-size: 15px; }
.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.row { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 11px 14px; border-bottom: 1px solid var(--line); }
.row:hover, .row.on { background: var(--bg); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--bg); color: var(--muted); display: grid;
  place-items: center; font-weight: 600; flex: none; font-size: 15px; }
.row-main { flex: 1; min-width: 0; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar { overflow: hidden; }
.head-avatar { width: 36px; height: 36px; font-size: 13px; cursor: zoom-in; }
.row-top { display: flex; gap: 8px; align-items: baseline; }
.row-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-name .tilde { color: var(--muted); font-weight: 400; }
.row-time { color: var(--muted); font-size: 12px; flex: none; }
.row.unread .row-time { color: var(--accent); font-weight: 600; }
.row-bottom { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.row-preview { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .row-preview { color: var(--ink); }
.wa { color: var(--ok); font-size: 12px; flex: none; }
.list-note { padding: 18px 16px; color: var(--muted); font-size: 14px; }
.row.archived-entry .avatar { background: transparent; font-size: 20px; }
.row.archived-entry .row-name { font-weight: 600; }
.list-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line);
  font-weight: 650; }
.fab { position: absolute; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 52px; height: 52px;
  border-radius: 16px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 24px;
  box-shadow: 0 4px 14px rgba(43, 89, 195, .35); }

/* ---- conversation */
.empty-chat { flex: 1; display: grid; place-items: center; padding: 24px; color: var(--muted); text-align: center; }
.empty-chat p { max-width: 300px; }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface);
  border-bottom: 1px solid var(--line); }
.who { flex: 1; min-width: 0; }
.who-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-sub { color: var(--muted); font-size: 13px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 10px; font-size: 13px;
  font-weight: 600; letter-spacing: .04em; flex: none; }

.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 16px; display: flex; flex-direction: column; gap: 6px;
  overscroll-behavior: contain; }
.day { align-self: center; color: var(--muted); font-size: 12px; padding: 8px 0 2px; }
.msg { max-width: min(78%, 560px); padding: 8px 11px 6px; border-radius: var(--r); box-shadow: var(--shadow);
  position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: var(--in); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 4px; }
.msg .primary-line { white-space: pre-wrap; }
/* the signature: the original language as an interlinear gloss */
.msg .gloss { white-space: pre-wrap; font-family: var(--gloss-font); font-style: italic; color: var(--gloss);
  font-size: 14px; margin-top: 3px; padding-top: 3px; border-top: 1px dashed color-mix(in srgb, var(--gloss) 35%, transparent); }
.msg.swapped .primary-line { font-family: var(--gloss-font); font-style: italic; }
.msg.swapped .gloss { font-family: var(--sans); font-style: normal; color: var(--muted); }
.msg .meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; color: var(--muted); font-size: 11px; margin-top: 3px; }
.msg .lang { text-transform: uppercase; letter-spacing: .06em; }
.msg .pending { color: var(--muted); font-size: 13px; }
.msg .pending::after { content: "…"; animation: blink 1.2s steps(3) infinite; }
@keyframes blink { 50% { opacity: .3; } }
.msg img.photo { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 2px 0 4px; cursor: zoom-in; background: var(--bg); }
.msg audio { width: 240px; max-width: 100%; height: 36px; display: block; margin: 2px 0 4px; }
.msg .kind { color: var(--muted); font-size: 14px; }
.msg .err { color: var(--warn); font-size: 13px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }
.msg.out.failed { background: var(--warn-bg); }
.status { font-size: 11px; }
.status.sent { color: var(--ok); }
.status.failed { color: var(--warn); font-weight: 600; }
.fail-box { margin-top: 4px; font-size: 13px; color: var(--warn); }
.fail-box .acts { display: flex; gap: 12px; margin-top: 4px; }

/* ---- proof panel: what will actually go out */
.proof { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.proof-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.proof textarea { width: 100%; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
  font: 16px/1.4 var(--gloss-font); font-style: italic; color: var(--ink); background: var(--bg); max-height: 30vh; }
.means { font-size: 14px; color: var(--ink); }
.means-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-right: 4px; }
.proof.stale .means #proof-back { color: var(--muted); text-decoration: line-through; }
.proof-actions { display: flex; justify-content: flex-end; gap: 8px; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px;
  font: 16px/1.4 var(--sans); background: var(--bg); color: var(--ink); max-height: 30vh; min-height: 40px; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; border-radius: 20px;
  padding: 0 16px; height: 40px; flex: none; }
.primary:disabled { opacity: .5; cursor: default; }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 20px; padding: 0 14px; height: 38px; }
.danger { color: var(--warn); }

/* ---- sheets, lightbox, toast */
.sheet-wrap { position: fixed; inset: 0; background: rgba(10, 15, 20, .45); display: flex; align-items: flex-end;
  justify-content: center; z-index: 20; }
.sheet { background: var(--surface); width: 100%; max-width: 520px; max-height: 85dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 18px; } }
.sheet h2 { font-size: 18px; margin: 0 0 12px; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.sheet input, .sheet textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: 16px var(--sans); }
.sheet .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.sheet .note { color: var(--muted); font-size: 14px; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 13px 4px;
  border-bottom: 1px solid var(--line); font-size: 16px; }
.qr { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.qr button.use { flex: 1; text-align: left; border: 0; background: transparent; padding: 12px 4px; }
.photo-preview { width: 100%; max-height: 40dvh; object-fit: contain; border-radius: 10px; background: var(--bg); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 30; display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 40; font-size: 14px;
  max-width: calc(100vw - 32px); }

/* ---- login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--surface); padding: 28px 22px; border-radius: 18px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.login .gloss-demo { font-family: var(--gloss-font); font-style: italic; color: var(--gloss); }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login input { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 16px; }
.login .primary { width: 100%; margin-top: 20px; }
.login .error { color: var(--warn); font-size: 14px; margin-top: 12px; min-height: 1.2em; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
