/* Universal Messages - web viewer. Neutral, original design. No external resources. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1d2330;
  --muted: #667085;
  --border: #dde1e7;
  --accent: #2f6f62;
  --accent-text: #ffffff;
  --accent-soft: #e2efec;
  --bubble-in: #eceef2;
  --bubble-out: #2f6f62;
  --bubble-out-text: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn-soft: #fff4dc;
  --warn-text: #6b4a00;
  --focus: #f4c542;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #232834;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --border: #2e3442;
    --accent: #5fb3a1;
    --accent-text: #0d1a17;
    --accent-soft: #1f3a34;
    --bubble-in: #262c38;
    --bubble-out: #2d6b5e;
    --bubble-out-text: #f1f7f5;
    --danger: #f07167;
    --danger-soft: #3a1e1c;
    --warn-soft: #3a3020;
    --warn-text: #f3d48a;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
}
h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); margin: 10px 0 0; }

/* banners */
.banner { margin: 0; padding: 10px 16px; font-weight: 500; }
.banner-danger { background: var(--danger); color: #fff; text-align: center; }
.banner-warn { background: var(--warn-soft); color: var(--warn-text); border-radius: var(--radius); margin: 8px; }

/* buttons and inputs */
.btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-block { display: block; width: 100%; }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
input {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
label { display: block; font-weight: 500; margin: 14px 0 5px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* auth screens */
.auth-screen { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
}
.brand { font-size: 22px; letter-spacing: .2px; }
.brand-small { font-size: 17px; font-weight: 600; white-space: nowrap; }
.card .btn-block { margin-top: 18px; }
.hint { font-size: 13px; color: var(--muted); margin: 5px 0 0; }
.note { font-size: 13px; color: var(--muted); margin: 16px 0 0; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }
.switch { margin: 16px 0 0; text-align: center; font-size: 14px; }

/* app layout */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.search { flex: 1; max-width: 480px; }
.whoami { color: var(--muted); font-size: 14px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panes {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(260px, 360px) 1fr;
}
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); background: var(--surface); }
.pane-thread { background: var(--bg); border-right: 0; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); min-height: 52px; background: var(--surface); }
.pane-foot { padding: 10px 12px; border-top: 1px solid var(--border); }
.pane-foot:empty { display: none; }
.back { display: none; padding: 6px 10px; }
.status { margin: 0; padding: 8px 16px; font-size: 13px; border-bottom: 1px solid var(--border); }
.status:empty { display: none; }
.thread-title { min-width: 0; display: flex; flex-direction: column; }
.thread-title h2, .thread-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-title span { font-size: 13px; }

/* lists */
.list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
.item {
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; text-align: left;
  font: inherit; color: inherit;
  background: none; border: 0; border-left: 3px solid transparent;
  padding: 10px 14px 10px 13px;
  cursor: pointer;
}
.item:hover { background: var(--surface-2); }
.item.selected { background: var(--accent-soft); border-left-color: var(--accent); }
.item.bad .item-title { color: var(--danger); }
.item-row { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.item-title { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 12px; white-space: nowrap; }
.item-preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.item-sub { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 16px; font-size: 14px; margin: 0; }

/* thread */
.thread { flex: 1; overflow-y: auto; padding: 12px 16px 20px; display: flex; flex-direction: column; gap: 6px; }
.thread-more { text-align: center; margin: 4px 0 10px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; margin: 10px 0 4px; }
.bubble { max-width: min(560px, 80%); padding: 8px 12px; border-radius: 16px; overflow-wrap: anywhere; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); border-bottom-right-radius: 4px; }
.bubble.bad { background: var(--danger-soft); color: var(--danger); font-style: italic; }
.bubble.focus { outline: 3px solid var(--focus); }
.bubble-text { white-space: pre-wrap; }
.bubble-meta { font-size: 11px; opacity: .75; margin-top: 3px; }

/* dialog */
.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 22px; max-width: 420px; width: calc(100% - 32px); background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog p { margin: 10px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* phone-width: one column at a time */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .panes { grid-template-columns: 1fr; }
  .pane { display: none; border-right: 0; }
  .panes[data-pane="devices"] .pane-devices,
  .panes[data-pane="convs"] .pane-convs,
  .panes[data-pane="thread"] .pane-thread { display: flex; }
  .back { display: inline-block; }
  .bubble { max-width: 88%; }
}

/* ---- v2: sign-in, vault, settings ---- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.gsi-button { display: flex; justify-content: center; min-height: 44px; margin: 22px 0 6px; }
.test-login { margin-top: 18px; padding: 12px; border: 1px dashed var(--border); border-radius: 8px; }
.test-login .btn-block { margin-top: 10px; }
.big-code {
  font: 600 clamp(17px, 5.2vw, 25px)/1.3 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 1px; text-align: center; white-space: nowrap; overflow-x: auto;
  background: var(--surface-2); border-radius: 10px; padding: 14px 10px; margin: 16px 0 10px;
  user-select: all;
}
.row-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; margin: 16px 0 0; cursor: pointer; }
label.check input { width: auto; margin-top: 3px; }
.warn-text { color: var(--warn-text); background: var(--warn-soft); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin: 14px 0 0; }
.ok-text { color: var(--accent); margin: 10px 0 0; }
.card p { margin: 10px 0 0; }
.btn-small { padding: 4px 10px; font-size: 13px; }

.app { position: relative; }
.settings { position: absolute; inset: 0; top: 0; overflow-y: auto; background: var(--bg); z-index: 5; }
.settings-inner { max-width: 720px; margin: 0 auto; padding: 16px; }
.settings-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 12px; }
.settings-head h2 { font-size: 20px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 18px 20px; margin: 0 0 14px; }
.panel h3 { margin: 0 0 6px; font-size: 17px; }
.panel p { margin: 8px 0; }
.panel input[type="password"], .panel input[type="email"], .panel input[type="text"] { max-width: 380px; }
.panel .btn-primary { margin-top: 12px; }
.steps { margin: 8px 0 4px; padding-left: 22px; }
.steps li { margin: 4px 0; }
.inline-code { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; overflow-wrap: anywhere; }
.secret-choice { display: flex; gap: 18px; flex-wrap: wrap; }
.secret-choice label.check { margin-top: 4px; }
.people-list { list-style: none; padding: 0; margin: 10px 0; border-top: 1px solid var(--border); }
.person { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 9px 0; border-bottom: 1px solid var(--border); }
.person-email { font-weight: 600; overflow-wrap: anywhere; }
.person-info { font-size: 13px; flex: 1; }
.inline-form { display: flex; gap: 8px; align-items: center; max-width: 480px; }
.inline-form .btn-primary { margin-top: 0; }
@media (max-width: 760px) {
  .big-code { letter-spacing: 0; padding: 12px 6px; }
}
.panel form > .btn-primary { display: block; }
