:root {
  --navy: #16375E;
  --navy-2: #e8eef6;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e2e6ec;
  --panel: #f4f6f8;
  --card: #ffffff;
  --link: #2563eb;
  --bad: #b91c1c;
  --bad-bg: #fef2f2;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --good: #15803d;
  --good-bg: #ecfdf3;
  --info-bg: #eff6ff;
  --tab-h: 62px;
  --accent-fg: #16375E;
  --ai: #7e22ce;
  --ai-bg: #f3e8ff;
  --side-m: #16375E;
  --side-m-bg: #dbe6f3;
  --side-r: #0f766e;
  --side-r-bg: #ccfbf1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy: #3b6ea8; --navy-2: #1c2a3b; --ink: #e5e7eb; --muted: #9ca3af; --line: #2a3340;
    --panel: #0f141a; --card: #171d25; --link: #7aa7ff; --bad: #f87171; --bad-bg: #2a1515;
    --warn: #fbbf24; --warn-bg: #2a2110; --good: #4ade80; --good-bg: #0f2418; --info-bg: #142033; --accent-fg: #cfe0f5; --ai: #c084fc; --ai-bg: #2a1a3a; --side-m: #cfe0f5; --side-m-bg: #1f3350; --side-r: #5eead4; --side-r-bg: #11302d; color-scheme: dark; }
}
:root[data-theme="dark"] {
    --navy: #3b6ea8; --navy-2: #1c2a3b; --ink: #e5e7eb; --muted: #9ca3af; --line: #2a3340;
    --panel: #0f141a; --card: #171d25; --link: #7aa7ff; --bad: #f87171; --bad-bg: #2a1515;
    --warn: #fbbf24; --warn-bg: #2a2110; --good: #4ade80; --good-bg: #0f2418; --info-bg: #142033; --accent-fg: #cfe0f5; --ai: #c084fc; --ai-bg: #2a1a3a; --side-m: #cfe0f5; --side-m-bg: #1f3350; --side-r: #5eead4; --side-r-bg: #11302d; color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--panel); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* top bar */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #16375E; color: #fff;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.bar-left { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.bar-left b { font-size: 16px; letter-spacing: .3px; }
.who { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avail { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; font-weight: 600; }
.avail input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.avail .track { width: 46px; height: 28px; border-radius: 14px; background: rgba(255,255,255,.25); position: relative; transition: background .15s; }
.avail .knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.avail input:checked + .track { background: #22c55e; }
.avail input:checked + .track .knob { transform: translateX(18px); }
.avail input:focus-visible + .track { outline: 2px solid #fff; outline-offset: 2px; }
.staging { background: var(--warn-bg); color: var(--warn); font-size: 12px; padding: 6px 16px; border-bottom: 1px solid var(--line); }

main { max-width: 640px; margin: 0 auto; padding-block: 12px 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: #16375E; }
h1.page { font-size: 20px; margin: 4px 0 10px; }
.sub { color: var(--muted); font-size: 13px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 16px 0 6px; font-weight: 700; }

/* chips / filters */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 8px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.filters button[aria-pressed=true] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--navy-2); color: var(--accent-fg); white-space: nowrap; }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.good { background: var(--good-bg); color: var(--good); }

/* queue cards */
.qcard { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; color: inherit; text-decoration: none; position: relative; }
.qlink { position: absolute; inset: 0; border-radius: 12px; z-index: 1; }
.qactions { position: relative; z-index: 2; }
.qcard.p1 { border-left: 4px solid var(--bad); }
.qcard.p2 { border-left: 4px solid var(--warn); }
.qcard.p3 { border-left: 4px solid var(--navy); }
.qtop { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.qname { font-weight: 700; font-size: 16px; }
.qwhen { font-size: 12px; color: var(--muted); white-space: nowrap; }
.qreason { margin: 2px 0 6px; font-size: 14px; }
.qmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.qactions { display: flex; gap: 8px; margin-top: 10px; }
.btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); text-decoration: none; color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; padding: 0 10px; }
.btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.good { background: #15803d; border-color: #15803d; color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* contact */
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; text-decoration: none; margin-bottom: 6px; }
.chead { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.chead h1 { margin: 0; font-size: 22px; }
.chead .line { color: var(--muted); font-size: 13px; margin-top: 2px; }
.chead .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cactions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.cactions .btn { flex-direction: column; gap: 2px; min-height: 58px; font-size: 12px; }
.cactions .btn svg { width: 20px; height: 20px; }
.flag { margin-top: 10px; font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--bad-bg); color: var(--bad); }
.flag.info { background: var(--info-bg); color: var(--ink); }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin: 12px 0; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-selected=true] { background: var(--navy-2); color: var(--ink); }

/* timeline */
.day { font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .4px; }
.ev { display: grid; grid-template-columns: 32px 1fr; gap: 10px; margin-bottom: 10px; }
.ev .ic { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--navy-2); }
.ev .ic svg { width: 16px; height: 16px; stroke: var(--accent-fg); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ev.missed .ic { background: var(--bad-bg); } .ev.missed .ic svg { stroke: var(--bad); }
.ev.ai .ic { background: var(--ai-bg); } .ev.ai .ic svg { stroke: var(--ai); }
.ev .body { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.ev .head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.ev .head b { font-weight: 700; }
.ev .head time { color: var(--muted); white-space: nowrap; font-size: 12px; }
.ev .txt { font-size: 14px; margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ev .by { font-size: 12px; color: var(--muted); margin-top: 3px; }
.ev.sms-in .body { background: var(--panel); }
.ev.sms-out .body { background: var(--info-bg); }
.ev .pending { font-size: 11px; color: var(--warn); font-weight: 700; }

.kv { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

/* tasks */
.task { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 8px; }
.task input[type=checkbox] { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: #15803d; }
.task .t-main { flex: 1; min-width: 0; }
.task .t-title { font-weight: 600; }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.task .t-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.task .t-meta a { text-decoration: none; }
.overdue { color: var(--bad) !important; font-weight: 700; }

/* search */
.search { position: relative; }
.search input { width: 100%; padding: 12px 14px; font-size: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); }
.hit { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 8px; text-decoration: none; color: inherit; }
.hit span { display: block; font-size: 12px; color: var(--muted); }

/* tabs */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; position: relative; }
.tabs a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--accent-fg); font-weight: 700; }
.badge { position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-style: normal; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 90vh; overflow: auto; background: var(--card); border-radius: 16px 16px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.x { border: 0; background: none; font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.sheet label { display: block; font-size: 13px; font-weight: 700; margin: 10px 0 4px; }
.sheet textarea, .sheet input, .sheet select { width: 100%; padding: 10px 12px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.sheet textarea { min-height: 110px; resize: vertical; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.quick button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.sheet .btn { width: 100%; margin-top: 14px; }
.note-ro { font-size: 12px; color: var(--warn); margin-top: 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.skeleton { height: 92px; border-radius: 12px; background: linear-gradient(90deg, var(--card), var(--line), var(--card)); background-size: 200% 100%; animation: sh 1.2s infinite; margin-bottom: 10px; }
@keyframes sh { to { background-position: -200% 0; } }

.chip.side-mortgage { background: var(--side-m-bg); color: var(--side-m); }
.chip.side-real_estate { background: var(--side-r-bg); color: var(--side-r); }
.mirror { margin-top: 10px; font-size: 12px; color: var(--muted); }
.sync { color: var(--good); font-weight: 600; }
.sync.wait { color: var(--warn); }
.sync.bad { color: var(--bad); }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.pick button { min-height: 44px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 8px; font-size: 14px; cursor: pointer; text-align: left; }
.pick button[aria-pressed=true] { background: var(--navy-2); border-color: var(--navy); font-weight: 700; cursor: default; }
.sheet .sub .chip { margin: 2px 2px 0 0; }

.halves { display: grid; gap: 8px; margin-top: 10px; }
.half { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.half.mine { border-color: var(--navy); }
.half:not(.mine) { background: var(--panel); }
.half-head { display: flex; align-items: center; gap: 8px; }
.half-head .chip { margin-left: auto; }
.half-kv { margin: 6px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.half-kv dt { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.half-kv dd { margin: 0; font-size: 14px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.half-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
