/* The WhatsApp inbox (D-476). Daylight like the Control Center: warm paper, ink, one scarlet. Phones first; two columns
   from 900 px. Inputs are 16 px so focusing never zooms (ENGINEERING.md §2). */
:root {
  --paper: #f6f3ef;
  --card: #ffffff;
  --ink: #1f1a17;
  --soft: #6b625b;
  --line: #e4ddd5;
  --scarlet: #d6283b;
  --mine: #fde9e3;
  --theirs: #ffffff;
  --note: #f3efe8;
  --blue: #2f6fd6;
  --ok: #2e7d4f;
  --shadow: 0 1px 2px rgba(31, 26, 23, .08), 0 4px 16px rgba(31, 26, 23, .06);
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161311; --card: #201c19; --ink: #f2ece6; --soft: #a39890; --line: #332d29;
    --mine: #3a2420; --theirs: #241f1c; --note: #2a2420; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-text-size-adjust: 100%; touch-action: manipulation; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select { font-size: 16px; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--scarlet); outline-offset: 2px; }
.bootline { text-align: center; margin-top: 40vh; color: var(--soft); }

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

/* sign-in */
.gate { margin: auto; max-width: 360px; padding: 32px 24px; text-align: center; }
.gate h1 { font-size: 22px; margin: 16px 0 8px; }
.gate p { color: var(--soft); margin: 0 0 24px; }
.gate img { width: 56px; height: 56px; }
.big { display: block; width: 100%; padding: 14px 18px; border-radius: 14px; background: var(--ink); color: var(--paper); font-weight: 600; }
.big:disabled { opacity: .5; }
.err { color: var(--scarlet); margin-top: 14px; min-height: 1.4em; }

/* top bar */
.top { display: flex; align-items: center; gap: 8px; padding: calc(var(--top) + 8px) 12px 8px; border-bottom: 1px solid var(--line); background: var(--paper); flex-wrap: wrap; }
.numbers { display: flex; gap: 6px; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
.numbers::-webkit-scrollbar { display: none; }
.num { flex: none; display: flex; flex-direction: column; align-items: flex-start; padding: 6px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); text-align: left; }
.num b { font-size: 14px; }
.num small { color: var(--soft); font-size: 12px; }
.num[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 10px; background: var(--scarlet); color: #fff; font-size: 12px; font-weight: 700; text-align: center; margin-left: 6px; }
.tool { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 14px; white-space: nowrap; }
@media (max-width: 420px) { .numbers { flex-basis: 100%; } .tool { padding: 7px 10px; font-size: 13px; } }
.tool.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* body: list and thread */
.main { flex: 1; display: flex; min-height: 0; }
.list { width: 100%; overflow-y: auto; background: var(--paper); }
.thread { display: none; flex-direction: column; flex: 1; min-width: 0; background: var(--note); }
.main.reading .list { display: none; }
.main.reading .thread { display: flex; }
@media (min-width: 900px) {
  .list { width: 360px; flex: none; border-right: 1px solid var(--line); display: block !important; }
  .thread { display: flex; }
}
.search { position: sticky; top: 0; padding: 8px 12px; background: var(--paper); z-index: 1; }
.search input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.row { display: flex; gap: 10px; width: 100%; padding: 12px; border-bottom: 1px solid var(--line); text-align: left; align-items: flex-start; }
.row[aria-current="true"] { background: var(--card); }
.face { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font-weight: 700; color: var(--soft); }
.row .mid { flex: 1; min-width: 0; }
.row .name { display: flex; justify-content: space-between; gap: 8px; }
.row .name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .when { color: var(--soft); font-size: 12px; flex: none; }
.row .line { color: var(--soft); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; justify-content: space-between; gap: 8px; }
.row .open { color: var(--ok); font-size: 11px; font-weight: 600; flex: none; }
.empty { padding: 40px 24px; text-align: center; color: var(--soft); }

/* thread */
.thead { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--paper); border-bottom: 1px solid var(--line); }
.thead .who { flex: 1; min-width: 0; }
.thead .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thead .who small { color: var(--soft); }
.back { font-size: 22px; padding: 4px 8px; }
@media (min-width: 900px) { .back { display: none; } }
.msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.day { align-self: center; font-size: 12px; color: var(--soft); background: var(--paper); padding: 2px 10px; border-radius: 10px; margin: 8px 0; }
.b { max-width: min(80%, 520px); padding: 8px 10px 6px; border-radius: 12px; background: var(--theirs); box-shadow: var(--shadow); align-self: flex-start; position: relative; overflow-wrap: anywhere; }
.b.out { align-self: flex-end; background: var(--mine); }
.b.event { align-self: center; background: var(--paper); box-shadow: none; border: 1px dashed var(--line); font-size: 13px; color: var(--soft); max-width: 90%; text-align: center; }
.b .label { font-size: 12px; font-weight: 700; color: var(--soft); margin-bottom: 2px; }
.b .text { white-space: pre-wrap; }
.b .gone { text-decoration: line-through; opacity: .6; }
.b .tag { font-size: 11px; color: var(--soft); font-style: italic; }
.b .meta { display: flex; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--soft); margin-top: 2px; }
.b .meta .read { color: var(--blue); }
.b .meta .failed { color: var(--scarlet); font-weight: 700; }
.b .fail { color: var(--scarlet); font-size: 12px; margin-top: 4px; }
.b .quote { border-left: 3px solid var(--scarlet); background: rgba(0,0,0,.04); padding: 4px 8px; border-radius: 6px; font-size: 13px; color: var(--soft); margin-bottom: 4px; max-height: 3.2em; overflow: hidden; }
.b .note { font-size: 13px; color: var(--soft); background: var(--note); border-radius: 8px; padding: 6px 8px; margin-top: 4px; }
.b .ad { font-size: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; margin-bottom: 4px; }
.b dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 4px 0 0; font-size: 13px; }
.b dt { color: var(--soft); }
.b dd { margin: 0; }
.b a { color: var(--blue); }
.b img.pic { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; }
.b img.sticker { width: 140px; height: 140px; object-fit: contain; }
.b video { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; }
.b audio { width: 260px; max-width: 100%; }
.b .file { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; background: var(--note); }
.b .waiting { font-size: 13px; color: var(--soft); padding: 12px; background: var(--note); border-radius: 8px; }
.b .reacts { position: absolute; bottom: -12px; right: 8px; background: var(--card); border-radius: 12px; padding: 0 6px; font-size: 14px; box-shadow: var(--shadow); }
.b.hasreacts { margin-bottom: 12px; }
.b .acts { display: none; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.b.picked .acts { display: flex; }
.b .acts button { padding: 4px 8px; border-radius: 8px; background: var(--note); font-size: 14px; }
.window { padding: 8px 12px; font-size: 13px; background: var(--paper); border-top: 1px solid var(--line); color: var(--soft); display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.window.shut { color: var(--ink); }
.replying { display: flex; gap: 8px; align-items: center; padding: 6px 12px; font-size: 13px; background: var(--paper); border-top: 1px solid var(--line); }
.replying span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--soft); }
.compose { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(8px + var(--bottom)); background: var(--paper); border-top: 1px solid var(--line); }
.compose textarea { flex: 1; resize: none; max-height: 40vh; min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.compose .round { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); font-size: 18px; }
.compose .send { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.nothread { margin: auto; color: var(--soft); text-align: center; padding: 24px; }

/* sheets */
.veil { position: fixed; inset: 0; background: rgba(20, 16, 14, .4); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
@media (min-width: 700px) { .veil { align-items: center; } }
.sheet { background: var(--paper); width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--bottom)); }
@media (min-width: 700px) { .sheet { border-radius: 18px; } }
.sheet h2 { font-size: 18px; margin: 0 0 12px; display: flex; justify-content: space-between; align-items: center; }
.sheet label { display: block; font-size: 13px; color: var(--soft); margin: 10px 0 4px; }
.sheet input, .sheet select, .sheet textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.sheet .preview { white-space: pre-wrap; background: var(--card); border-radius: 10px; padding: 10px 12px; margin: 12px 0; border: 1px solid var(--line); font-size: 14px; }
.sheet .tpl { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--card); }
.sheet .tpl small { color: var(--soft); display: block; white-space: pre-wrap; max-height: 4.2em; overflow: hidden; }
.notice { border-bottom: 1px solid var(--line); padding: 10px 0; font-size: 14px; }
.notice small { color: var(--soft); }
.notice dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0 0; font-size: 13px; }
.notice dt { color: var(--soft); }
.notice dd { margin: 0; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: calc(80px + var(--bottom)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; z-index: 20; max-width: 90vw; font-size: 14px; }
