:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e3e7ee;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --mine: #4f46e5;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --err: #dc2626;
  --warn: #b45309;
  --hover: #f1f5f9;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 8px 24px rgb(15 23 42 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --panel: #111827;
    --line: #1f2937;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --accent: #818cf8;
    --accent-soft: #1e1b4b;
    --mine: #4f46e5;
    --theirs: #1f2937;
    --err: #f87171;
    --warn: #fbbf24;
    --hover: #1a2234;
    --shadow: 0 8px 24px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Noto Sans SC", "Noto Sans Lao", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
input, textarea { font: inherit; color: var(--text); }
small { font-size: 12px; }
.muted { color: var(--muted); }
.err { color: var(--err); }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 16px; font-weight: 600;
}
.btn.small { padding: 5px 12px; font-size: 13px; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.link-btn { background: none; border: 0; color: var(--accent); padding: 4px 6px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.lang {
  margin-left: auto; font: inherit; font-size: 13px; font-weight: 400; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; cursor: pointer;
}
.lang:hover { border-color: var(--muted); }
.link-card.center .lang { justify-self: end; }
.head-actions { display: flex; align-items: center; gap: 4px; }
.tag { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag.soft { background: var(--hover); color: var(--muted); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.logo { flex: none; }
.spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- linking ---- */
.link { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.link-card { width: min(860px, 100%); background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 32px 32px; }
.link-card.center { width: min(420px, 100%); display: grid; justify-items: center; gap: 12px; text-align: center; }
.link-card.center h2 { margin: 4px 0 0; font-size: 18px; }
.link-card.center p { margin: 0 0 4px; color: var(--muted); }
.link-body { display: flex; gap: 40px; align-items: center; margin-top: 24px; }
.link-text { flex: 1; min-width: 0; }
.link-text h1 { font-size: 24px; margin: 0 0 16px; font-weight: 650; }
.link-text ol { margin: 0; padding-left: 22px; display: grid; gap: 10px; font-size: 15px; }
.link-text .note { margin-top: 24px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 14px; }
.link-progress p { margin: 0 0 8px; }
.code { font-size: 56px; font-weight: 750; letter-spacing: 8px; color: var(--accent); margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.qr-box { flex: none; width: 280px; height: 280px; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; background: #fff; position: relative; }
.qr { width: 264px; height: 264px; image-rendering: pixelated; }
.qr.dim { opacity: .15; filter: blur(2px); }
.qr-over { display: grid; gap: 12px; justify-items: center; text-align: center; color: #0f172a; padding: 16px; }
@media (max-width: 720px) {
  .link-card { padding: 20px 16px; }
  .link-body { flex-direction: column-reverse; gap: 20px; }
  .qr-box { width: 100%; max-width: 280px; }
}

/* ---- chat layout ---- */
.app { height: 100%; display: grid; grid-template-columns: 340px 1fr; transition: grid-template-columns .22s ease; }
.side { display: flex; flex-direction: column; min-height: 0; overflow: hidden; background: var(--panel); border-right: 1px solid var(--line); }
/* The list keeps its width while it slides away (clipped, not squeezed). */
.side > * { min-width: 340px; }
.app.side-hidden { grid-template-columns: 0 1fr; }
.app.side-hidden .side { border-right-color: transparent; }
@media (prefers-reduced-motion: reduce) { .app { transition: none; } }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px 16px; }
.list-tools { display: flex; gap: 6px; padding: 4px 12px 10px 16px; }
.search { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 10px; outline: none; }
.search:focus { border-color: var(--accent); }
.list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.row { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: transparent; padding: 9px 8px; border-radius: 10px; text-align: left; }
.row:hover { background: var(--hover); }
.row.active { background: var(--accent-soft); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { color: var(--muted); font-size: 12px; flex: none; }
.row-sub { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; min-width: 0; }
.row-sub span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; }

.main { min-width: 0; min-height: 0; display: flex; }
.placeholder { margin: auto; display: grid; justify-items: center; gap: 12px; color: var(--muted); }
.placeholder .logo { opacity: .5; }

.thread { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
/* Files dragged over the conversation: dropped, they are sent. Over everything, never catching the drag itself. */
.drop-overlay { position: absolute; inset: 8px; z-index: 20; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--bg) 82%, transparent); pointer-events: none; }
.drop-card { display: grid; justify-items: center; gap: 6px; max-width: 320px; text-align: center; padding: 20px 24px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); color: var(--accent); }
.drop-card strong { font-size: 16px; color: var(--text); }
.drop-card span { font-size: 13px; color: var(--muted); }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.thread-head .back { display: none; }
.thread-head .side-toggle { margin-left: -6px; }
.thread-title { display: grid; min-width: 0; }
.thread-title span { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-title small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow-y: auto; padding: 16px 20px 8px; display: flex; flex-direction: column; gap: 6px; }
.older { align-self: center; margin-bottom: 8px; }
.msg { display: flex; align-items: flex-end; gap: 4px; max-width: 72%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble { background: var(--theirs); border-radius: 14px 14px 14px 4px; padding: 7px 11px 5px; box-shadow: 0 1px 1px rgb(15 23 42 / 6%); min-width: 0; overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); border-radius: 14px 14px 4px 14px; }
.msg.mine .muted, .msg.mine .meta { color: rgb(255 255 255 / 75%); }
.text { white-space: pre-wrap; }

/* A formatted message (RichText.tsx): JSON and Markdown, display only. */
.rich { display: grid; gap: 6px; min-width: 0; }
.rich p, .rich ul, .rich ol, .rich blockquote { margin: 0; }
.rich ul, .rich ol { padding-left: 1.3em; display: grid; gap: 3px; }
.rich li > * + * { margin-top: 4px; }
.rich-h { font-weight: 700; }
.rich-h.big { font-size: 1.12em; }
.rich blockquote { border-left: 3px solid currentColor; padding-left: 8px; opacity: .78; display: grid; gap: 6px; }
.rich code, .rich-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.rich code { background: rgb(127 127 127 / 16%); border-radius: 4px; padding: 0 3px; }
.rich-code { margin: 0; padding: 8px 10px; border-radius: 8px; background: rgb(127 127 127 / 12%); overflow-x: auto; white-space: pre; max-width: 100%; }
.rich hr { border: 0; border-top: 1px solid currentColor; opacity: .3; width: 100%; margin: 2px 0; }
.rich-table { overflow-x: auto; max-width: 100%; }
.rich table { border-collapse: collapse; font-size: 14px; }
.rich th, .rich td { border: 1px solid rgb(127 127 127 / 35%); padding: 4px 8px; white-space: nowrap; }
.rich th { font-weight: 700; }
.j-key { color: var(--accent); font-weight: 600; }
.j-string { color: #16a34a; }
.j-number { color: #b45309; }
.j-literal { color: #dc2626; }
@media (prefers-color-scheme: dark) {
  .j-string { color: #4ade80; }
  .j-number { color: #fbbf24; }
  .j-literal { color: #f87171; }
}
/* On my (indigo) bubble: the bubble's own ink, the parts told apart by weight and opacity, as on the phone. */
.msg.mine .rich code, .msg.mine .rich-code { background: rgb(255 255 255 / 16%); }
.msg.mine .rich th, .msg.mine .rich td { border-color: rgb(255 255 255 / 35%); }
.msg.mine .j-key, .msg.mine .j-number, .msg.mine .j-literal { color: inherit; }
.msg.mine .j-string { color: rgb(255 255 255 / 85%); }
.sender { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.quote { border-left: 3px solid currentColor; opacity: .75; padding: 1px 8px; margin: 2px 0 5px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; }
.meta { display: flex; gap: 8px; align-items: center; justify-content: flex-end; font-size: 11px; color: var(--muted); margin-top: 2px; }
/* My message's state (as the phone draws it): clock, ✓ sent, ✓✓ read in blue. */
.tick { display: inline-flex; margin-left: -4px; }
.tick svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tick.sending svg { stroke-width: 1.5; }
.tick.read { color: #1f8fe5; }
.msg.mine .tick.read { color: #7fd0ff; }
/* "Not sent · Retry" on my (indigo) bubble: red there is unreadable. */
.msg.mine .meta .err { color: #ffd0d0; font-weight: 600; }
.reply-btn { visibility: hidden; border: 0; background: transparent; color: var(--muted); padding: 4px; border-radius: 6px; }
.msg:hover .reply-btn { visibility: visible; }
.reply-btn:hover { background: var(--hover); }
.media { display: block; max-width: min(360px, 100%); max-height: 360px; border-radius: 10px; margin: 2px 0; cursor: zoom-in; background: #000; }
video.media { cursor: default; }
.video-cover { position: relative; display: block; width: fit-content; line-height: 0; padding: 0; border: 0; background: none; margin: 2px 0; cursor: pointer; }
.video-cover .media { margin: 0; max-width: min(360px, 66vw); cursor: pointer; }
.video-cover .play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; padding-left: 4px; font-size: 20px; color: #fff; background: rgb(0 0 0 / 55%);
}
.video-cover .video-meta { position: absolute; right: 8px; bottom: 8px; padding: 1px 6px; border-radius: 6px; color: #fff; background: rgb(0 0 0 / 55%); }
.video-cover .err { position: absolute; left: 8px; bottom: 8px; padding: 1px 6px; border-radius: 6px; background: var(--panel); }
.media-load { display: grid; gap: 2px; justify-items: start; background: rgb(127 127 127 / 12%); border: 1px dashed currentColor; border-radius: 10px; padding: 18px 22px; margin: 2px 0; }
.file { display: flex; align-items: center; gap: 10px; min-width: 240px; padding: 4px 0; }
.file-main { flex: 1; display: grid; min-width: 0; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.mine .file .btn { background: #fff; color: var(--mine); }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px 12px; }
.compose-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; max-height: 160px; min-height: 38px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--bg); outline: none; field-sizing: content; }
.composer textarea:focus { border-color: var(--accent); }
.send { height: 38px; }
.attach { position: relative; }
.menu { position: absolute; bottom: 44px; left: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); display: grid; min-width: 140px; padding: 4px; z-index: 5; }
.menu button { border: 0; background: transparent; text-align: left; padding: 8px 12px; border-radius: 6px; }
.menu button:hover { background: var(--hover); }
.bar { font-size: 13px; padding: 6px 10px; margin-bottom: 8px; background: var(--hover); border-radius: 8px; display: grid; gap: 4px; }
.bar.err { color: var(--err); cursor: pointer; }
.bar.warn { color: var(--warn); margin: 0 12px 8px; }
.bar.reply { display: flex; justify-content: space-between; align-items: center; }
.bar.reply span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); transition: width .2s; }
.request-bar { padding: 14px; display: flex; justify-content: center; background: var(--panel); border-top: 1px solid var(--line); }

.modal { position: fixed; inset: 0; background: rgb(15 23 42 / 45%); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-card { width: min(440px, 100%); background: var(--panel); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); display: grid; gap: 12px; max-height: 90vh; }
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: var(--bg); outline: none; }
.modal-card input:focus { border-color: var(--accent); }
.contacts { overflow-y: auto; max-height: 280px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 760px) {
  .app, .app.side-hidden { grid-template-columns: 1fr; }
  .side > * { min-width: 0; }
  .app.has-thread .side { display: none; }
  .app:not(.has-thread) .main { display: none; }
  .thread-head .back { display: inline-grid; }
  .thread-head .side-toggle { display: none; }
  .msg { max-width: 88%; }
  .messages { padding: 12px; }
}
