/* ==========================================================================
   Send My Demand — client portal + admin portal
   Builds on base.css (the public site's tokens, type, buttons, forms).
   App shell: sidebar ≥ 960px, top bar + bottom tab bar below.
   ========================================================================== */
:root { --side-w: 256px; --top-h: 60px; --tab-h: 64px; }
body.app { padding-bottom: 0; background: var(--surface); }
@media (max-width: 959px) { body.app { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); } }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
@media (min-width: 960px) { .shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); } }

.side { display: none; }
@media (min-width: 960px) {
  .side {
    display: flex; flex-direction: column; gap: 6px;
    position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
    padding: 22px 14px 18px; border-right: 1px solid var(--line); background: var(--surface-raised);
  }
}
.side__brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; text-decoration: none; color: var(--ink); }
.side__brand img { height: 34px; width: auto; }
.side__tag { margin-left: auto; padding: 3px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .75rem; font-weight: 650; }
.side__cta { margin: 4px 4px 14px; }
.side nav { display: grid; gap: 2px; }
.side__label { margin: 18px 12px 6px; color: var(--ink-3); font-size: .8125rem; font-weight: 600; }
.nav-link {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px;
  border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 550; font-size: .9688rem;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link:hover { background: var(--surface-sunken); color: var(--ink); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-link .count { margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--warning-bg); color: var(--warning); font-size: .75rem; font-weight: 700; text-align: center; }
.side__foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.who__name { font-weight: 600; font-size: .9375rem; line-height: 1.25; overflow-wrap: anywhere; }
.who__mail { color: var(--ink-3); font-size: .8125rem; overflow-wrap: anywhere; }
.avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .875rem; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Mobile top bar */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px;
  height: var(--top-h); padding: 0 16px; background: var(--glass); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(1.6) blur(18px); backdrop-filter: saturate(1.6) blur(18px);
}
.topbar img { height: 30px; width: auto; }
.topbar__right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
@media (min-width: 960px) { .topbar { display: none; } }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--surface-sunken); color: var(--ink); }

/* Bottom tab bar (mobile) */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 50; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--glass); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(1.6) blur(18px); backdrop-filter: saturate(1.6) blur(18px);
}
@media (min-width: 960px) { .tabbar { display: none; } }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; color: var(--ink-3); text-decoration: none; font-size: .6875rem; font-weight: 600; letter-spacing: .005em; }
.tab .icon { width: 23px; height: 23px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab--new .tab__bubble { width: 44px; height: 32px; border-radius: 999px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.tab--new .tab__bubble .icon { width: 20px; height: 20px; stroke-width: 2.2; }
.tab--new { color: var(--ink-2); }

/* Main column */
.main { min-width: 0; padding: clamp(18px, 1rem + 1.6vw, 40px) clamp(16px, 1rem + 2vw, 48px) 56px; }
.main__inner { max-width: 1120px; margin-inline: auto; }
.app-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 20px; margin-bottom: clamp(18px, 1rem + 1vw, 28px); }
.app-head h1 { font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.2rem); line-height: 1.12; font-weight: 700; letter-spacing: -0.025em; }
.app-head p { margin: 6px 0 0; color: var(--ink-2); }
.crumb { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 10px; color: var(--ink-2); font-size: .9375rem; font-weight: 550; text-decoration: none; }
.crumb:hover { color: var(--ink); }

