/* Care Connection Inbox — v9 interface
   Palette: pine (brand, outbound), marigold (waiting / internal notes), rose (overdue), on cool paper.
   One family: Public Sans, tabular figures for every time and count. */

@font-face { font-family: "Public Sans"; src: url("/fonts/public-sans.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --paper: #F3F5F3; --surface: #FFFFFF; --surface-2: #F8FAF8; --sunken: #EBEFEC;
  --ink: #17242B; --ink-2: #46555C; --ink-3: #6E7B81; --line: #DFE4E1; --line-strong: #C8D0CC;
  --pine: #1F5C4A; --pine-ink: #FFFFFF; --pine-hover: #18493B; --pine-soft: #E3EFE9; --pine-text: #1A5141;
  --marigold: #C67A12; --marigold-soft: #FBF1DE; --marigold-line: #EBC888; --marigold-text: #8A520A;
  --rose: #B23A31; --rose-soft: #FBE9E7; --rose-text: #9A2F27;
  --sky: #2F78B4; --sky-soft: #E4EFF8; --plum: #7A4E86; --plum-soft: #F1E8F3; --slate: #5D6B72; --slate-soft: #E9EDEE;
  --bubble-in: #FFFFFF; --bubble-out: #DCEEE5; --wall: #EEF1EE;
  --chart-in: #2F78B4; --chart-out: #2E8A62;
  --focus: #2F78B4;
  --shadow-pop: 0 12px 32px rgba(18, 33, 40, .16), 0 2px 6px rgba(18, 33, 40, .08);
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --rail: 64px; --list: 372px; --details: 320px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #0F1518; --surface: #161E22; --surface-2: #1A2328; --sunken: #11181B;
  --ink: #E4EBE8; --ink-2: #AEBAB6; --ink-3: #85928F; --line: #263137; --line-strong: #34424A;
  --pine: #3E9C7A; --pine-ink: #06140F; --pine-hover: #4CAE8A; --pine-soft: #193429; --pine-text: #7FD1B0;
  --marigold: #E2A04A; --marigold-soft: #33260F; --marigold-line: #6B4E1E; --marigold-text: #F0BE73;
  --rose: #E06A5F; --rose-soft: #3A1C1A; --rose-text: #F2958B;
  --sky: #5FA0D6; --sky-soft: #172A3A; --plum: #B38BC0; --plum-soft: #2C2032; --slate: #95A3A9; --slate-soft: #222C31;
  --bubble-in: #1E282D; --bubble-out: #1C3A2F; --wall: #12191C;
  --chart-in: #4A8FC7; --chart-out: #3EA276;
  --focus: #5FA0D6;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 14px/1.45 "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif; font-feature-settings: "tnum" 1; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--pine-text); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- Buttons & fields ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; padding: 0 13px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 560; font-size: 13px; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--pine); border-color: var(--pine); color: var(--pine-ink); }
.btn-primary:hover { background: var(--pine-hover); border-color: var(--pine-hover); }
.btn-danger { color: var(--rose-text); border-color: color-mix(in srgb, var(--rose) 45%, transparent); }
.btn-danger:hover { background: var(--rose-soft); border-color: var(--rose); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--sunken); border-color: transparent; color: var(--ink); }
.btn-block { width: 100%; min-height: 42px; font-size: 14px; }
.btn-sm { min-height: 28px; padding: 0 9px; font-size: 12px; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--ink-2); padding: 0; flex: none; }
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn[aria-pressed="true"] { background: var(--pine-soft); color: var(--pine-text); }
kbd { font: 600 11px/1 "Public Sans", system-ui; padding: 3px 5px; border-radius: 4px; border: 1px solid var(--line-strong); border-bottom-width: 2px; background: var(--surface); color: var(--ink-2); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12px; }
.input, .field input, .field select, .field textarea { width: 100%; min-height: 38px; padding: 8px 11px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }
.field textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid color-mix(in srgb, var(--focus) 45%, transparent); outline-offset: 0; border-color: var(--focus); }
.form-error { margin: 0; padding: 9px 11px; border-radius: var(--r-sm); background: var(--rose-soft); color: var(--rose-text); font-size: 13px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Sign in ---------- */
.signin { position: fixed; inset: 0; display: grid; grid-template-columns: minmax(360px, 520px) 1fr; overflow: auto; }
.signin-panel { background: var(--surface); padding: clamp(28px, 7vh, 72px) clamp(24px, 5vw, 64px); display: flex; flex-direction: column; justify-content: center; gap: 0; border-right: 1px solid var(--line); }
.signin-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; margin-bottom: 44px; }
.signin-brand .mark { width: 34px; height: 34px; }
.mark rect { fill: var(--pine); }
.mark path { fill: none; stroke: #F6F7F5; stroke-width: 2.6; stroke-linecap: round; }
.mark circle { fill: #E6A23C; }
.signin h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 10px; font-weight: 720; }
.signin-lede { margin: 0 0 30px; color: var(--ink-2); font-size: 15px; max-width: 34ch; }
#signin-form { display: grid; gap: 16px; max-width: 380px; }
.signin-foot { margin: 28px 0 0; color: var(--ink-3); font-size: 12.5px; max-width: 42ch; }
.signin-aside { background: var(--wall); display: grid; place-items: center; padding: 40px; }
.signin-chat { width: min(440px, 100%); display: grid; gap: 10px; }
.sc-row { position: relative; max-width: 82%; padding: 9px 12px 18px; border-radius: 12px; font-size: 14px; background: var(--bubble-in); box-shadow: 0 1px 0 var(--line); }
.sc-row p { margin: 0; }
.sc-row time { position: absolute; right: 10px; bottom: 4px; font-size: 11px; color: var(--ink-3); }
.sc-row b { position: absolute; left: 12px; bottom: 4px; font-size: 11px; font-weight: 600; color: var(--pine-text); }
.sc-out { justify-self: end; background: var(--bubble-out); }
.sc-note { justify-self: end; background: var(--marigold-soft); border: 1px dashed var(--marigold-line); box-shadow: none; }
.sc-note b { color: var(--marigold-text); }
.sc-wait { justify-self: start; font-size: 12px; font-weight: 600; color: var(--marigold-text); padding-left: 12px; border-left: 3px solid var(--marigold); }
.signin-legal { position: absolute; left: clamp(24px, 5vw, 64px); bottom: 18px; display: flex; gap: 16px; font-size: 12px; }
.signin-legal a { color: var(--ink-3); }
@media (max-width: 860px) { .signin { grid-template-columns: 1fr; } .signin-aside { display: none; } .signin-panel { border: 0; padding-bottom: 80px; } }

/* ---------- App shell ---------- */
.app { position: fixed; inset: 0; display: grid; grid-template-columns: var(--rail) 1fr; }
.rail { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 4px; z-index: 20; }
.rail .mark { width: 36px; height: 36px; margin-bottom: 14px; }
.rail-btn { position: relative; width: 44px; height: 44px; border-radius: var(--r); border: 0; background: transparent; color: var(--ink-3); display: grid; place-items: center; text-decoration: none; }
.rail-btn svg.i { width: 21px; height: 21px; }
.rail-btn:hover { background: var(--sunken); color: var(--ink); }
.rail-btn[aria-current="page"] { background: var(--pine-soft); color: var(--pine-text); }
.rail-btn .label { display: none; }
.rail-btn .tip { position: absolute; left: 54px; top: 50%; transform: translateY(-50%); padding: 5px 8px; border-radius: 5px; background: var(--ink); color: var(--paper); font-size: 12px; font-weight: 600; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s; }
.rail-btn:hover .tip, .rail-btn:focus-visible .tip { opacity: 1; }
.rail-btn .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--marigold); color: #1E1405; font-size: 10px; font-weight: 750; display: grid; place-items: center; border: 2px solid var(--surface); box-sizing: content-box; }
.rail-spacer { flex: 1; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; background: var(--sunken); color: var(--ink-2); letter-spacing: .02em; }
.avatar.me { background: var(--pine); color: var(--pine-ink); }
.views { min-width: 0; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow: auto; }

