:root {
  --bg: #ffffff;
  --panel: #f6f6f7;
  --line: #e4e4e7;
  --ink: #111113;
  --ink-2: #52525b;
  --muted: #8b8b93;
  --brand: #000000;
  --gold: #8a6d1f;
  --gold-soft: #f6f0e1;
  --mine: #8a6d1f;
  --mine-ink: #ffffff;
  --theirs: #f0f0f2;
  --theirs-ink: #111113;
  --danger: #b42318;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0f;
    --panel: #16161a;
    --line: #26262c;
    --ink: #f4f4f5;
    --ink-2: #b4b4bc;
    --muted: #7c7c86;
    --gold: #c9a44a;
    --gold-soft: #2a2416;
    --mine: #8a6d1f;
    --theirs: #1f1f24;
    --theirs-ink: #f4f4f5;
    --danger: #f97066;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
#app { height: 100dvh; display: flex; flex-direction: column; }
.splash { flex: 1; display: grid; place-items: center; }
.splash img { border-radius: 14px; }

/* top bar */
.bar { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: calc(var(--safe-top) + 6px) 12px 6px; background: var(--brand); color: #fff; flex-shrink: 0; }
.bar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { display: block; font-size: 12px; font-weight: 400; color: #bdbdc4; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; color: inherit; border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { background: rgba(127,127,127,.15); }
.icon-btn svg { width: 22px; height: 22px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; }

/* layout: list and chat side by side on wide screens */
.layout { flex: 1; display: flex; min-height: 0; }
.pane-list { width: 100%; display: flex; flex-direction: column; min-height: 0; }
.pane-chat { flex: 1; display: none; flex-direction: column; min-width: 0; min-height: 0; }
.layout.chat-open .pane-list { display: none; }
.layout.chat-open .pane-chat { display: flex; }
@media (min-width: 900px) {
  .pane-list { width: 360px; border-right: 1px solid var(--line); display: flex !important; }
  .pane-chat { display: flex !important; }
  .layout .back-btn { display: none; }
}
.empty-chat { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }

/* chat list */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; }
.chat-item:hover, .chat-item.active { background: var(--panel); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 16px; color: #fff; flex-shrink: 0; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.chat-item .meta { flex: 1; min-width: 0; }
.chat-item .row1 { display: flex; gap: 8px; align-items: baseline; }
.chat-item .name { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-item .row2 { display: flex; gap: 8px; align-items: center; }
.chat-item .preview { color: var(--ink-2); font-size: 14px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--gold); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.list-empty { padding: 32px 20px; color: var(--muted); text-align: center; }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 2px; -webkit-overflow-scrolling: touch; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 10px; margin: 12px 0 6px; }
.msg { max-width: min(78%, 560px); display: flex; flex-direction: column; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); margin: 8px 10px 2px; }
.bubble { padding: 8px 12px; border-radius: var(--radius); background: var(--theirs); color: var(--theirs-ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-ink); }
.msg.mine .bubble a { color: #fff; }
.msg.cont { margin-top: -0px; }
.bubble.media { padding: 4px; background: transparent; }
.msg.mine .bubble.media { background: transparent; }
.bubble img { display: block; max-width: 100%; max-height: 360px; border-radius: 14px; cursor: zoom-in; }
.file-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--theirs); color: var(--theirs-ink); text-decoration: none; }
.msg.mine .file-chip { background: var(--mine); color: #fff; }
.file-chip .fname { font-weight: 500; overflow-wrap: anywhere; }
.file-chip .fsize { font-size: 12px; opacity: .75; }
.system { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0; text-align: center; }
.stamp { font-size: 11px; color: var(--muted); margin: 2px 8px 6px; }
.load-more { align-self: center; margin: 8px; }

/* composer */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(var(--safe-bottom) + 8px); border-top: 1px solid var(--line); background: var(--bg); flex-shrink: 0; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--panel); border-radius: 20px; padding: 9px 14px; max-height: 160px; min-height: 40px; line-height: 1.4; outline: none; }
.composer textarea:focus { border-color: var(--gold); }
.composer .icon-btn { color: var(--ink-2); }
.send-btn { background: var(--gold) !important; color: #fff !important; border-radius: 50% !important; }
.send-btn:disabled { opacity: .45; }
.uploading { font-size: 13px; color: var(--muted); padding: 0 14px 6px; }

/* forms and pages */
.page { flex: 1; overflow-y: auto; padding: 20px 16px calc(var(--safe-bottom) + 24px); }
.page-inner { max-width: 520px; margin: 0 auto; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 6px; }
.card p { margin: 0 0 12px; color: var(--ink-2); }
.center-card { max-width: 400px; margin: 8vh auto 0; text-align: center; }
.center-card img { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 12px; }
.center-card h1 { font-size: 22px; margin: 0 0 6px; }
.center-card p { color: var(--ink-2); margin: 0 0 18px; }
label.field { display: block; text-align: left; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
input.text { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 12px; outline: none; }
input.text:focus { border-color: var(--gold); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--panel); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
.note { color: var(--muted); font-size: 13px; margin-top: 8px; }
.code { font: 600 26px/1.2 ui-monospace, Menlo, monospace; letter-spacing: 3px; padding: 10px; background: var(--panel); border-radius: 10px; text-align: center; margin: 6px 0; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { flex: 1; min-width: 0; }
.person { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .meta { flex: 1; min-width: 0; }
.person .meta .s { font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--gold); }
.banner { background: var(--gold-soft); color: var(--ink); font-size: 14px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.banner .x { margin-left: auto; }
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 20px); transform: translateX(-50%); background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: 90vw; }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: grid; place-items: center; z-index: 40; cursor: zoom-out; }
.viewer img { max-width: 96vw; max-height: 92vh; }
.offline { background: #3f3f46; color: #fff; font-size: 13px; text-align: center; padding: 4px; }
