:root {
  --bg: #f3f1ec;
  --panel: #ffffff;
  --panel-2: #faf9f6;
  --ink: #17231f;
  --ink-2: #4b5a55;
  --ink-3: #85918c;
  --line: #e4e1d9;
  --brand: #0e3b36;
  --brand-ink: #f6f3ea;
  --accent: #0f7a6c;
  --accent-soft: #e2f1ed;
  --gold: #f4c26b;
  --danger: #b4382f;
  --danger-soft: #fbe9e7;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --ok: #1f8a5b;
  --ok-soft: #e3f4ea;
  --bubble-in: #ffffff;
  --bubble-out: #dcefe8;
  --chat-bg: #ebe7df;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.06), 0 8px 24px rgba(20, 30, 25, 0.08);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", "Segoe UI Arabic", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --panel: #161e1b;
    --panel-2: #1b2420;
    --ink: #e8ece9;
    --ink-2: #aab5b0;
    --ink-3: #78847f;
    --line: #26312d;
    --brand: #0b2a26;
    --accent: #3fb59f;
    --accent-soft: #17322c;
    --danger: #ef7a6f;
    --danger-soft: #3a1d1a;
    --warn: #e6b157;
    --warn-soft: #33281a;
    --ok: #54c38f;
    --ok-soft: #173126;
    --bubble-in: #1e2925;
    --bubble-out: #19403a;
    --chat-bg: #111917;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px;
  border: 0; background: transparent; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--ink-3); }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 9px;
  padding: 9px 11px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 84px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; margin-bottom: 10px; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 22px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; flex: none; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 19px; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--panel-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Login ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #1b5a51 0%, transparent 60%), var(--brand);
}
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow); }
.brandmark { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.01em; margin-bottom: 6px; }
.brandmark .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; }
.login-card p { margin: 0 0 22px; color: var(--ink-3); }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: -4px 0 10px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 76px 1fr; height: 100vh; height: 100dvh; }
.rail { background: var(--brand); color: var(--brand-ink); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail .logo { width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,.08); display: grid; place-items: center; margin-bottom: 14px; }
.rail a {
  width: 56px; padding: 8px 0 6px; border-radius: 12px; display: grid; justify-items: center; gap: 3px;
  color: rgba(246,243,234,.72); text-decoration: none; font-size: 10.5px; font-weight: 600; position: relative;
}
.rail a svg { width: 22px; height: 22px; }
.rail a:hover { background: rgba(255,255,255,.06); color: #fff; }
.rail a.active { background: rgba(255,255,255,.12); color: #fff; }
.rail a.active::before { content: ""; position: absolute; left: -10px; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--gold); }
.rail .badge { position: absolute; top: 3px; right: 8px; background: var(--gold); color: #3a2a06; border-radius: 99px; font-size: 10px; padding: 0 5px; min-width: 16px; line-height: 16px; text-align: center; }
.rail .spacer { flex: 1; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: 13px; color: #fff; background: var(--accent); text-transform: uppercase;
}
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ---------- Page (non-inbox) ---------- */
.page { padding: 28px clamp(16px, 4vw, 40px); overflow: auto; height: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card h3 { margin: 0; font-size: 16px; }
.card .meta { display: flex; gap: 14px; color: var(--ink-3); font-size: 13px; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.empty { text-align: center; padding: 50px 20px; color: var(--ink-3); border: 1px dashed var(--line); border-radius: var(--radius); background: var(--panel); }
.empty h3 { color: var(--ink); margin: 0 0 6px; }

.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); background: var(--panel-2); }
.table tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 360px 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; }
.list-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.list-head .title { display: flex; align-items: center; justify-content: space-between; }
.list-head h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); }
.search .input { padding-left: 32px; background: var(--panel-2); }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 6px 4px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.tabs button.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tabs .count { font-size: 11px; color: var(--ink-3); margin-left: 3px; }
.list-filters { display: flex; gap: 8px; }
.list-filters select { flex: 1; padding: 6px 8px; font-size: 13px; }

.conv-list { overflow-y: auto; flex: 1; }
.conv {
  display: grid; grid-template-columns: auto 1fr auto; gap: 11px; padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line); align-items: center; text-decoration: none; color: inherit;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--accent-soft); }