.banner { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 13px; border-bottom: 1px solid var(--marigold-line); background: var(--marigold-soft); color: var(--marigold-text); }
.banner.critical { background: var(--rose-soft); color: var(--rose-text); border-color: color-mix(in srgb, var(--rose) 40%, transparent); }
.banner strong { font-weight: 700; }
.banner .btn { margin-left: auto; }
.has-banner .views { display: grid; grid-template-rows: auto 1fr; }
.has-banner .views > .view { position: relative; inset: auto; }

/* ---------- Inbox layout ---------- */
.inbox { display: grid; grid-template-columns: var(--list) minmax(0, 1fr) var(--details); height: 100%; min-height: 0; overflow: hidden; }
.inbox.no-details { grid-template-columns: var(--list) minmax(0, 1fr) 0; }
.inbox.no-details .details { display: none; }
.list-pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.list-head { padding: 14px 14px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.list-title { display: flex; align-items: center; gap: 6px; }
.list-title h1 { font-size: 19px; margin: 0; font-weight: 720; letter-spacing: -.01em; margin-right: auto; }
.team-clock { font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 3px 8px; border-radius: 6px; background: var(--sunken); white-space: nowrap; margin-right: 2px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); margin-right: 4px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.live.on::before { background: #2E9A6A; box-shadow: 0 0 0 3px color-mix(in srgb, #2E9A6A 22%, transparent); }
.search { position: relative; }
.search svg.i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); width: 16px; height: 16px; }
.search input { width: 100%; height: 36px; padding: 0 34px 0 32px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2); }
.search input:focus { outline: 2px solid color-mix(in srgb, var(--focus) 45%, transparent); border-color: var(--focus); background: var(--surface); }
.search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; background: var(--sunken); border-radius: 8px; }
.segmented button { border: 0; background: transparent; border-radius: 6px; height: 28px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; justify-content: center; gap: 6px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segmented .n { font-weight: 500; color: var(--ink-3); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-size: 12.5px; font-weight: 560; color: var(--ink-2); }
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip .n { font-weight: 700; }
.chip.waiting .n { color: var(--marigold-text); }
.chip[aria-pressed="true"] .n { color: inherit; }
.chip select { border: 0; background: transparent; padding: 0; font-size: 12.5px; font-weight: 560; max-width: 120px; }

.bulkbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--ink); color: var(--paper); font-size: 13px; }
.bulkbar .btn { min-height: 28px; font-size: 12px; background: transparent; color: var(--paper); border-color: color-mix(in srgb, var(--paper) 30%, transparent); }
.bulkbar .btn:hover { background: color-mix(in srgb, var(--paper) 12%, transparent); }
.bulkbar span { margin-right: auto; font-weight: 600; }