/* ---------- Surfaces ---------- */
.panel { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--shadow-1); }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.panel__head h2 { font-size: 1.0625rem; font-weight: 650; letter-spacing: -0.01em; font-family: var(--font-sans); }
.panel__body { padding: 16px 20px 20px; }
.panel + .panel, .panel + .grid, .grid + .panel, .stack-l > * + * { margin-top: 20px; }
.cols { display: grid; gap: 20px; }
@media (min-width: 1040px) { .cols { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start; } }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { padding: 16px 18px; border-radius: var(--radius); background: var(--surface-raised); border: 1px solid var(--line); text-decoration: none; color: var(--ink); display: block; }
a.kpi:hover { border-color: var(--line-strong); text-decoration: none; }
.kpi__label { color: var(--ink-2); font-size: .875rem; font-weight: 550; }
.kpi__value { margin-top: 4px; font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi__note { color: var(--ink-3); font-size: .8125rem; }
.kpi--alert { border-color: color-mix(in srgb, var(--warning) 40%, var(--line)); background: color-mix(in srgb, var(--warning-bg) 55%, var(--surface-raised)); }

/* Status pills (always text + colour) */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 650; white-space: nowrap; background: var(--surface-sunken); color: var(--ink-2); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill--success { background: var(--success-bg); color: var(--success); }
.pill--warning { background: var(--warning-bg); color: var(--warning); }
.pill--danger { background: var(--danger-bg); color: var(--danger); }
.pill--info { background: var(--info-bg); color: var(--info); }

/* Lists → cards on phones, table on desktop */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; gap: 4px 16px; padding: 14px 20px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.rows > li:first-child .row, .rows > .row:first-child { border-top: 0; }
a.row:hover { background: var(--surface-sunken); text-decoration: none; }
.row__main { min-width: 0; }
.row__title { font-weight: 600; overflow-wrap: anywhere; }
.row__meta { color: var(--ink-3); font-size: .875rem; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.row__side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (min-width: 720px) { .row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; } .row__side { justify-content: flex-end; } }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9375rem; }
table.data th { text-align: left; font-size: .8125rem; font-weight: 650; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-sunken); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data a { font-weight: 600; text-decoration: none; }
table.data a:hover { text-decoration: underline; }
@media (max-width: 759px) {
  table.data--stack thead { display: none; }
  table.data--stack, table.data--stack tbody, table.data--stack tr, table.data--stack td { display: block; width: 100%; }
  table.data--stack tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  table.data--stack td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 16px; text-align: right; }
  table.data--stack td::before { content: attr(data-label); color: var(--ink-3); font-size: .8125rem; font-weight: 600; text-align: left; flex: none; }
  table.data--stack td.num { white-space: normal; }
}

dl.kv { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px 18px; margin: 0; }
dl.kv dt { color: var(--ink-3); font-size: .8125rem; font-weight: 600; margin-top: 10px; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (min-width: 560px) { dl.kv { grid-template-columns: 170px minmax(0, 1fr); } dl.kv dt { margin-top: 0; padding: 9px 0; border-top: 1px solid var(--line); } dl.kv dd { padding: 8px 0; border-top: 1px solid var(--line); } dl.kv dt:first-of-type, dl.kv dt:first-of-type + dd { border-top: 0; } }

/* Filters / segmented links */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-sunken); border: 1px solid var(--line); }
.seg a { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 999px; color: var(--ink-2); font-size: .875rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.seg a:hover { color: var(--ink); }
.seg a[aria-current="true"] { background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow-1); }
.seg .count { color: var(--ink-3); font-weight: 600; }
.search { position: relative; flex: 1 1 240px; max-width: 420px; }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search .input { min-height: 44px; padding-left: 42px; border-radius: 999px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: .875rem; }

/* Notices / flash */
.flash { margin-bottom: 18px; }
.notice .icon { flex: none; }
.notice strong { display: block; }
.notice--inline { padding: 12px 14px; }

/* Empty state */
.empty-mini { text-align: center; padding: 36px 20px; color: var(--ink-2); }
.empty-mini .icon { width: 28px; height: 28px; margin: 0 auto 10px; color: var(--ink-3); }
.empty-mini p { margin: 0 auto 14px; max-width: 42ch; }