.conv .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .preview { color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .preview { color: var(--ink); font-weight: 550; }
.conv .side { display: grid; justify-items: end; gap: 4px; font-size: 11.5px; color: var(--ink-3); }
.conv.unread .time { color: var(--accent); font-weight: 600; }
.conv .unread-badge { background: var(--accent); color: #fff; border-radius: 99px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.conv .tags { display: flex; gap: 5px; margin-top: 3px; overflow: hidden; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.tag.me { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); }
.chat-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--ink-3); padding: 30px; }
.chat-empty .art { width: 84px; height: 84px; border-radius: 26px; background: var(--panel); display: grid; place-items: center; margin: 0 auto 14px; box-shadow: var(--shadow); }
.chat-head {
  background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 14px;
  display: flex; align-items: center; gap: 12px; min-height: 64px;
}
.chat-head .who { min-width: 0; flex: 1; }
.chat-head .who .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who .sub { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .tools { display: flex; gap: 8px; align-items: center; }
.chat-head select { width: auto; padding: 6px 8px; font-size: 13px; max-width: 170px; }
.back-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 18px clamp(12px, 4vw, 48px); display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; background: var(--panel); color: var(--ink-2); font-size: 12px; padding: 3px 12px; border-radius: 8px; margin: 10px 0; box-shadow: 0 1px 1px rgba(0,0,0,.05); }
.sys { align-self: center; font-size: 12px; color: var(--ink-2); background: rgba(255,255,255,.55); padding: 3px 11px; border-radius: 8px; margin: 4px 0; text-align: center; }
@media (prefers-color-scheme: dark) { .sys { background: rgba(255,255,255,.06); } }
.msg { max-width: min(78%, 560px); padding: 7px 10px 5px; border-radius: 10px; background: var(--bubble-in); align-self: flex-start; box-shadow: 0 1px 1px rgba(0,0,0,.06); position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .body { white-space: pre-wrap; }
.msg .media { font-weight: 600; color: var(--ink-2); }
.msg .foot { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.msg .by { font-size: 11.5px; font-weight: 700; color: var(--accent); margin-bottom: 1px; }
.msg .ticks { width: 15px; height: 15px; }
.msg .ticks.read { color: #2f8fd8; }
.msg.failed { outline: 1px solid var(--danger); }
.load-more { align-self: center; margin-bottom: 8px; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 12px; position: relative; }
.composer .bar { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; max-height: 160px;
  min-height: 42px; background: var(--panel-2); outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); background: var(--panel); }
.composer .send { width: 42px; height: 42px; border-radius: 12px; padding: 0; }
.composer .note { font-size: 12px; color: var(--ink-3); margin: 0 0 8px; }
.qr-pop {
  position: absolute; bottom: calc(100% + 6px); left: 12px; right: 12px; max-height: 260px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 5;
}
.qr-pop .item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.qr-pop .item:last-child { border-bottom: 0; }
.qr-pop .item.sel, .qr-pop .item:hover { background: var(--accent-soft); }
.qr-pop .item b { color: var(--accent); }
.qr-pop .item div { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 20, 17, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: var(--panel); border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); animation: pop .18s; }
.modal.wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

.qr-box { display: grid; place-items: center; gap: 12px; text-align: center; padding: 6px 0; }
.qr-box img { width: 260px; height: 260px; border-radius: 12px; background: #fff; padding: 8px; border: 1px solid var(--line); }
.qr-box ol { text-align: left; margin: 0; padding-left: 20px; color: var(--ink-2); }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { cursor: pointer; }
.days input { display: none; }
.days span { display: inline-block; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); font-weight: 600; font-size: 13px; }
.days input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.checks { display: grid; gap: 6px; max-height: 200px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.checks label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.section-title { font-weight: 700; margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.section-title:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 550; animation: pop .2s; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Install banner ---------- */
.install-banner { display: flex; align-items: center; gap: 10px; margin: 10px 12px 0; padding: 10px 6px 10px 12px; border-radius: 12px; background: var(--accent-soft); }
.install-banner img { width: 36px; height: 36px; border-radius: 9px; flex: none; }
.install-banner .icon-btn { width: 30px; height: 30px; }
@media (display-mode: standalone) {
  .shell, .login { padding-top: env(safe-area-inset-top); }
  .shell { background: var(--brand); }
  .main { background: var(--bg); }
}

/* ---------- Media in chat ---------- */
.msg .m-img { display: block; width: 260px; max-width: 100%; max-height: 340px; object-fit: cover; border-radius: 8px; cursor: zoom-in; background: rgba(0,0,0,.05); margin: 2px 0 4px; }
.msg .m-sticker { display: block; width: 130px; height: 130px; object-fit: contain; }
.msg .m-video { display: block; width: 280px; max-width: 100%; max-height: 360px; border-radius: 8px; background: #000; margin: 2px 0 4px; }
.media-pending, .media-retry { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink-2); padding: 10px 4px; background: none; border: 0; font: inherit; cursor: default; }
.media-retry { cursor: pointer; color: var(--danger); text-align: left; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.voice { display: flex; align-items: center; gap: 10px; width: 250px; max-width: 100%; padding: 4px 2px; }
.vp-play { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.vp-play svg { width: 18px; height: 18px; }
.vp-track { flex: 1; height: 22px; position: relative; cursor: pointer; }
.vp-track::before { content: ""; position: absolute; left: 0; right: 0; top: 10px; height: 3px; border-radius: 3px; background: rgba(0,0,0,.14); }
@media (prefers-color-scheme: dark) { .vp-track::before { background: rgba(255,255,255,.18); } }
.vp-fill { position: absolute; left: 0; top: 10px; height: 3px; border-radius: 3px; background: var(--accent); width: 0; }
.vp-knob { position: absolute; top: 5px; width: 13px; height: 13px; margin-left: -6px; border-radius: 50%; background: var(--accent); left: 0; }
.vp-time { font-size: 12px; color: var(--ink-3); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.m-doc { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; background: rgba(0,0,0,.045); text-decoration: none; color: var(--ink); width: 270px; max-width: 100%; margin: 2px 0 4px; }
@media (prefers-color-scheme: dark) { .m-doc { background: rgba(255,255,255,.06); } }
.m-doc-icon { position: relative; width: 36px; height: 44px; flex: none; color: var(--accent); display: grid; place-items: center; }
.m-doc-icon svg { width: 36px; height: 44px; }
.m-doc-icon b { position: absolute; bottom: 7px; font-size: 8px; font-weight: 800; letter-spacing: .02em; }
.m-doc-info { display: grid; min-width: 0; flex: 1; }
.m-doc-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-doc-dl { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink-2); flex: none; }
.m-doc-dl svg { width: 16px; height: 16px; }
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.92); display: grid; place-items: center; animation: fade .15s; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox-bar { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; display: flex; gap: 6px; }
.lightbox-bar .icon-btn { color: #fff; background: rgba(255,255,255,.12); width: 42px; height: 42px; border-radius: 50%; }
.pv { display: grid; place-items: center; }
.pv-img { max-width: 100%; max-height: 52dvh; border-radius: 10px; background: #000; }
.chat-pane.drop { outline: 3px dashed var(--accent); outline-offset: -8px; }
.rec-bar { align-items: center !important; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e5484d; animation: pulse 1s ease-in-out infinite; flex: none; margin-left: 4px; }
@keyframes pulse { 50% { opacity: .3; } }
.rec-time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 40px; }
.rec-hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer .send.hidden { display: none !important; }

/* ---------- Shared bits for the phone layout ---------- */
.m-only { display: none !important; }
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }
.fab {
  position: absolute; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 18px;
  border: 0; background: var(--accent); color: #fff; place-items: center; cursor: pointer; z-index: 3;
  box-shadow: 0 6px 18px rgba(15, 122, 108, .35), 0 2px 4px rgba(0,0,0,.15);
}
.fab svg { width: 26px; height: 26px; }
.sheet-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin: 14px 4px 6px; }
.sheet-label:first-child { margin-top: 0; }
.sheet-item {
  width: 100%; display: flex; align-items: center; gap: 14px; padding: 12px 6px; border: 0; background: none; cursor: pointer;
  text-align: left; font-size: 15px; border-radius: 10px; color: var(--ink);
}
.sheet-item:hover, .sheet-item:active { background: var(--panel-2); }
.sheet-item > svg { width: 22px; height: 22px; color: var(--ink-2); flex: none; margin: 0 4px; }
.sheet-check { color: var(--accent); display: inline-grid; }
.sheet-check svg { width: 20px; height: 20px; }

/* ---------- Mobile: WhatsApp-style ---------- */
@media (max-width: 860px) {
  .m-only { display: inline-grid !important; }
  .d-only { display: none !important; }
  .input, textarea.input, select.input, .composer textarea { font-size: 16px; } /* stops iPhone zooming in on focus */

  /* App frame + bottom tab bar */
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail {
    order: 2; flex-direction: row; justify-content: space-around; align-items: stretch; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line);
  }
  .rail .logo, .rail .spacer, .rail .avatar-link { display: none !important; }
  .rail a { flex: 1; width: auto; padding: 2px 0; color: var(--ink-3); font-size: 11.5px; gap: 4px; background: none !important; display: grid !important; }
  .rail a svg { width: 56px; height: 30px; padding: 4px 16px; border-radius: 99px; box-sizing: border-box; transition: background .15s; }
  .rail a.active { color: var(--ink); }
  .rail a.active svg { background: var(--accent-soft); color: var(--accent); }
  .rail a.active::before { display: none; }
  .rail .badge { top: 0; right: calc(50% - 26px); }
  .main { order: 1; min-height: 0; }

  /* Chats page */
  .inbox { grid-template-columns: 1fr; }
  .inbox .chat-pane { display: none; }
  .inbox.show-chat .list-pane { display: none; }
  .inbox.show-chat .chat-pane { display: flex; }
  .list-pane { border-right: 0; position: relative; }
  .list-head { padding: calc(12px + env(safe-area-inset-top)) 16px 10px; border-bottom: 0; gap: 12px; }
  .list-head h2 { font-size: 26px; color: var(--accent); letter-spacing: -.03em; }
  .search .input { border-radius: 99px; border-color: transparent; padding: 10px 14px 10px 38px; }
  .search svg { left: 14px; }
  .tabs { background: none; padding: 0; gap: 8px; overflow-x: auto; scrollbar-width: none; }
  .tabs button { flex: none; border-radius: 99px; padding: 7px 14px; background: var(--panel-2); border: 1px solid var(--line); font-size: 14px; }
  .tabs button.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; box-shadow: none; }
  .tabs button.active .count { color: var(--accent); }
  .list-filters select { border-radius: 99px; padding: 7px 12px; font-size: 14px; background: var(--panel-2); border-color: transparent; }
  .conv-list { padding-bottom: 96px; }
  .conv { padding: 11px 16px; gap: 13px; border-bottom: 0; position: relative; }
  .conv::after { content: ""; position: absolute; left: 77px; right: 0; bottom: 0; border-bottom: 1px solid var(--line); }
  .conv .avatar { width: 50px; height: 50px; font-size: 16px; }
  .conv .name { font-size: 16px; }
  .conv .preview { font-size: 14px; }
  .conv .side { font-size: 12px; }
  .conv.active { background: transparent; }
  .install-banner { margin: 4px 16px 8px; }

  /* Chat page */
  .shell.chat-open .rail { display: none; }
  .shell.chat-open { grid-template-rows: 1fr; }
  .back-btn { display: inline-grid; }
  .chat-head {
    background: var(--brand); color: #fff; border-bottom: 0; gap: 6px; min-height: 60px;
    padding: calc(6px + env(safe-area-inset-top)) 4px 6px 2px;
  }
  .chat-head .icon-btn { color: #fff; }
  .chat-head .icon-btn:hover { background: rgba(255,255,255,.1); }
  .chat-head .avatar { width: 40px; height: 40px; }
  .chat-head .who .name { font-size: 16.5px; }
  .chat-head .who .sub { color: rgba(255,255,255,.72); }
  .chat-pane { background-color: var(--chat-bg); }
  .messages {
    padding: 12px 10px 8px; gap: 3px;
    background-image: radial-gradient(rgba(0,0,0,.045) 1.2px, transparent 1.4px);
    background-size: 20px 20px;
  }
  .msg { max-width: 84%; border-radius: 12px; border-top-left-radius: 3px; padding: 6px 9px 4px; font-size: 15px; }
  .msg.out { border-top-left-radius: 12px; border-top-right-radius: 3px; }
  .day-sep { font-size: 12.5px; }
  .composer { background: transparent; border-top: 0; padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer .bar { gap: 6px; align-items: flex-end; }
  .composer textarea { border-radius: 24px; background: var(--panel); border-color: transparent; padding: 11px 16px; min-height: 46px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
  .composer textarea:focus { border-color: transparent; }
  .composer #qr-btn { width: 46px; height: 46px; border-radius: 50%; background: var(--panel); box-shadow: 0 1px 1px rgba(0,0,0,.06); }
  .composer .send { width: 46px; height: 46px; border-radius: 50%; flex: none; }
  .composer #attach-btn { width: 40px; height: 46px; margin-left: -4px; }
  .composer #qr-btn { display: none; } /* phones: type / for quick replies */
  .rec-bar { background: var(--panel); border-radius: 24px; padding: 0 0 0 6px; }
  .msg .m-img { width: 240px; }
  .composer .note { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 10px; }
  .qr-pop { left: 8px; right: 8px; border-radius: 16px; }

  /* Pop-ups slide up from the bottom, like WhatsApp sheets */
  .modal-backdrop { align-items: end; padding: 0; }
  .modal, .modal.wide {
    max-width: none; border-radius: 20px 20px 0 0; max-height: 92dvh;
    padding-bottom: env(safe-area-inset-bottom); animation: slideup .22s ease-out;
  }
  .modal-head { position: relative; padding-top: 22px; }
  .modal-head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 4px; background: var(--line); }
  .qr-box img { width: min(260px, 70vw); height: auto; aspect-ratio: 1; }

  /* Other pages */
  .page { padding: calc(16px + env(safe-area-inset-top)) 16px 24px; }
  .page-head h1 { font-size: 24px; }
  .cards { grid-template-columns: 1fr; }
  .table .hide-sm { display: none; }
  #toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