.conv-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.conv { position: relative; display: grid; grid-template-columns: auto 1fr; gap: 11px; padding: 11px 14px 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; outline: none; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--pine-soft); }
.conv.kbd { box-shadow: inset 0 0 0 2px var(--focus); }
.conv.checked { background: var(--sky-soft); }
/* The wait bar: how long the customer has been waiting for a reply */
.conv::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: transparent; }
.conv.wait-due::before { background: var(--marigold); }
.conv.wait-over::before { background: var(--rose); }
.conv-avatar { position: relative; }
.conv-avatar .avatar { width: 40px; height: 40px; font-size: 13px; }
.conv-check { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 50%; background: var(--sky); color: #fff; opacity: 0; }
.conv-check svg.i { width: 18px; height: 18px; stroke-width: 2.4; }
.conv.checked .conv-check { opacity: 1; }
.selecting .conv-avatar:hover .conv-check, .conv-avatar:hover .conv-check { opacity: .9; }
.conv-main { min-width: 0; display: grid; gap: 2px; }
.conv-top, .conv-mid, .conv-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv-name { font-weight: 560; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: auto; }
.conv.unread .conv-name { font-weight: 750; }
.conv-time { font-size: 12px; color: var(--ink-3); flex: none; }
.conv.unread .conv-time { color: var(--pine-text); font-weight: 650; }
.conv-preview { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: auto; }
.conv.unread .conv-preview { color: var(--ink-2); }
.conv-preview .who { color: var(--ink-2); font-weight: 600; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--pine); color: var(--pine-ink); font-size: 11px; font-weight: 750; display: inline-grid; place-items: center; flex: none; }
.conv-bottom { margin-top: 3px; flex-wrap: wrap; gap: 5px; }
.wait { font-size: 11.5px; font-weight: 650; color: var(--marigold-text); }
.wait-over .wait { color: var(--rose-text); }
.owner { font-size: 11.5px; color: var(--ink-3); display: inline-flex; align-items: center; gap: 4px; }
.owner svg.i { width: 13px; height: 13px; }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 4px; font-size: 11.5px; font-weight: 600; background: var(--slate-soft); color: var(--ink-2); }
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--slate); }
.tag.pine { background: var(--pine-soft); } .tag.marigold { background: var(--marigold-soft); } .tag.rose { background: var(--rose-soft); } .tag.sky { background: var(--sky-soft); } .tag.plum { background: var(--plum-soft); }
.tag.pine::before { background: var(--pine); } .tag.marigold::before { background: var(--marigold); } .tag.rose::before { background: var(--rose); }
.tag.sky::before { background: var(--sky); } .tag.plum::before { background: var(--plum); } .tag.slate::before { background: var(--slate); }
.list-empty { padding: 48px 24px; text-align: center; color: var(--ink-3); }
.list-empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }

/* ---------- Thread ---------- */
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--wall); }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px 9px 16px; background: var(--surface); border-bottom: 1px solid var(--line); min-height: 60px; }
.thread-who { min-width: 0; margin-right: auto; }
.thread-who h2 { margin: 0; font-size: 15.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-sub { display: flex; gap: 10px; align-items: center; font-size: 12.5px; color: var(--ink-3); flex-wrap: wrap; }
.presence { color: var(--sky); font-weight: 600; }
.presence.typing { color: var(--marigold-text); }
.thread-actions { display: flex; align-items: center; gap: 4px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 11.5px; font-weight: 650; background: var(--pine-soft); color: var(--pine-text); }
.status-pill.pending { background: var(--sky-soft); color: var(--sky); }
.status-pill.closed { background: var(--sunken); color: var(--ink-3); }
.back-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px clamp(12px, 4%, 48px) 12px; overscroll-behavior: contain; }
.load-more { display: flex; justify-content: center; margin-bottom: 12px; }
.day { display: flex; justify-content: center; margin: 14px 0 10px; }
.day span { padding: 4px 10px; border-radius: 6px; background: var(--surface); color: var(--ink-2); font-size: 12px; font-weight: 600; box-shadow: 0 1px 0 var(--line); }
.msg { display: flex; margin: 3px 0; }
.msg.out { justify-content: flex-end; }
.bubble { position: relative; max-width: min(72%, 620px); padding: 7px 10px 6px; border-radius: 10px; background: var(--bubble-in); box-shadow: 0 1px 0 var(--line); overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--bubble-out); }
.msg.first.in .bubble { border-top-left-radius: 3px; }
.msg.first.out .bubble { border-top-right-radius: 3px; }
.bubble-text { white-space: pre-wrap; font-size: 14px; line-height: 1.42; }
.bubble-text a { word-break: break-all; }
.bubble-meta { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 3px; font-size: 11px; color: var(--ink-3); flex-wrap: wrap; }
.by { font-weight: 650; color: var(--pine-text); }
.by.phone { color: var(--sky); display: inline-flex; align-items: center; gap: 3px; }
.by.phone svg.i { width: 12px; height: 12px; }
.by.history { color: var(--ink-3); font-weight: 500; }
.ticks { display: inline-flex; color: var(--ink-3); }
.ticks svg.i { width: 15px; height: 15px; stroke-width: 2; }
.ticks.read { color: var(--sky); }
.ticks.failed { color: var(--rose); }
.reader { color: var(--ink-3); }
.edited { font-style: italic; }
.quote { margin: 0 0 5px; padding: 5px 8px; border-left: 3px solid var(--pine); background: color-mix(in srgb, var(--ink) 5%, transparent); border-radius: 4px; font-size: 12.5px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.kind-tag { display: inline-block; font-size: 11px; font-weight: 650; color: var(--plum); margin-bottom: 3px; }
.media { display: grid; gap: 6px; margin: 1px 0 4px; }
.media img { display: block; max-width: min(340px, 100%); max-height: 340px; border-radius: 7px; background: var(--sunken); cursor: zoom-in; object-fit: cover; }
.media audio, .media video { max-width: min(340px, 100%); }
.file { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 7px; background: color-mix(in srgb, var(--ink) 5%, transparent); text-decoration: none; color: var(--ink); font-size: 13px; }
.file small { color: var(--ink-3); display: block; }
.revoked .bubble-text { color: var(--ink-3); font-style: italic; }
.note-row { display: flex; justify-content: center; margin: 10px 0; }
.note { width: min(560px, 92%); padding: 9px 12px; border-radius: 8px; background: var(--marigold-soft); border: 1px dashed var(--marigold-line); }
.note-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--marigold-text); margin-bottom: 3px; }
.note-head strong { font-weight: 700; }
.note-head .icon-btn { width: 24px; height: 24px; margin-left: auto; color: var(--marigold-text); }
.note-body { white-space: pre-wrap; font-size: 13.5px; }
.mention { font-weight: 700; color: var(--marigold-text); }

