/* BDW Matter Tracker. Brand ink taken from the BDW logo (#22240C). */
:root {
  --ink: #22240c;
  --ink-2: #3b3e22;
  --paper: #f6f5ef;
  --surface: #ffffff;
  --line: #e1dfd4;
  --line-2: #cfccbe;
  --text: #22240c;
  --muted: #6b6a5c;
  --accent: #55622a;
  --accent-soft: #eef0e2;
  --danger: #a33a2b;
  --danger-soft: #f8e9e6;
  --warn: #a86b12;
  --warn-soft: #fbf1e0;
  --ok: #3f6b35;
  --ok-soft: #e7f0e2;
  --info: #3d5a80;
  --info-soft: #e8eef6;

  /* Stage text (ink) and soft backgrounds; >= 4.5:1 contrast. */
  --stage-intake: #2f5597;
  --stage-intake-soft: #e9eff9;
  --stage-open: #0a6b62;
  --stage-open-soft: #e2f3f1;
  --stage-on_hold: #9c4a10;
  --stage-on_hold-soft: #fcefe4;
  --stage-closed: #6b6a5c;
  --stage-closed-soft: #efeee9;

  /* Chart marks. Stage hues validated as a categorical set (colour-blind safe, >= 3:1 on white). */
  --viz-intake: #3a66b5;
  --viz-open: #0f9488;
  --viz-on_hold: #e0782c;
  --viz-closed: #a3a196;
  --viz-single: #55622a;
  --viz-track: #d9dfc2;
  --viz-nonbill: #b9b6a3;
  --viz-grid: #e7e5dc;
  --viz-axis: #c3c2b7;
  --viz-tick: #898781;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(34, 36, 12, .08), 0 1px 1px rgba(34, 36, 12, .04);
  --shadow-lift: 0 8px 24px rgba(34, 36, 12, .16);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 14px/1.45 var(--font);
}
a { color: var(--accent); }
a:hover { color: var(--ink); }
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 12px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 18px 0 8px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 12px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 20px;
  height: 56px; padding: 0 20px;
  background: var(--ink); color: #f6f5ef;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.brand img { height: 34px; width: auto; display: block; }