/* ---------- Case timeline ---------- */
.steps-v { list-style: none; margin: 0; padding: 0; }
.steps-v li { position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; padding-bottom: 18px; }
.steps-v li:last-child { padding-bottom: 0; }
.steps-v li::before { content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--line); }
.steps-v li:last-child::before { display: none; }
.steps-v .dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line-strong); background: var(--surface-raised); color: var(--ink-3); }
.steps-v .dot .icon { width: 15px; height: 15px; stroke-width: 2.4; }
.steps-v .is-done .dot { border-color: var(--success); background: var(--success); color: #fff; }
.steps-v .is-now .dot { border-color: var(--accent); color: var(--accent); }
.steps-v .is-done::before { background: var(--success); }
.steps-v h3 { font-family: var(--font-sans); font-size: .9688rem; font-weight: 650; margin: 3px 0 2px; }
.steps-v p { margin: 0; color: var(--ink-3); font-size: .875rem; }

.track { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; padding: 16px 18px; border-radius: var(--radius); background: var(--info-bg); border: 1px solid color-mix(in srgb, var(--info) 22%, transparent); }
.track__num { font-family: var(--font-mono); font-size: 1rem; font-weight: 600; letter-spacing: .02em; overflow-wrap: anywhere; }

/* ---------- New letter wizard ---------- */
.wizard { max-width: 760px; }
.progress { display: grid; gap: 8px; margin-bottom: 22px; }
.progress__bar { height: 6px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }
.progress__bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 400ms var(--ease-out); }
.progress__text { display: flex; justify-content: space-between; color: var(--ink-3); font-size: .875rem; font-weight: 600; }
.choice-grid { display: grid; gap: 10px; }
@media (min-width: 640px) { .choice-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.choice { position: relative; display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: var(--radius); border: 1.5px solid var(--line-strong); background: var(--surface-raised); cursor: pointer; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.choice:hover { border-color: var(--ink-3); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice__icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.choice__title { font-weight: 650; }
.choice__desc { color: var(--ink-2); font-size: .9063rem; }
.choice__price { margin-left: auto; font-family: var(--font-display); font-weight: 700; font-size: 1.125rem; white-space: nowrap; }
.choice__tick { position: absolute; top: 12px; right: 12px; width: 22px; height: 22px; border-radius: 50%; display: none; place-items: center; background: var(--accent); color: var(--on-accent); }
.choice:has(input:checked) .choice__tick { display: grid; }
.choice:has(input:checked) .choice__price { margin-right: 26px; }
.wizard-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; margin-top: 24px; }
.wizard-actions .btn--primary { margin-left: auto; }
@media (max-width: 559px) {
  .wizard-actions { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); margin-inline: -16px; padding: 12px 16px; background: var(--glass); border-top: 1px solid var(--line); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  .wizard-actions .btn { flex: 1; }
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-weight: 600; font-size: .9375rem; margin-bottom: 8px; }

/* Upload + signature */
.drop { display: grid; place-items: center; gap: 8px; padding: 28px 18px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); text-align: center; color: var(--ink-2); cursor: pointer; transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease); }
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop .icon { width: 28px; height: 28px; color: var(--accent); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 12px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-sunken); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.sigpad { position: relative; border: 1.5px solid var(--line-strong); border-radius: var(--radius); background: #fff; touch-action: none; }
.sigpad canvas { display: block; width: 100%; height: 190px; border-radius: inherit; cursor: crosshair; }
.sigpad__line { position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1px solid #c5cfdc; pointer-events: none; }
.sigpad__hint { position: absolute; left: 24px; bottom: 16px; color: #56657a; font-size: .8125rem; pointer-events: none; }
.sig-img { max-height: 90px; width: auto; background: #fff; border-radius: 8px; padding: 6px; border: 1px solid var(--line); }

/* Letter preview (paper) */
.paper { background: #fff; color: #111; border-radius: 6px; box-shadow: var(--shadow-3); padding: clamp(22px, 5vw, 64px); font-family: var(--font-letter); font-size: clamp(14px, .8rem + .3vw, 16px); line-height: 1.6; max-width: 760px; }
.paper p { margin: 0 0 1em; white-space: pre-wrap; }
.paper .sig-img { border: 0; padding: 0; max-height: 70px; }
.paper-frame { background: var(--surface-sunken); border-radius: var(--radius-l); padding: clamp(10px, 3vw, 32px); }

/* Checkout */
.order { display: grid; gap: 10px; }
.order__row { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-2); }
.order__row strong { color: var(--ink); }
.order__total { padding-top: 12px; border-top: 1px solid var(--line); font-size: 1.125rem; color: var(--ink); font-weight: 700; }
#card-element { padding: 14px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface-raised); min-height: 50px; }
.secure-note { display: flex; gap: 8px; align-items: center; color: var(--ink-3); font-size: .8125rem; }

/* Dialog */
dialog.dlg { border: 0; padding: 0; border-radius: var(--radius-l); background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow-3); width: min(520px, calc(100vw - 32px)); }
dialog.dlg::backdrop { background: rgba(8, 19, 31, .5); }
.dlg__body { padding: 24px; }
.dlg__body h2 { font-size: 1.25rem; margin-bottom: 8px; font-family: var(--font-sans); font-weight: 700; }
.dlg__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 0 24px 22px; }

/* Auth pages */
.auth-page { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
.auth-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px var(--gutter); }
.auth-top img { height: 34px; width: auto; }
.auth-foot { padding: 20px var(--gutter) 28px; text-align: center; color: var(--ink-3); font-size: .8125rem; }
.btn-google { --btn-bg: var(--surface-raised); --btn-bd: var(--line-strong); }
.code-input { font-family: var(--font-mono); font-size: 1.5rem; letter-spacing: .4em; text-align: center; }

/* Admin specifics */
.admin-tag { display: inline-flex; padding: 2px 8px; border-radius: 999px; background: var(--navy-800); color: #fff; font-size: .75rem; font-weight: 650; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form .field { flex: 1 1 220px; }
.note { padding: 12px 14px; border-radius: 12px; background: var(--surface-sunken); }
.note__meta { color: var(--ink-3); font-size: .8125rem; margin-top: 4px; }
.answer { white-space: pre-wrap; overflow-wrap: anywhere; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery a { display: block; aspect-ratio: 1; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-sunken); }
.gallery img { width: 100%; height: 100%; object-fit: cover; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.stage-ribbon { position: sticky; top: 0; z-index: 70; padding: 6px 16px; text-align: center; font-size: .8125rem; font-weight: 650; background: repeating-linear-gradient(-45deg, #fbf0d9, #fbf0d9 12px, #f7e7c3 12px, #f7e7c3 24px); color: #5c3e00; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stage-ribbon { background: repeating-linear-gradient(-45deg, #2c220d, #2c220d 12px, #33280f 12px, #33280f 24px); color: #f0c36b; }
}
:root[data-theme="dark"] .stage-ribbon { background: repeating-linear-gradient(-45deg, #2c220d, #2c220d 12px, #33280f 12px, #33280f 24px); color: #f0c36b; }
.stage-ribbon a { color: inherit; text-decoration: underline; }

.hide-sm { display: none; }
@media (min-width: 720px) { .hide-sm { display: initial; } .show-sm { display: none; } }
.w-full { width: 100%; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.gap-8 { gap: 8px; }

@media print {
  .side, .topbar, .tabbar, .no-print, .stage-ribbon { display: none !important; }
  body.app { background: #fff; padding: 0; }
  .main { padding: 0; }
  .paper { box-shadow: none; padding: 0; }
  .paper-frame { background: none; padding: 0; }
}
.mx-auto { margin-inline: auto; } .justify-center { justify-content: center; }

/* Progress widths (no inline styles: CSP) */
.progress__bar span.w-20 { width: 20%; } .progress__bar span.w-40 { width: 40%; } .progress__bar span.w-60 { width: 60%; } .progress__bar span.w-80 { width: 80%; } .progress__bar span.w-100 { width: 100%; }
.panel__legend { float: left; width: 100%; padding: 18px 20px 0; font-family: var(--font-sans); font-size: 1.0625rem; font-weight: 650; letter-spacing: -0.01em; }
.panel__legend + * { clear: both; }
fieldset.panel { margin: 0 0 20px; }

/* AI chat */
.chat { display: flex; flex-direction: column; min-height: 420px; }
.chat__log { list-style: none; margin: 0; padding: 20px; display: grid; gap: 14px; align-content: start; flex: 1; }
.bubble { max-width: min(680px, 92%); padding: 12px 16px; border-radius: 18px; line-height: 1.55; }
.bubble__text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble--me { justify-self: end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.bubble--ai { justify-self: start; background: var(--surface-sunken); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble--letter { background: var(--surface-raised); border: 1.5px solid color-mix(in srgb, var(--success) 45%, var(--line)); max-width: 100%; }
.bubble--letter .bubble__text { font-family: var(--font-letter); font-size: .9688rem; }
.bubble__tag { display: inline-flex; gap: 6px; align-items: center; margin-bottom: 8px; padding: 3px 10px; border-radius: 999px; background: var(--success-bg); color: var(--success); font-size: .8125rem; font-weight: 650; }
.chat__thinking { display: flex; gap: 8px; align-items: center; margin: 0 20px 14px; color: var(--ink-3); font-size: .9375rem; }
.chat__thinking .icon { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) { .chat__thinking .icon { animation: pulse 1.2s ease-in-out infinite; } }
@keyframes pulse { 50% { opacity: .35; } }
.chat__start { padding: 32px 20px; text-align: center; border-top: 1px solid var(--line); }
.chat__form { display: flex; gap: 10px; align-items: flex-end; padding: 14px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface-raised); border-radius: 0 0 var(--radius-l) var(--radius-l); }
@media (max-width: 959px) { .chat__form { bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); } }
.chat__form .textarea { min-height: 50px; max-height: 40vh; resize: none; }
.chat__form .btn { flex: none; }
[hidden] { display: none !important; }

.paper-edit { min-height: 520px; font-family: var(--font-letter); font-size: 1rem; line-height: 1.6; background: #fff; color: #111; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .paper-edit { background: #fbfbf8; color: #111; }
}
:root[data-theme="dark"] .paper-edit { background: #fbfbf8; color: #111; }
.agreement { max-height: 62vh; overflow-y: auto; font-size: .9375rem; color: var(--ink-2); }
.agreement h3 { font-size: 1.0625rem; text-align: center; margin: 0 0 14px; font-family: var(--font-sans); color: var(--ink); }
.agreement h4 { font-size: .9688rem; margin: 18px 0 6px; font-family: var(--font-sans); color: var(--ink); }
.agreement strong { color: var(--ink); }
.agreement ul { padding-left: 1.25em; margin: 0 0 1em; }
.agreement li { margin: 0 0 .35em; }
.agreement__sub { text-align: center; margin-top: -8px; }
.agreement__fill { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; padding: 8px 12px; border-radius: 10px; background: var(--surface-sunken); }
.agreement__fill span { color: var(--ink-3); }
.agreement__parties { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); font-size: .875rem; }
.agreement__parties strong { display: block; font-size: .75rem; letter-spacing: .02em; margin-bottom: 4px; }
.agreement__parties span { color: var(--ink-2); }
.countersign { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-sunken); }
[data-sig-error] { display: none; }
.has-sig-error [data-sig-error] { display: flex; }
.has-sig-error .sigpad { border-color: var(--danger); }

/* Select arrow (appearance is reset in base.css) */
select.select { padding-right: 42px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2356657a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; background-size: 16px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) select.select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23b4bfcd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); }
}
:root[data-theme="dark"] select.select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23b4bfcd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); }

/* Local test copy only: /__dev/emails */
.dev-mail { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.5; background: var(--surface-sunken, #f3f1ec); padding: 12px 14px; border-radius: 10px; }

/* ==========================================================================
   Shared additions (both portals): logo per theme, messages, timeline
   ========================================================================== */
.mt-20 { margin-top: 20px; }
.logo { display: inline-flex; align-items: center; }
.logo .logo__d { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo .logo__l { display: none; }
  :root:not([data-theme="light"]) .logo .logo__d { display: inline; }
}
:root[data-theme="dark"] .logo .logo__l { display: none; }
:root[data-theme="dark"] .logo .logo__d { display: inline; }

.count--accent { background: var(--accent-soft) !important; color: var(--accent) !important; }
.icon-btn--badge { position: relative; }
.badge-dot { position: absolute; top: 10px; right: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--surface); }
.empty-inline { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius); background: var(--surface-sunken); color: var(--ink-2); }
.empty-inline .icon { flex: none; color: var(--ink-3); margin-top: 2px; }
.empty-inline p { margin: 0; }
.row.is-unread .row__title { color: var(--ink); }
.row.is-unread { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .9375rem; list-style: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸"; font-size: .8em; transition: transform var(--dur) var(--ease); }
details.more[open] > summary::before { transform: rotate(90deg); }
.ok { color: var(--success); }
.err { color: var(--danger); }

/* Conversation */
.thread { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.msg { display: grid; gap: 4px; max-width: min(640px, 92%); }
.msg--out { justify-self: end; justify-items: end; text-align: left; }
.msg--in { justify-self: start; }
.msg__head { font-size: .8125rem; color: var(--ink-2); }
.msg__bubble { padding: 12px 16px; border-radius: 18px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg--out .msg__bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.msg--in .msg__bubble { background: var(--surface-sunken); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg__meta { font-size: .8125rem; color: var(--ink-3); }
.msg__meta a { color: inherit; }
.composer { display: grid; gap: 10px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.composer > label { font-weight: 600; font-size: .9375rem; }
.composer__to { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .9063rem; color: var(--ink-2); }
.composer__foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }

/* Timeline (status history, payment timeline, audit trail) */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item { position: relative; display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 12px; padding-bottom: 16px; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__item::before { content: ""; position: absolute; left: 10px; top: 20px; bottom: 0; width: 2px; background: var(--line); }
.timeline__item:last-child::before { display: none; }
.timeline__dot { width: 22px; height: 22px; border-radius: 50%; margin-top: 1px; border: 2px solid var(--line-strong); background: var(--surface-raised); display: grid; place-items: center; color: var(--ink-3); }
.timeline__dot--icon { border-width: 1.5px; }
.timeline__dot .icon { width: 12px; height: 12px; stroke-width: 2.2; }
.timeline__item--stage .timeline__dot { border-color: var(--accent); }
.timeline__item--payment .timeline__dot, .timeline__item--succeeded .timeline__dot, .timeline__item--case_linked .timeline__dot { border-color: var(--success); color: var(--success); }
.timeline__item--failed .timeline__dot, .timeline__item--dispute .timeline__dot { border-color: var(--danger); color: var(--danger); }
.timeline__item--refunded .timeline__dot { border-color: var(--warning); color: var(--warning); }
.timeline__title { font-weight: 600; font-size: .9375rem; overflow-wrap: anywhere; }
.timeline__meta { color: var(--ink-3); font-size: .8125rem; overflow-wrap: anywhere; }
.timeline__note { margin-top: 4px; padding: 6px 10px; border-radius: 8px; background: var(--surface-sunken); font-size: .875rem; color: var(--ink-2); }

button.nav-link { border: 0; background: transparent; font: inherit; cursor: pointer; text-align: left; }

/* ---------- Notifications (customer) ---------- */
.badge-count { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .6875rem; font-weight: 700; line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--surface); }
.notif-list .row { position: relative; padding-left: 34px; }
.notif-dot { position: absolute; left: 14px; top: 22px; width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.notif-dot.is-on { background: var(--accent); }
.notif-list .is-unread .row__title { font-weight: 700; }
.notif-body span { white-space: normal; }
.panel--action { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent); }
.request-text { padding: 12px 14px; border-left: 3px solid var(--accent); border-radius: 0 var(--radius-s) var(--radius-s) 0; background: var(--surface-sunken); }
.form-card--wide { max-width: 760px; }
.panel--action .panel__head h2 { display: inline-flex; gap: 8px; align-items: center; }
.panel--action .panel__head h2 .icon { width: 18px; height: 18px; color: var(--accent); flex: none; }
.notif-list .row__side { align-self: center; }
@media (max-width: 640px) { .notif-list .row__side { display: none; } }