/* Composer */
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 12px calc(10px + var(--safe-b)); position: relative; }
.composer-tabs { display: flex; align-items: center; gap: 2px; margin-bottom: 6px; }
.composer-tabs button { border: 0; background: transparent; height: 28px; padding: 0 10px; border-radius: 6px; font-size: 12.5px; font-weight: 650; color: var(--ink-3); }
.composer-tabs button[aria-pressed="true"] { background: var(--pine-soft); color: var(--pine-text); }
.composer-tabs button.note-tab[aria-pressed="true"] { background: var(--marigold-soft); color: var(--marigold-text); }
.window { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-3); }
.window.held { color: var(--sky); font-weight: 600; }
.msg.held .bubble { background: transparent; border: 1.5px dashed color-mix(in srgb, var(--pine) 55%, transparent); box-shadow: none; }
.held-state { display: inline-flex; align-items: center; gap: 4px; color: var(--sky); font-weight: 600; }
.held-state.failed { color: var(--rose-text); }
.held-state svg.i, .held-chip svg.i { width: 13px; height: 13px; }
.held-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650; color: var(--sky); }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink-2); font-size: 11px; font-weight: 650; text-decoration: underline; }
.held-preview { padding: 10px 12px; border-radius: 8px; border: 1.5px dashed color-mix(in srgb, var(--pine) 55%, transparent); }
.held-preview span { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--sky); }
.held-preview svg.i { width: 14px; height: 14px; }
.held-preview p { margin: 4px 0 0; white-space: pre-wrap; }
.window-meter { width: 54px; height: 5px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.window-meter i { display: block; height: 100%; background: var(--pine); border-radius: 3px; }
.window.low .window-meter i { background: var(--marigold); }
.window.low { color: var(--marigold-text); }
.window.closed { color: var(--rose-text); font-weight: 600; }
.compose-box { display: flex; align-items: flex-end; gap: 6px; border: 1px solid var(--line-strong); border-radius: var(--r); padding: 5px 5px 5px 6px; background: var(--surface); }
.compose-box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 30%, transparent); }
.compose-box.note-mode { background: var(--marigold-soft); border-color: var(--marigold-line); border-style: dashed; }
.compose-box textarea { flex: 1; border: 0; outline: 0; background: transparent; resize: none; min-height: 36px; max-height: 200px; padding: 8px 4px; line-height: 1.4; font-size: 14px; }
.send-btn { width: 36px; height: 36px; border-radius: 8px; border: 0; background: var(--pine); color: var(--pine-ink); display: grid; place-items: center; flex: none; }
.send-btn:hover { background: var(--pine-hover); }
.note-mode .send-btn { background: var(--marigold); color: #1E1405; }
.send-btn:disabled { opacity: .45; }
.compose-hint { display: flex; gap: 14px; margin-top: 6px; font-size: 11.5px; color: var(--ink-3); }
.closed-window { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--r); background: var(--rose-soft); color: var(--rose-text); font-size: 13px; }
.closed-window p { margin: 0; flex: 1; }
.closed-window strong { display: block; margin-bottom: 1px; }

.popover { position: absolute; z-index: 40; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-pop); padding: 6px; min-width: 220px; max-height: 340px; overflow-y: auto; }
.composer .popover { left: 12px; right: 12px; bottom: calc(100% - 6px); }
.pop-item { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent; border-radius: 7px; text-align: left; }
.pop-item:hover, .pop-item.active { background: var(--sunken); }
.pop-item b { font-size: 12.5px; color: var(--pine-text); grid-row: span 2; align-self: start; padding-top: 1px; }
.pop-item span { font-weight: 600; font-size: 13px; }
.pop-item small { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-empty { padding: 10px; color: var(--ink-3); font-size: 13px; }
.menu { min-width: 200px; }
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; height: 34px; padding: 0 10px; border: 0; background: transparent; border-radius: 6px; text-align: left; font-size: 13px; }
.menu button:hover { background: var(--sunken); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }
.menu .check { margin-left: auto; color: var(--pine-text); }