.brand-name { font-weight: 600; letter-spacing: .02em; font-size: 15px; padding-left: 12px; border-left: 1px solid rgba(246,245,239,.25); }
.mainnav { display: flex; align-items: center; gap: 4px; flex: 1; }
.mainnav > a, .mainnav summary {
  color: #e9e8df; text-decoration: none; padding: 7px 12px; border-radius: 6px; cursor: pointer; font-weight: 500;
}
.mainnav > a:hover, .mainnav summary:hover { background: rgba(246,245,239,.1); color: #fff; }
.mainnav > a.active, .mainnav summary.active { background: rgba(246,245,239,.16); color: #fff; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; font-size: 10px; margin-left: 6px; opacity: .7; }
.menu-panel {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lift); padding: 6px; display: flex; flex-direction: column;
}
.menu-panel.right { left: auto; right: 0; }
.menu-panel a, .menu-panel .linklike {
  display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; text-align: left;
  font: inherit; background: none; border: 0; width: 100%; cursor: pointer;
}
.menu-panel a:hover, .menu-panel .linklike:hover { background: var(--accent-soft); }
.usermenu summary { display: flex; align-items: center; gap: 10px; color: #f6f5ef; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.usermenu summary:hover { background: rgba(246,245,239,.1); }
.who { display: flex; flex-direction: column; line-height: 1.15; font-weight: 500; }
.who small { color: #c9c8bb; font-weight: 400; font-size: 11.5px; }

/* ---- avatars & chips ---- */
.avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: #e8e6da; color: var(--ink); font-size: 11.5px; font-weight: 600; letter-spacing: .02em; flex: none;
}
.topbar .avatar { background: #f6f5ef; }
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.partner { background: var(--ink); color: #f6f5ef; }
.avatar.lead { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--viz-open); }
.chip {
  display: inline-block; font-size: 11px; line-height: 1.3; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip-unbillable { background: var(--info-soft); color: var(--info); }
.chip-lead { background: #f3e8f7; color: #6d3a84; }
.chip-nocode { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.flag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--stage-closed-soft); color: var(--muted); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.lock {
  display: inline-block; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 1px 6px; border-radius: 4px; background: var(--stage-closed-soft); color: var(--muted); vertical-align: 1px;
}
.lock::before { content: "🔒"; margin-right: 3px; font-size: 9px; }
.status-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-pill.stage-intake { background: var(--stage-intake-soft); color: var(--stage-intake); }
.status-pill.stage-open { background: var(--stage-open-soft); color: var(--stage-open); }
.status-pill.stage-on_hold { background: var(--stage-on_hold-soft); color: var(--stage-on_hold); }
.status-pill.stage-closed { background: var(--stage-closed-soft); color: var(--stage-closed); }

/* ---- layout ---- */
.page { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }
.page-wide { padding: 16px 20px 40px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.panel.medium { max-width: 760px; }
.panel.center { text-align: center; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.row-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; align-items: start; }
.row-3.tight { gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(to top, var(--surface) 70%, rgba(255,255,255,0)); padding: 12px 0 4px; }
.inline, .inline-form { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---- forms ---- */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 6px; padding: 7px 9px; min-height: 34px; width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--ink); }
input[type=file] { border-style: dashed; padding: 10px; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, summary:focus-visible, .col-head:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.pin-input { font-size: 22px; letter-spacing: .5em; text-align: center; font-family: var(--mono); max-width: 180px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap;
  padding: 7px 14px; min-height: 34px; border-radius: 6px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--accent-soft); color: var(--ink); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #f6f5ef; }
.btn-primary:hover { background: var(--ink-2); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); border-color: #e3b9b2; }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-small { padding: 4px 10px; min-height: 28px; font-size: 12.5px; }
.btn-confirm { border-color: var(--ok); color: var(--ok); background: var(--surface); }
.btn-confirm:hover { background: var(--ok-soft); color: var(--ok); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #8a2f22; color: #fff; }

/* ---- flashes & toast ---- */
.flashes { position: fixed; top: 64px; right: 20px; z-index: 40; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.flash { padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow-lift); background: var(--surface); border-left: 4px solid var(--accent); }
.flash-error { border-left-color: var(--danger); }
.flash-success { border-left-color: var(--ok); }
.flash-info { border-left-color: var(--info); }
.auth-body .flashes { top: 20px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #f6f5ef; padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow-lift);
}
.toast.error { background: var(--danger); }

/* ---- auth ---- */
.auth-body { background: var(--paper); }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 32px; box-shadow: var(--shadow-lift); }
.auth-card .pin-input { max-width: none; }
.auth-logo { display: block; height: 64px; width: auto; margin: 0 0 18px; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card > p.muted { margin: 0 0 20px; }
.auth-foot { margin: 18px 0 0; font-size: 13px; color: var(--muted); }

/* ---- toolbar / filters ---- */
.toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 12px; padding-top: 4px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input[type=search] { width: 220px; }
.filters select { width: auto; max-width: 170px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg label { flex-direction: row; padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg label.on { background: var(--ink); color: #f6f5ef; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Filters button + panel */
.filter-menu { position: relative; }
.filter-menu > summary { list-style: none; }
.filter-menu > summary::-webkit-details-marker { display: none; }
.filter-toggle { gap: 6px; min-height: 34px; padding: 6px 12px; }
.filter-toggle .icon { display: block; }
.filter-toggle.has-active { border-color: var(--ink); }
.filter-menu[open] > .filter-toggle { background: var(--ink); color: #f6f5ef; border-color: var(--ink); }
.count-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--ink); color: #f6f5ef; font-size: 11px; font-weight: 700; }
.filter-menu[open] .count-badge { background: #f6f5ef; color: var(--ink); }
.filter-panel { position: absolute; top: calc(100% + 6px); left: 0; z-index: 35; width: min(560px, calc(100vw - 40px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lift);
  padding: 14px 16px; }
.filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.filter-grid select, .filter-grid input:not([type=checkbox]) { width: 100%; max-width: none; }
.filter-checks { grid-column: 1 / -1; display: flex; gap: 8px 22px; flex-wrap: wrap; }
.filter-checks .check { white-space: nowrap; }
.filter-actions { display: flex; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.chips-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -6px 0 12px; }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink-2); font-size: 12.5px; text-decoration: none; border: 1px solid #d9dec4; }
.filter-chip:hover { background: #e3e7cf; color: var(--ink); }
.chip-x { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; font-size: 13px; line-height: 1;
  color: var(--muted); }
.filter-chip:hover .chip-x { background: rgba(34, 36, 12, .1); color: var(--ink); }
.chips-clear { font-size: 12.5px; margin-left: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.empty-hint { background: var(--surface); border: 1px dashed var(--line-2); padding: 12px 16px; border-radius: var(--radius); }
.legend { font-size: 12px; margin-top: 10px; }

/* ---- board ---- */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; min-height: calc(100vh - 190px); }
.stage { flex: none; display: flex; flex-direction: column; gap: 8px; }
.stage-head {
  display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; padding: 6px 10px; border-radius: 6px;
}
.stage-intake .stage-head { background: var(--stage-intake-soft); color: var(--stage-intake); }
.stage-open .stage-head { background: var(--stage-open-soft); color: var(--stage-open); }
.stage-on_hold .stage-head { background: var(--stage-on_hold-soft); color: var(--stage-on_hold); }
.stage-closed .stage-head { background: var(--stage-closed-soft); color: var(--stage-closed); }
.stage-cols { display: flex; gap: 10px; align-items: flex-start; }
.col {
  width: 268px; flex: none; background: #ecebe3; border-radius: var(--radius); display: flex; flex-direction: column;
  max-height: calc(100vh - 200px); border-top: 3px solid transparent;
}
.stage-intake .col { border-top-color: var(--viz-intake); }
.stage-open .col { border-top-color: var(--viz-open); }
.stage-on_hold .col { border-top-color: var(--viz-on_hold); }
.stage-closed .col { border-top-color: var(--viz-closed); }
.col-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; font: inherit; font-weight: 600; font-size: 13px; color: var(--ink);
  padding: 10px 12px 8px; cursor: pointer; text-align: left;
}
.count { font-size: 11.5px; font-weight: 700; background: rgba(34,36,12,.08); color: var(--ink-2); padding: 1px 8px; border-radius: 999px; }
.col-body { padding: 4px 8px 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 60px; flex: 1; }
.col.collapsed { width: 44px; }
.col.collapsed .col-body { display: none; }
.col.collapsed .col-head { flex-direction: column; justify-content: flex-start; gap: 10px; height: 100%; min-height: 220px; padding: 10px 0; align-items: center; }
.col.collapsed .col-title { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
.col.drop-target { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -2px; }
.col.drop-target.collapsed .col-head { background: var(--accent-soft); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  border-left: 3px solid transparent; transition: box-shadow .12s, transform .12s;
}
.card:hover { box-shadow: var(--shadow-lift); }
.card.movable { cursor: grab; }
.card:not(.movable) { cursor: pointer; }
.card.just-moved { animation: just-moved 1.6s ease-out; }
@keyframes just-moved { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow); } }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0 11px 9px; }
.card-actions .btn-small { min-height: 24px; padding: 2px 10px; font-size: 12px; }
.card.dragging { opacity: .45; transform: rotate(1deg); }
.card.saving { opacity: .6; pointer-events: none; }
.card.due-soon { border-left-color: var(--warn); }
.card.due-overdue { border-left-color: var(--danger); }
.card-link { display: flex; flex-direction: column; gap: 5px; padding: 10px 11px; color: inherit; text-decoration: none; }
.card-link:hover { color: inherit; }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.code { font-family: var(--mono); font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client { font-weight: 600; font-size: 13px; line-height: 1.3; }
.title { font-size: 12.5px; color: var(--ink-2); line-height: 1.35; }
.fee-line { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.fee-line.empty { font-weight: 400; color: var(--muted); }
.note-snippet { margin: 2px 0 0; font-size: 12px; color: var(--muted); border-left: 2px solid var(--line); padding-left: 7px; overflow-wrap: anywhere; }
.card-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.people { display: inline-flex; gap: 2px; margin-right: auto; }
.due { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.due-soon .due { color: var(--warn); }
.due-overdue .due { color: var(--danger); }

/* ---- matter page ---- */
.matter-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.matter-head h1 { margin-bottom: 4px; }
.matter-head p { margin: 0; }
.matter-status { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.matter-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.fields .field-matter_context, .fields .field-comments, .fields .field-associates, .fields .field-billable,
.fields .actions, .fields .field-matter_description, .fields .field-client { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { display: block; }
.field > label .lock { margin-left: 6px; }
.field.readonly .value { padding: 7px 0; min-height: 34px; color: var(--text); border-bottom: 1px dashed var(--line); }
.checkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 12px; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 6px; }
.checkgrid label { font-weight: 400; }
.timeline { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 12px; max-height: 520px; overflow-y: auto; }
.timeline li { border-left: 2px solid var(--line); padding-left: 10px; font-size: 13px; }
.timeline .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.timeline .meta strong { color: var(--ink-2); }
.history li { font-size: 12.5px; }
.old { text-decoration: line-through; color: var(--muted); }
.new { font-weight: 600; }
.danger-zone { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel .table-wrap { border: 0; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #faf9f5; position: sticky; top: 0; white-space: nowrap; }
.grid th a { color: inherit; text-decoration: none; }
.grid th a.sorted { color: var(--ink); text-decoration: underline; }
.grid tr:hover td { background: #fbfaf6; }
.grid tr.inactive td { color: var(--muted); }
.grid .num { text-align: right; }
.grid .wrap { max-width: 520px; overflow-wrap: anywhere; }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell > * { margin-left: 4px; vertical-align: middle; }
.order-input { width: 70px; text-align: right; }
.matrix td { padding: 4px 6px; }
.matrix select { min-height: 28px; padding: 3px 6px; font-size: 12.5px; }
.matrix td.changed select { background: var(--warn-soft); border-color: var(--warn); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--ink); }

/* ---- customers: documents and billing ---- */
.customer-search { margin-bottom: 12px; }
.customer-search input[type=search] { width: 320px; max-width: 100%; }
.stats.profile-stats { grid-template-columns: repeat(3, minmax(130px, auto)); margin: 0; }
.stats.profile-stats div { background: var(--surface); border: 1px solid var(--line); }
.stats.profile-stats .is-overdue dd { color: var(--danger); }
.settings-form fieldset.choice { margin-bottom: 16px; }
.kind-filter { display: flex; gap: 4px; flex-wrap: wrap; }
.kind-filter a { padding: 3px 10px; border-radius: 999px; font-size: 12.5px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); }
.kind-filter a.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip-doc { background: var(--accent-soft); color: var(--accent); }
.bill-paid { background: var(--ok-soft); color: var(--ok); }
.bill-open { background: var(--warn-soft); color: var(--warn); }
.bill-overdue { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.doc-note { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.doc-list { list-style: none; margin: 0 0 12px; padding: 0; }
.doc-list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.doc-list .meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
details.attach { margin-top: 14px; }
details.attach > summary { display: inline-block; cursor: pointer; list-style: none; }
details.attach > summary::-webkit-details-marker { display: none; }
details.attach[open] > summary { margin-bottom: 12px; }
.grid tfoot td { font-weight: 600; border-bottom: 0; background: #faf9f5; }
.detail-list { margin: 0; }
.detail-list dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 10px; }
.detail-list dd { margin: 2px 0 0; }
.narrow-field { max-width: 420px; margin-bottom: 12px; }

/* ---- Exact connection steps ---- */
ol.steps { padding-left: 20px; margin: 4px 0 12px; display: grid; gap: 10px; font-size: 13.5px; }
ol.steps code.copyable { user-select: all; background: var(--paper); padding: 2px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.paste-back { margin: 8px 0 4px; width: 100%; }
.paste-back input[name=returned_url] { flex: 1 1 380px; min-width: 0; }
.warn-text { color: var(--warn); font-weight: 600; }
.inline-check { display: inline-flex; margin-left: 8px; font-weight: 400; }

/* ---- time & costs ---- */
.f-nonbill { fill: var(--viz-nonbill); }
.f-over { fill: var(--danger); }
.key-nonbill { background: var(--viz-nonbill); }
a.hrow, a.hrow:hover { color: inherit; text-decoration: none; cursor: pointer; }
a.hrow:hover .hlabel { text-decoration: underline; }
.hrow.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.hbars .hrow:has(.hvalue.wide) { grid-template-columns: minmax(110px, 34%) minmax(0, 1fr) 86px; }
.tile-unit { font-size: 14px; font-weight: 600; }
.bar-col { min-width: 150px; }
.meter, .meter-row { display: grid; grid-template-columns: minmax(60px, 1fr) auto; gap: 8px; align-items: center; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.meter.over span, .meter-row.over span { color: var(--danger); font-weight: 700; }
.meter-row { margin: 4px 0 2px; }
.small-link { font-size: 11.5px; margin-left: 6px; }
.compact-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.compact-stats dd { font-size: 18px; }
table.grid.compact th, table.grid.compact td { padding: 5px 8px; }
.heat td.num { font-variant-numeric: tabular-nums; min-width: 52px; }
.heat .heat-1 { background: #e2f3f1; }
.heat .heat-2 { background: #b9e2dd; }
.heat .heat-3 { background: #7cc7be; }
.heat .heat-4 { background: #2f9e93; color: #fff; }
.heat .heat-5 { background: #0a6b62; color: #fff; }
.grid.heat tr:hover td.heat-4, .grid.heat tr:hover td.heat-5 { background: #08564f; }

/* ---- dashboard ---- */
.dash-scope { margin: 0; }
.dash-filters { margin: 4px 0 6px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 10px 0 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.tile-value { font-size: 28px; font-weight: 600; line-height: 1.2; margin: 6px 0 4px; display: flex; align-items: center; gap: 8px; }
.tile-sub { font-size: 12px; color: var(--muted); }
.tile-keys { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.tile-keys > span { white-space: nowrap; }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.dash-grid .panel { margin-bottom: 0; }
.span-2 { grid-column: 1 / -1; }
.chart-card h2 { margin-bottom: 2px; }
.chart-card > .hint { margin-top: 0; }
.hbars { display: grid; gap: 2px; }
.hrow { display: grid; grid-template-columns: minmax(110px, 36%) minmax(0, 1fr) 56px; align-items: center; gap: 10px;
  padding: 4px 6px; border-radius: 6px; cursor: default; }
.hrow:hover, .hrow:focus-visible { background: #f4f3ee; outline: none; }
.hrow:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.hlabel { font-size: 13px; overflow-wrap: anywhere; line-height: 1.3; }
.hvalue { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.hgroup { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2);
  margin: 8px 0 2px; padding: 0 6px; display: flex; align-items: center; gap: 2px; }
.hgroup:first-child { margin-top: 0; }
.hgroup .muted { margin-left: 6px; font-weight: 600; }
.hbar { display: block; overflow: visible; }
.f-intake { fill: var(--viz-intake); }
.f-open { fill: var(--viz-open); }
.f-on_hold { fill: var(--viz-on_hold); }
.f-closed { fill: var(--viz-closed); }
.f-single { fill: var(--viz-single); }
.f-track { fill: var(--viz-track); }
.f-gap { fill: var(--surface); }
.hrow:hover rect:not(.f-gap):not(.f-track), .hrow:focus-visible rect:not(.f-gap):not(.f-track) { opacity: .82; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.key-intake { background: var(--viz-intake); }
.key-open { background: var(--viz-open); }
.key-on_hold { background: var(--viz-on_hold); }
.key-closed { background: var(--viz-closed); }
.key-billed { background: var(--viz-single); }
.key-estimate { background: var(--viz-track); }
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.multiples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.multiples figure { margin: 0; }
.multiples figcaption { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.colchart { display: block; width: 100%; height: auto; }
.colchart .tick { font-size: 11px; fill: var(--viz-tick); font-family: var(--font); font-variant-numeric: tabular-nums; }
.colchart .gridline { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.colchart .gridline.baseline { stroke: var(--viz-axis); }
.colchart .hit-area { fill: transparent; }
.colchart .hit { outline: none; }
.colchart .hit:hover .hit-area, .colchart .hit:focus .hit-area { fill: rgba(34, 36, 12, .05); }
.empty-state { color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 14px 16px; margin: 4px 0; font-size: 13px; }
.table-view { margin-top: 10px; }
.table-view summary { font-size: 12.5px; color: var(--accent); cursor: pointer; font-weight: 600; }
.table-view table { margin-top: 8px; }
.status-icon { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 12px;
  font-weight: 700; margin-right: 6px; flex: none; vertical-align: -3px; }
.tile-value .status-icon { width: 22px; height: 22px; font-size: 14px; margin: 0; }
.status-icon.critical { background: #d03b3b; color: #fff; }
.status-icon.warning { background: #fab219; color: #22240c; }
.status-icon.good { background: #0ca30c; color: #fff; }
.viz-tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: #f6f5ef; padding: 7px 10px;
  border-radius: 6px; box-shadow: var(--shadow-lift); max-width: 300px; font-size: 12px; line-height: 1.35; }
.viz-tip-value { font-weight: 700; font-size: 13px; }
.viz-tip-label { color: #c9c8bb; }

/* ---- import / code ---- */
fieldset.choice { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
fieldset.choice legend { font-weight: 600; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.radio-card { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; font-size: 13px; color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.radio-card input { margin-top: 3px; }
.radio-card:has(input:checked) { border-color: var(--ink); background: var(--accent-soft); }
.radio-card.danger:has(input:checked) { border-color: var(--danger); background: var(--danger-soft); }
.alert { padding: 12px 14px; border-radius: var(--radius); margin: 8px 0 12px; font-size: 13.5px; }
.alert-danger { background: var(--danger-soft); border: 1px solid #e3b9b2; color: #6e2318; }
.confirm-label { flex-direction: row; align-items: center; gap: 8px; }
.grant-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
.grant { align-items: flex-start; font-size: 13px; }
.grant input { margin-top: 3px; }
.grant .included-note { display: none; font-size: 12px; color: var(--ok); }
.grant.is-included .included-note { display: block; }
.grant.is-included strong { color: var(--muted); }
.access-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
@media (max-width: 640px) { .grant-grid { grid-template-columns: 1fr; } }
.confirm-label input { width: 130px; font-family: var(--mono); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 12px 0; }
.stats div { background: var(--paper); border-radius: var(--radius); padding: 10px 12px; }
.stats dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: 2px 0 0; font-size: 22px; font-weight: 600; }
ul.cols { columns: 3 180px; padding-left: 18px; }
ul.warnings { font-size: 12.5px; color: var(--muted); max-height: 320px; overflow-y: auto; }
.code-display { font-family: var(--mono); font-size: 48px; letter-spacing: .3em; font-weight: 700; margin: 16px 0; padding: 12px; background: var(--paper); border-radius: var(--radius); }

@media (max-width: 960px) {
  .matter-grid, .dash-grid, .multiples { grid-template-columns: 1fr; }
  .row-3 { grid-template-columns: 1fr 1fr; }
  .brand-name, .who { display: none; }
}
@media (max-width: 640px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand img { height: 28px; }
  .mainnav { gap: 0; }
  .mainnav > a, .mainnav summary { padding: 6px 7px; font-size: 13px; white-space: nowrap; }
  .menu summary::after { margin-left: 3px; }
  .colchart .tick { font-size: 18px; }
  .filter-menu { width: 100%; }
  .filter-panel { position: static; width: auto; margin-top: 8px; box-shadow: var(--shadow); }
  .filter-grid { grid-template-columns: 1fr; }
  .hrow { grid-template-columns: minmax(96px, 40%) minmax(0, 1fr) 44px; gap: 8px; }
  .fields, .row-2, .row-3 { grid-template-columns: 1fr; }
  .filters input[type=search] { width: 100%; }
  .page { padding: 16px 12px 48px; }
  .page-wide { padding: 12px; }
}
@media print {
  .topbar, .toolbar, .actions, .flashes, .danger-zone { display: none !important; }
  body { background: #fff; }
}
