/* wa-meow web UI. Plain CSS, no build step.
   Design tokens first. Light is the default; dark follows the system unless
   the user picked a theme (data-theme on <html>).
   Corners stay small on purpose (3-8px); only dots are fully round. */
:root {
  color-scheme: light;
  --bg: #f1f3f5;
  --panel: #ffffff;
  --panel-2: #f6f7f9;
  --line: #e1e5e9;
  --line-strong: #cdd3d9;
  --ink: #0f1a21;
  --muted: #5c6b75;
  --accent: #068f77;
  --accent-ink: #ffffff;
  --accent-soft: #e0f3ee;
  --bubble-in: #ffffff;
  --bubble-in-line: #e1e5e9;
  --bubble-out: #d8f2e4;
  --bubble-out-line: #c3e6d3;
  --wallpaper: #eaeef1;
  --ok: #0a7d55;
  --ok-bg: #dcf5e8;
  --bad: #b3261e;
  --bad-bg: #fde8e6;
  --wait: #8a5a00;
  --wait-bg: #fff3d6;
  --focus: #1a73e8;
  --quote-bg: rgb(15 26 33 / .05);
  --shadow: 0 1px 2px rgb(15 26 33 / .06), 0 8px 24px rgb(15 26 33 / .08);
  --r-xs: 3px;
  --r-sm: 5px;
  --r-md: 6px;
  --r-lg: 8px;
  --pad: 1rem;
  --who-l: 36%;
  --rail: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --who-l: 68%; color-scheme: dark; --bg: #0b1217; --panel: #121c23; --panel-2: #18242c; --line: #25333c; --line-strong: #34454f; --ink: #e8edf0; --muted: #8b9aa4; --accent: #1fb596; --accent-ink: #04201a; --accent-soft: #11332d; --bubble-in: #1b2831; --bubble-in-line: #25333c; --bubble-out: #0d4a3f; --bubble-out-line: #145c4e; --wallpaper: #0e171d; --ok: #6fdba9; --ok-bg: #0f3326; --bad: #f2a29b; --bad-bg: #3b1714; --wait: #f1cb73; --wait-bg: #3a2d0e; --focus: #8ab4f8; --quote-bg: rgb(255 255 255 / .07); --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .45); }
}
:root[data-theme="dark"] { --who-l: 68%; color-scheme: dark; --bg: #0b1217; --panel: #121c23; --panel-2: #18242c; --line: #25333c; --line-strong: #34454f; --ink: #e8edf0; --muted: #8b9aa4; --accent: #1fb596; --accent-ink: #04201a; --accent-soft: #11332d; --bubble-in: #1b2831; --bubble-in-line: #25333c; --bubble-out: #0d4a3f; --bubble-out-line: #145c4e; --wallpaper: #0e171d; --ok: #6fdba9; --ok-bg: #0f3326; --bad: #f2a29b; --bad-bg: #3b1714; --wait: #f1cb73; --wait-bg: #3a2d0e; --focus: #8ab4f8; --quote-bg: rgb(255 255 255 / .07); --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .45); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.3rem; font-weight: 700; }
h2 { font-size: 1.08rem; font-weight: 650; }
h3 { font-size: .98rem; font-weight: 650; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
svg.icon { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 2.4rem; padding: 0 1rem; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--panel); cursor: pointer; font-weight: 550; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 2.05rem; padding: 0 .75rem; font-size: .9rem; }
.btn.block { width: 100%; }
.iconbtn { display: inline-grid; place-items: center; width: 2.3rem; height: 2.3rem; border: 0; background: transparent; border-radius: var(--r-md); cursor: pointer; color: var(--muted); }
.iconbtn:hover { background: var(--panel-2); color: var(--ink); }
.field { display: flex; flex-direction: column; gap: .4rem; font-weight: 550; }
.field > span { font-size: .84rem; color: var(--muted); }
.field input, .field select, .field textarea, .search input, .composer textarea { border: 1px solid var(--line-strong); background: var(--panel); border-radius: var(--r-md); padding: .6rem .8rem; min-height: 2.5rem; width: 100%; font-weight: 400; }
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus, .composer textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 450; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.form-error { min-height: 1.3em; color: var(--bad); font-size: .9rem; }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: var(--r-xs); font-size: .76rem; font-weight: 650; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.on { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.off { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.wait { background: var(--wait-bg); color: var(--wait); border-color: transparent; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: #22c55e; } .dot.off { background: var(--bad); } .dot.wait { background: #f5a524; }
.err { color: var(--bad); }

/* Login */
.login-body { display: grid; place-items: center; padding: 1rem; background: radial-gradient(1000px 420px at 50% -8%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 24rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 2rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1.5rem; }
.login-card img { border-radius: var(--r-lg); }
.brand { display: flex; align-items: center; gap: 1rem; }
.legacy summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.legacy form { margin-top: 1rem; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; height: 100%; height: 100dvh; }
.rail { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: .9rem 0; gap: .4rem; }
.rail .logo { width: 2.4rem; height: 2.4rem; margin-bottom: .8rem; border-radius: var(--r-lg); }
.rail .spacer { flex: 1; }
.navbtn { position: relative; display: grid; place-items: center; width: 2.7rem; height: 2.7rem; border: 0; background: transparent; color: var(--muted); border-radius: var(--r-lg); cursor: pointer; text-decoration: none; }
.navbtn:hover { background: var(--panel-2); color: var(--ink); }
.navbtn[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.navbtn .pill { position: absolute; top: .15rem; right: .1rem; min-width: 1.1rem; padding: 0 .3rem; border-radius: var(--r-xs); background: var(--accent); color: var(--accent-ink); font-size: .7rem; font-weight: 700; text-align: center; }
.avatar { display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: var(--r-lg); background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; text-transform: uppercase; }
.avatar.sm { width: 2.25rem; height: 2.25rem; font-size: .85rem; }
.view { min-width: 0; min-height: 0; overflow: hidden; }

/* Messages */
.inbox { display: grid; grid-template-columns: minmax(19rem, 25rem) 1fr; height: 100%; min-height: 0; }
.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.pane-head { padding: 1rem 1rem .75rem; display: flex; flex-direction: column; gap: .8rem; border-bottom: 1px solid var(--line); }
.pane-title { display: flex; align-items: center; gap: .3rem; }
.picker { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: 0 .4rem 0 .8rem; background: var(--panel-2); }
.picker select { flex: 1; border: 0; background: transparent; min-height: 2.4rem; min-width: 0; font-weight: 600; }
.tabs { display: flex; gap: .35rem; }
.tab { border: 1px solid transparent; background: transparent; color: var(--muted); padding: .3rem .85rem; border-radius: var(--r-md); cursor: pointer; font-weight: 600; font-size: .86rem; }
.tab:hover { background: var(--panel-2); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.search input { background: var(--panel-2); }
.chats { overflow-y: auto; flex: 1; min-height: 0; }
.chat { display: flex; gap: .85rem; width: 100%; padding: .85rem 1rem; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; align-items: center; }
.chat:hover { background: var(--panel-2); }
.chat[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.chat .avatar { width: 2.75rem; height: 2.75rem; }
.chat .meta { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: .2rem; }
.chat .top { display: flex; gap: .6rem; justify-content: space-between; align-items: baseline; }
.chat .name { font-weight: 650; }
.chat .time { font-size: .75rem; color: var(--muted); flex: none; }
.preview { display: flex; align-items: center; gap: .35rem; min-width: 0; flex: 1; }
.preview .icon { width: 1rem; height: 1rem; }
.chat .bottom { display: flex; gap: .6rem; justify-content: space-between; align-items: center; color: var(--muted); font-size: .88rem; }
.chat.unread .name, .chat.unread .time { color: var(--accent); }
.unread-pill { background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: .72rem; min-width: 1.35rem; text-align: center; padding: .05rem .4rem; border-radius: var(--r-xs); }
.empty { display: grid; place-items: center; align-content: center; text-align: center; gap: .75rem; padding: 2rem 1.5rem; color: var(--muted); height: 100%; }
.empty .icon { width: 2.6rem; height: 2.6rem; opacity: .6; }

.convo { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--wallpaper); }
.convo-head { display: flex; align-items: center; gap: .8rem; padding: .75rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.back { display: none; }
.thread { flex: 1; overflow-y: auto; padding: .6rem clamp(.75rem, 5vw, 4rem); display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.day { align-self: center; margin: .6rem 0 .4rem; padding: .15rem .7rem; border-radius: var(--r-sm); background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: .76rem; font-weight: 550; }
/* Bubbles follow WhatsApp Web: 14.2px text on a 19px line, 2px between messages
   of one sender, a wider gap when the sender changes, and the time floated to
   the end of the last line instead of sitting on a row of its own. */
.msg { position: relative; max-width: min(36rem, 80%); padding: .375rem .75rem .4rem; border-radius: var(--r-lg); background: var(--bubble-in); border: 1px solid var(--bubble-in-line); align-self: flex-start; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 14.2px; line-height: 19px; }
.msg::after { content: ""; display: table; clear: both; }
.msg.first { border-top-left-radius: var(--r-xs); margin-top: .45rem; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-color: var(--bubble-out-line); }
.msg.out.first { border-top-left-radius: var(--r-lg); border-top-right-radius: var(--r-xs); }
.msgrow.first { margin-top: .45rem; }
.msgrow .msg.first { margin-top: 0; }
.msg .wa { display: contents; }
.msg .who { font-size: .78rem; font-weight: 650; color: var(--accent); line-height: 1.3; margin-bottom: .1rem; }
.msg .who.sender { display: flex; gap: .5rem; align-items: baseline; justify-content: space-between; color: hsl(var(--who-h, 160) 55% var(--who-l)); }
.who-num { font-weight: 400; font-size: .72rem; color: var(--muted); }
.msg .media { font-style: italic; color: var(--muted); }
.msg .foot { float: right; display: inline-flex; align-items: center; gap: .25rem; margin: .45rem -.15rem -.25rem .6rem; font-size: .69rem; line-height: 1; color: var(--muted); user-select: none; }
.msg .foot .icon { width: .9rem; height: .9rem; }
.msg.failed .foot { color: var(--bad); }
.loadmore { align-self: center; margin: .25rem 0 .5rem; }
.composer { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; padding: .8rem 1rem; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1 1 0; min-width: 0; resize: none; max-height: 8rem; padding: .65rem .85rem; line-height: 1.4; }
.send { width: 2.6rem; height: 2.6rem; border: 0; border-radius: var(--r-md); background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; flex: none; }
.send:hover { filter: brightness(1.08); }
.send:disabled { opacity: .5; cursor: not-allowed; }
.notice { padding: .75rem 1rem; background: var(--wait-bg); color: var(--wait); font-size: .88rem; border-top: 1px solid var(--line); }

/* Reply / quote */
.msgrow { display: flex; align-items: center; gap: .25rem; align-self: flex-start; max-width: min(38rem, 90%); }
.msgrow .msg { align-self: auto; max-width: none; }
.replybtn { opacity: 0; width: 2rem; height: 2rem; transition: opacity .12s; }
.replybtn .icon { width: 1.05rem; height: 1.05rem; }
.msgrow:hover .replybtn, .replybtn:focus-visible { opacity: 1; }
@media (hover: none) { .replybtn { opacity: .55; } }
.msg .quote { display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; width: 100%; margin: 0 0 .3rem; padding: .3rem .6rem; text-align: left; border: 0; border-left: 3px solid var(--accent); border-radius: var(--r-sm); background: var(--quote-bg); color: inherit; cursor: pointer; white-space: normal; }
.quote .who { font-size: .78rem; font-weight: 650; color: var(--accent); margin: 0; }
.quote .qtext { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.msg.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }
.replybar { flex: 0 0 100%; display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem .5rem .8rem; border-left: 3px solid var(--accent); border-radius: var(--r-sm); background: var(--panel-2); }
.replybar .quote { display: flex; flex-direction: column; background: transparent; border: 0; padding: 0; margin: 0; cursor: default; min-width: 0; }
.replybar .qtext { -webkit-line-clamp: 2; }
.replybar[hidden] { display: none; }

/* Pages (devices, users) */
.page { height: 100%; overflow-y: auto; padding: 1.5rem clamp(1rem, 3vw, 2.25rem) 3rem; }
.page-inner { max-width: 64rem; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }
.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.15rem 1.25rem; }
.card-head { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 25rem), 1fr)); }
.kv { display: grid; grid-template-columns: 8.5rem 1fr; gap: .5rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.banner { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; padding: .85rem 1.1rem; border-radius: var(--r-lg); background: var(--wait-bg); color: var(--wait); }
.banner code { background: var(--panel); color: var(--ink); padding: .2rem .55rem; border-radius: var(--r-sm); overflow-wrap: anywhere; user-select: all; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: .75rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { color: var(--muted); font-size: .78rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.qr { display: block; width: 15rem; height: 15rem; max-width: 100%; object-fit: contain; background: #fff; border-radius: var(--r-lg); padding: .5rem; margin: 0 auto; }

/* Modal, toasts */
.modal { position: fixed; inset: 0; z-index: 30; background: rgb(8 14 18 / .55); display: grid; place-items: center; padding: 1rem; }
.dialog { width: 100%; max-width: 34rem; max-height: 92dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.35rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1.1rem; }
.dialog.wide { max-width: 44rem; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 40; display: flex; flex-direction: column; gap: .5rem; max-width: calc(100vw - 2rem); }
.toast { background: var(--ink); color: var(--panel); padding: .7rem 1rem; border-radius: var(--r-md); box-shadow: var(--shadow); max-width: 24rem; }
.toast.bad { background: var(--bad); color: #fff; }

/* Narrow screens: one column, rail becomes a bottom bar. */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { order: 2; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom)); }
  .rail .logo, .rail .spacer { display: none; }
  .inbox { grid-template-columns: 1fr; }
  .inbox .convo { display: none; }
  .inbox.open .list-pane { display: none; }
  .inbox.open .convo { display: flex; }
  .back { display: inline-grid; }
  .thread { padding: 1rem .9rem; }
  .msg { max-width: 88%; }
  .msgrow { max-width: 94%; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: .6rem; }
  .tbl.responsive thead { display: none; }
  .tbl.responsive tr { display: block; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .tbl.responsive td { display: block; border: 0; padding: .25rem .25rem; }
  .toasts { bottom: 4.8rem; }
  .login-card { padding: 1.5rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .msg, .toast, .dialog { animation: pop .14s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}

/* WhatsApp text formatting (see format.js) */
.msg .wa strong { font-weight: 700; }
.msg a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.wa-mono, .wa-pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: .9em; }
.wa-mono { background: var(--quote-bg); padding: .08rem .35rem; border-radius: var(--r-xs); }
.wa-pre { margin: .35rem 0; padding: .6rem .8rem; border-radius: var(--r-sm); background: var(--quote-bg); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.wa-quote { margin: .35rem 0; padding: .1rem 0 .1rem .75rem; border-left: 3px solid var(--line-strong); color: var(--muted); white-space: pre-wrap; }
.wa-list { margin: .3rem 0; padding-left: 1.4rem; white-space: normal; }
.wa-list li { margin: .1rem 0; padding-left: .2rem; }
.qtext .wa-mono { padding: 0 .25rem; }

/* Attachments */
.mlink { display: block; margin: 0 0 .3rem; line-height: 0; border-radius: var(--r-sm); overflow: hidden; }
.mimg { display: block; max-width: min(100%, 20rem); max-height: 22rem; min-width: 8rem; min-height: 5rem; background: var(--quote-bg); border-radius: var(--r-sm); object-fit: contain; }
.mimg.loaded { min-width: 0; min-height: 0; background: transparent; }
.mimg.sticker { max-width: 9rem; max-height: 9rem; background: transparent; }
.mvid { display: block; max-width: min(100%, 22rem); max-height: 22rem; margin: 0 0 .3rem; border-radius: var(--r-sm); background: #000; }
.maudio { display: block; width: 16rem; max-width: 100%; margin: 0 0 .3rem; }
.mfile { display: flex; align-items: center; gap: .65rem; width: 100%; min-width: 13rem; margin: 0 0 .3rem; padding: .55rem .7rem; border: 0; border-radius: var(--r-sm); background: var(--quote-bg); color: inherit; font: inherit; text-align: left; text-decoration: none; cursor: pointer; white-space: normal; }
.msg a.mfile { color: inherit; text-decoration: none; }
.mfile:hover { filter: brightness(.97); }
.mfile .ellipsis { font-weight: 600; }
.mfile.off { cursor: default; color: var(--muted); }
.mfile > .icon:first-child { width: 1.6rem; height: 1.6rem; color: var(--accent); }
.mname { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.mmeta { font-size: .76rem; color: var(--muted); }

/* Delivery ticks */
.tick { display: inline-flex; }
.tick.read { color: #34a9e8; }
.tick.err { color: var(--bad); }