.thread-empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 30px; color: var(--ink-3); }
.thread-empty h2 { color: var(--ink); font-size: 18px; margin: 0 0 8px; }
.shortcut-grid { display: grid; grid-template-columns: auto auto; gap: 8px 16px; justify-content: center; margin-top: 18px; font-size: 13px; text-align: left; }
.shortcut-grid span:nth-child(odd) { text-align: right; }

/* ---------- Details panel ---------- */
.details { background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; min-width: 0; }
.details-head { display: none; }
.panel-sec { padding: 16px 18px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.panel-sec h3 { margin: 0; font-size: 12.5px; font-weight: 700; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.panel-sec h3 .btn { margin-left: auto; }
.contact-card { display: grid; justify-items: start; gap: 8px; }
.contact-card .avatar { width: 52px; height: 52px; font-size: 17px; }
.contact-name { display: flex; align-items: center; gap: 6px; font-size: 17px; font-weight: 720; }
.contact-name input { font: inherit; border: 1px solid var(--focus); border-radius: 6px; padding: 2px 6px; width: 100%; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; margin: 0; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.label-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.label-picker button { border: 1px dashed var(--line-strong); background: transparent; }
.label-picker .tag { cursor: pointer; border: 1px solid transparent; }
.label-picker .tag { height: 26px; padding: 0 9px; }
.label-picker .tag[aria-pressed="true"] { border-color: color-mix(in srgb, var(--ink) 25%, transparent); color: var(--ink); }
.label-picker .tag[aria-pressed="false"] { background: transparent; border: 1px dashed var(--line-strong); color: var(--ink-3); }
.label-picker .tag[aria-pressed="false"]::before { opacity: .5; }
.window-card { display: grid; gap: 6px; font-size: 13px; }
.window-bar { height: 8px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.window-bar i { display: block; height: 100%; background: var(--pine); }
.window-card.low .window-bar i { background: var(--marigold); }
.window-card small { color: var(--ink-3); }
.reads { display: grid; gap: 6px; font-size: 13px; }
.reads li { display: flex; justify-content: space-between; gap: 10px; }
.reads ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.muted { color: var(--ink-3); }

/* ---------- Pages ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 26px 28px 60px; }
.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.015em; font-weight: 740; margin-right: auto; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); font-size: 13.5px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.card-pad { padding: 18px 20px; }
.card h2 { font-size: 15px; margin: 0 0 4px; font-weight: 700; }
.card .sub { color: var(--ink-3); font-size: 13px; margin: 0 0 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.stack { display: grid; gap: 16px; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 650; color: var(--ink-3); font-size: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; }
.person { display: flex; align-items: center; gap: 10px; }
.person small { display: block; color: var(--ink-3); }
.role { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 650; background: var(--sunken); }
.role.admin { background: var(--plum-soft); color: var(--plum); }
.role.manager { background: var(--sky-soft); color: var(--sky); }
.state-off { color: var(--rose-text); font-weight: 600; }
.state-temp { color: var(--marigold-text); font-weight: 600; }
.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; color: var(--ink-2); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters .input { width: auto; min-height: 34px; padding: 6px 10px; font-size: 13px; }
.filters .search { flex: 1; min-width: 220px; }

/* Insights */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-bottom: 16px; }
.kpi { padding: 18px 20px; border-right: 1px solid var(--line); display: grid; gap: 4px; align-content: start; }
.kpi:last-child { border-right: 0; }
.kpi .label { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: 30px; font-weight: 720; letter-spacing: -.02em; line-height: 1.1; }
.kpi .kpi-note { color: var(--ink-3); font-size: 12.5px; }
.kpi.alert .value { color: var(--marigold-text); }
.kpi.bad .value { color: var(--rose-text); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-pop); padding: 8px 10px; font-size: 12.5px; min-width: 130px; z-index: 5; }
.chart-tip strong { display: block; margin-bottom: 4px; }
.chart-tip div { display: flex; justify-content: space-between; gap: 12px; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
details.table-view { margin-top: 10px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--ink-3); }

/* Settings */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 12px; font-weight: 620; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--pine); }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.checklist li:last-child { border-bottom: 0; }
.checklist .ok { color: #2E8A62; } .checklist .no { color: var(--rose); }
.checklist small { display: block; color: var(--ink-3); }
.copy-field { display: flex; gap: 6px; }
.copy-field input { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.health { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; }
.health-ring { width: 64px; height: 64px; }
.health-ring circle { fill: none; stroke-width: 7; }
.health-ring .track { stroke: var(--sunken); }
.health-ring .val { stroke: var(--pine); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }
.health.warning .val { stroke: var(--marigold); } .health.critical .val { stroke: var(--rose); }
.health-ring text { font-size: 15px; font-weight: 740; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.swatches { display: flex; gap: 8px; }
.swatches label { position: relative; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 28px; height: 28px; border-radius: 7px; border: 2px solid transparent; }
.swatches input:checked + span { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--surface); }
.swatches input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.sw-pine { background: var(--pine); } .sw-marigold { background: var(--marigold); } .sw-rose { background: var(--rose); } .sw-sky { background: var(--sky); } .sw-plum { background: var(--plum); } .sw-slate { background: var(--slate); }

/* ---------- Overlays ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 18, 22, .45); z-index: 60; display: grid; place-items: center; padding: 16px; animation: fade .12s ease-out; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); animation: lift .16s ease-out; }
.modal.wide { width: min(680px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 6px; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 720; margin-right: auto; }
.modal-body { padding: 8px 18px 18px; display: grid; gap: 14px; }
.modal-body > p { margin: 0; color: var(--ink-2); }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.palette { align-self: start; margin-top: 12vh; width: min(600px, 100%); }
.palette input { width: 100%; height: 52px; border: 0; border-bottom: 1px solid var(--line); padding: 0 18px; font-size: 16px; background: transparent; outline: 0; }
.palette-list { max-height: 380px; overflow-y: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; background: transparent; border-radius: 7px; text-align: left; font-size: 13.5px; }
.palette-item.active { background: var(--sunken); }
.palette-item small { margin-left: auto; color: var(--ink-3); }
.palette-group { padding: 8px 12px 4px; font-size: 12px; color: var(--ink-3); font-weight: 650; }
.template-preview { padding: 12px; border-radius: 10px; background: var(--wall); }
.template-preview .bubble { max-width: 100%; background: var(--bubble-out); white-space: pre-wrap; }
.template-list { display: grid; gap: 6px; }
.template-opt { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); text-align: left; }
.template-opt[aria-pressed="true"] { border-color: var(--pine); box-shadow: inset 0 0 0 1px var(--pine); }
.template-opt small { color: var(--ink-3); }
.template-opt:disabled { opacity: .55; }
.lightbox { background: rgba(5, 9, 11, .88); }
.lightbox img { max-width: 92vw; max-height: 86vh; border-radius: 8px; }
.toasts { position: fixed; z-index: 90; left: 50%; bottom: calc(104px + var(--safe-b)); transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 9px; background: var(--ink); color: var(--paper); font-size: 13.5px; box-shadow: var(--shadow-pop); max-width: min(560px, calc(100vw - 32px)); animation: lift .16s ease-out; }
.toast.error { background: var(--rose); color: #fff; }
.toast button { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes lift { from { opacity: 0; transform: translateY(6px); } }
.skeleton { height: 64px; margin: 10px 14px; border-radius: 8px; background: linear-gradient(90deg, var(--sunken), var(--surface-2), var(--sunken)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.noscript { padding: 40px; text-align: center; }

/* ---------- Tablet: details become a drawer ---------- */
@media (max-width: 1280px) {
  .inbox, .inbox.no-details { grid-template-columns: var(--list) minmax(0, 1fr); }
  .inbox .details { display: block; position: absolute; top: 0; right: 0; bottom: 0; width: min(var(--details), 92vw); z-index: 30; box-shadow: var(--shadow-pop); transform: translateX(105%); transition: transform .18s ease; }
  .inbox.show-details .details { transform: none; }
  .inbox.no-details .details { display: block; }
  .details-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 0 18px; font-weight: 700; }
}
@media (max-width: 1060px) { :root { --list: 320px; } .kpis { grid-template-columns: repeat(2, 1fr); } .kpi:nth-child(2) { border-right: 0; } .kpi:nth-child(-n+2) { border-bottom: 1px solid var(--line); } }

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { grid-row: 2; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + var(--safe-b)); border-right: 0; border-top: 1px solid var(--line); gap: 0; }
  .rail .mark, .rail-spacer, .rail .desk-only { display: none; }
  .rail-btn { width: auto; flex: 1; height: 52px; display: flex; flex-direction: column; gap: 2px; align-items: center; justify-content: center; border-radius: 8px; }
  .rail-btn .label { display: block; font-size: 11px; font-weight: 600; }
  .rail-btn .tip { display: none; }
  .rail-btn .dot { top: 2px; right: auto; left: calc(50% + 4px); }
  .views { grid-row: 1; }
  .inbox, .inbox.no-details { grid-template-columns: 1fr; position: relative; }
  .list-pane, .thread { grid-area: 1 / 1; }
  .inbox .thread { transform: translateX(100%); transition: transform .2s ease; z-index: 2; }
  .inbox.thread-open .thread { transform: none; }
  .inbox.thread-open .list-pane { visibility: hidden; transition: visibility 0s .2s; }
  .list-head { padding-top: calc(12px + var(--safe-t)); }
  .search kbd, .compose-hint, .desk-only { display: none !important; }
  body.in-thread .rail { display: none; }
  .composer { padding-bottom: calc(10px + var(--safe-b)) !important; }
  .conv { padding: 12px 14px 12px 16px; }
  .conv-avatar .avatar { width: 46px; height: 46px; }
  .back-btn { display: inline-grid; margin-left: -6px; }
  .thread-head { padding: calc(6px + var(--safe-t)) 8px 6px; gap: 6px; }
  .icon-btn { width: 40px; height: 40px; }
  .bubble { max-width: 86%; }
  .messages { padding: 12px 10px; }
  .compose-box textarea { font-size: 16px; } /* prevents iOS zoom */
  .send-btn { width: 40px; height: 40px; }
  .inbox .details { width: 100%; }
  .page { padding: calc(18px + var(--safe-t)) 16px 40px; }
  .page-head h1 { font-size: 21px; }
  .kpi { padding: 14px; } .kpi .value { font-size: 24px; }
  .filters .input, .filters .search { flex: 1 1 100%; }
  table.data.responsive thead { display: none; }
  table.data.responsive tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.data.responsive td { padding: 0; border: 0; }
  table.data.responsive td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-3); }
  table.data.responsive td.wide { grid-column: 1 / -1; }
  .modal { align-self: end; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 90vh; padding-bottom: var(--safe-b); }
  .scrim { padding: 0; }
  .palette { align-self: start; margin-top: var(--safe-t); border-radius: 0 0 var(--r-lg) var(--r-lg); }
  .field input, .field select, .field textarea, .input { font-size: 16px; }
  .has-banner .banner { padding-top: calc(8px + var(--safe-t)); }
}

/* v9.1 security & time */
.qr-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.qr-wrap svg { border-radius: 8px; border: 1px solid var(--line); flex: none; }
.steps-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); }
.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 18px; padding: 14px; border-radius: 8px; background: var(--sunken); }
.recovery-grid .code { font-size: 15px; color: var(--ink); }
.toggle-row { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; cursor: pointer; }
.toggle-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--pine); }
.toggle-row small { display: block; color: var(--ink-3); font-size: 12.5px; margin-top: 2px; }
#twostep-form .link-btn { color: var(--pine-text); }

/* Contact colours (stable per number) */
.avatar.tone-0 { background: var(--pine-soft); color: var(--pine-text); }
.avatar.tone-1 { background: var(--sky-soft); color: var(--sky); }
.avatar.tone-2 { background: var(--plum-soft); color: var(--plum); }
.avatar.tone-3 { background: var(--marigold-soft); color: var(--marigold-text); }
.avatar.tone-4 { background: var(--rose-soft); color: var(--rose-text); }
.avatar.tone-5 { background: var(--slate-soft); color: var(--slate); }
.import-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--line); border-radius: 10px; }
.import-stats div { padding: 12px 14px; border-right: 1px solid var(--line); display: grid; gap: 2px; }
.import-stats div:last-child { border-right: 0; }
.import-stats strong { font-size: 20px; font-weight: 720; }
.import-stats span { font-size: 12.5px; color: var(--ink-3); }
