/* =====================================================================================================
   Multifamily Intelligence — design system
   One token layer + a small set of reusable components. Pages use these classes; no page-specific palette.
   House rule: 18px base body type. No JavaScript. Fonts: locally available stack only (nothing downloaded).
   ===================================================================================================== */

:root {
    /* Surfaces & text */
    --bg: #f5f3ef;          /* warm light neutral canvas */
    --surface: #ffffff;
    --surface-sunken: #faf9f6;
    --text: #1d2733;          /* 15.5:1 on white */
    --text-2: #3b4856;        /* 9.6:1 */
    --muted: #5d6a78;         /* 5.4:1 */
    --border: #e4e0d8;
    --border-strong: #c9c3b8;

    /* Accent (restrained blue) */
    --accent: #1f67a8;        /* 5.6:1 with white text */
    --accent-hover: #17538a;
    --accent-soft: #e9f1f9;
    --focus: #2b7fd1;

    /* States (always paired with text, never colour alone) */
    --success: #1c6b43;  --success-soft: #e6f3ec;
    --warning: #7c4a00;  --warning-soft: #fdf2df;  --warning-border: #e9c47f;
    --danger: #a8231a;   --danger-soft: #fcebea;
    --research: #5e4494; --research-soft: #f0ebf8;   /* researched intelligence */
    --source: #2f5f4e;   --source-soft: #e7f1ec;     /* source / provenance */

    /* Type scale */
    --font: Inter, Arial, Helvetica, system-ui, sans-serif;
    --fs-page-title: 1.75rem;   /* 31.5px */
    --fs-section: 1.25rem;      /* 22.5px */
    --fs-sub: 1.05rem;
    --fs-body: 1rem;            /* 18px */
    --fs-table: 0.9rem;         /* 16.2px */
    --fs-caption: 0.84rem;      /* 15px */
    --fs-metric: 2.2rem;

    /* Shape & spacing */
    --radius: 8px;
    --radius-sm: 6px;
    --card-pad: 20px;
    --page-pad-x: 32px;
    --page-max: 1480px;
    --control-h: 46px;
    --row-h: 48px;
    --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 1px 3px rgba(16, 32, 48, .05);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-body); line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.25; color: var(--text); }
h1 { font-size: var(--fs-page-title); margin: 0; font-weight: 700; }
h2 { font-size: var(--fs-section); margin: 0 0 12px; font-weight: 650; }
h3 { font-size: var(--fs-sub); margin: 0 0 8px; font-weight: 650; }
p { margin: 0 0 12px; }
code { font-size: .85em; word-break: break-all; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -80px; background: var(--surface); color: var(--accent); font: inherit; font-weight: 600; padding: 10px 16px; border: 1px solid var(--accent); border-radius: var(--radius-sm); z-index: 100; box-shadow: var(--shadow); cursor: pointer; }
.skip-link:focus { top: 8px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------------------------------------------------------------- shell */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-header { background: var(--surface); border-bottom: 1px solid var(--border); position: relative; }
.app-header-inner { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--page-pad-x); display: flex; align-items: stretch; gap: 32px; min-height: 64px; }
.brand { display: flex; flex-direction: column; justify-content: center; text-decoration: none; color: var(--text); padding: 8px 0; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand-name { font-weight: 750; font-size: 1.05rem; letter-spacing: -.01em; }
.brand-tenant { font-size: var(--fs-caption); color: var(--muted); }
.nav { display: flex; align-items: stretch; gap: 4px; flex: 1; min-width: 0; }
.nav a { display: flex; align-items: center; padding: 0 14px; color: var(--text-2); text-decoration: none; font-weight: 550; border-bottom: 3px solid transparent; border-top: 3px solid transparent; white-space: nowrap; }
.nav a:hover { color: var(--accent); background: var(--surface-sunken); }
.nav a.active { color: var(--accent); border-bottom-color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.header-actions .admin-link { font-weight: 600; text-decoration: none; padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-2); }
.header-actions .admin-link.active, .header-actions .admin-link:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.header-actions .user { color: var(--muted); font-size: var(--fs-caption); }
.header-actions form { margin: 0; }

.subnav { background: var(--surface-sunken); border-bottom: 1px solid var(--border); }
.subnav-inner { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--page-pad-x); display: flex; gap: 4px; overflow-x: auto; }
.subnav-label { display: flex; align-items: center; padding-right: 12px; font-size: var(--fs-caption); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.subnav a { padding: 12px 14px; text-decoration: none; color: var(--text-2); font-weight: 550; border-bottom: 3px solid transparent; white-space: nowrap; }
.subnav a.active { color: var(--accent); border-bottom-color: var(--accent); }

.page { width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 28px var(--page-pad-x) 48px; flex: 1; }
.page-narrow { max-width: 560px; }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 24px; }
.page-header .subtitle { color: var(--muted); margin: 6px 0 0; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb { font-size: var(--fs-caption); color: var(--muted); margin-bottom: 8px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb span[aria-hidden] { margin: 0 6px; }
.app-footer { border-top: 1px solid var(--border); background: var(--surface); }
.app-footer-inner { max-width: var(--page-max); margin: 0 auto; padding: 12px var(--page-pad-x); font-size: var(--fs-caption); color: var(--muted); }

/* ---------------------------------------------------------------- building blocks */
.stack { display: flex; flex-direction: column; gap: 24px; }
.section { margin-top: 32px; }
.section-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.section-header p { margin: 0; color: var(--muted); font-size: var(--fs-caption); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--card-pad); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-title { font-size: var(--fs-sub); font-weight: 650; margin: 0 0 12px; }
.muted { color: var(--muted); }
.caption { font-size: var(--fs-caption); color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.unknown { color: var(--muted); font-style: italic; }

/* Metric cards: clickable drill-downs */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.metric { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
a.metric:hover { border-color: var(--accent); color: var(--text); }
a.metric:hover .metric-link { text-decoration: underline; }
.metric-label { font-size: var(--fs-caption); font-weight: 650; color: var(--text-2); }
.metric-value { font-size: var(--fs-metric); font-weight: 750; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric-link { font-size: var(--fs-caption); color: var(--accent); margin-top: 4px; }
.metric-attention { border-color: var(--warning-border); background: var(--warning-soft); }
.metric-attention .metric-value { color: var(--warning); }
.metric-ok .metric-value { color: var(--success); }

/* Key/value facts */
.kv { display: grid; grid-template-columns: minmax(120px, min(220px, 40%)) minmax(0, 1fr); gap: 10px 20px; margin: 0; }
.kv dt { color: var(--muted); font-size: var(--fs-caption); padding-top: 2px; }
.kv dd { margin: 0; overflow-wrap: break-word; min-width: 0; }

/* Badges: only for real state */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-caption); font-weight: 600; padding: 2px 10px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-research { background: var(--research-soft); color: var(--research); }
.badge-source { background: var(--source-soft); color: var(--source); }
.badge-neutral { background: var(--surface-sunken); color: var(--text-2); border-color: var(--border); }

/* Alerts */
.alert { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid; margin: 0 0 16px; }
.alert p { margin: 0; }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.alert-error { background: var(--danger-soft); border-color: #f0b4ae; color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: #a9d4bb; color: var(--success); }
.alert-info { background: var(--accent-soft); border-color: #bcd4ec; color: var(--accent-hover); }
.alert a { color: inherit; font-weight: 650; }

/* Empty state */
.empty { text-align: left; padding: 24px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--muted); margin: 0; }

/* Buttons & controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--control-h); padding: 0 18px; font: inherit; font-size: .95rem; font-weight: 600; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent); padding: 0 8px; }
.btn-quiet:hover { background: var(--accent-soft); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: var(--fs-caption); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field .label { font-size: var(--fs-caption); font-weight: 650; color: var(--text-2); }
.field .hint { font-size: var(--fs-caption); color: var(--muted); }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
    font: inherit; font-size: .95rem; min-height: var(--control-h); padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); width: 100%; }
textarea { padding: 10px 12px; min-height: 90px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.form { display: flex; flex-direction: column; gap: 16px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
label.check input { width: 20px; height: 20px; }
.validation-message { color: var(--danger); font-size: var(--fs-caption); }

/* Toolbar (search / filters / sort) */
.toolbar { background: var(--surface); border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; padding: 16px 20px; display: grid; grid-template-columns: minmax(240px, 2fr) repeat(auto-fit, minmax(130px, 1fr)); gap: 12px 14px; align-items: end; }
.toolbar .toolbar-actions { display: flex; gap: 8px; align-items: end; }
.result-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; padding: 10px 20px; background: var(--surface-sunken); border: 1px solid var(--border); border-bottom: none; font-size: var(--fs-caption); color: var(--text-2); }
.result-bar strong { color: var(--text); }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.toolbar + .result-bar + .table-wrap, .result-bar + .table-wrap { border-top-left-radius: 0; border-top-right-radius: 0; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-table); }
.table th, .table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th { background: var(--surface-sunken); font-size: var(--fs-caption); font-weight: 650; color: var(--text-2); white-space: nowrap; }
.table tbody tr { height: var(--row-h); }
.table tbody tr:hover { background: #f7f5f0; }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .primary-link { font-weight: 650; text-decoration: none; }
.table .primary-link:hover { text-decoration: underline; }
.table .sub { display: block; font-size: var(--fs-caption); color: var(--muted); }
.table tfoot td { background: var(--surface-sunken); font-weight: 650; border-top: 1px solid var(--border); border-bottom: none; }
.table.compact th, .table.compact td { padding: 8px 12px; }
.table tr.row-differs td { background: var(--warning-soft); }

.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-top: 12px; }
.pager nav { display: flex; gap: 6px; flex-wrap: wrap; }
.pager a, .pager span.current { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); text-decoration: none; }
.pager span.current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; }

/* Tabs (links; Blazor-native, no JS) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 0 24px; overflow-x: auto; }
.tabs a { padding: 12px 16px; text-decoration: none; color: var(--text-2); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--accent); }
.tabs a[aria-current=page] { color: var(--accent); border-bottom-color: var(--accent); }

/* Workspace header */
.workspace-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px 32px; align-items: flex-start; margin-bottom: 20px; }
.workspace-head .facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-top: 8px; color: var(--text-2); }
.workspace-head .facts strong { color: var(--text); }
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 18px; min-width: 130px; }
.stat .value { font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat .label { font-size: var(--fs-caption); color: var(--muted); }

/* Goal hero */
.goal-hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 28px; box-shadow: var(--shadow); display: grid; grid-template-columns: minmax(260px, 1fr) minmax(280px, 2fr); gap: 20px 40px; align-items: center; }
.goal-hero .goal-name { font-size: var(--fs-caption); font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.goal-hero .goal-number { font-size: 3rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin: 8px 0 4px; }
.goal-hero .goal-number .of { font-size: 1.4rem; font-weight: 650; color: var(--muted); letter-spacing: 0; }
.goal-hero .goal-number a { color: inherit; text-decoration: none; }
.goal-hero .goal-number a:hover { text-decoration: underline; }
.progress-track { height: 14px; background: #e3e8ee; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; min-width: 0; }
.goal-meta { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-top: 12px; color: var(--text-2); }
.goal-meta strong { color: var(--text); }

/* Data-health list (secondary) */
.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.health a, .health div { padding: 14px 18px; border-right: 1px solid var(--border); text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.health a:hover { background: var(--surface-sunken); }
.health .h-label { font-size: var(--fs-caption); color: var(--muted); }
.health .h-value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Upload area */
.upload { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 24px; border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-sunken); }
.upload:hover, .upload:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.upload input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload input[type=file]:disabled { cursor: progress; }
.upload:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.upload .upload-title { font-size: var(--fs-sub); font-weight: 700; }
.upload .upload-cta { margin-top: 6px; }

/* Stepper (import wizard) */
.steps { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0 0 20px; counter-reset: step; }
.steps li { counter-increment: step; padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: var(--fs-caption); font-weight: 600; color: var(--muted); }
.steps li::before { content: counter(step) ". "; }
.steps li.done { color: var(--success); border-color: #a9d4bb; background: var(--success-soft); }
.steps li.current { color: #fff; background: var(--accent); border-color: var(--accent); }
.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.counts div { background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; display: flex; flex-direction: column; }
.counts span { font-size: var(--fs-caption); color: var(--muted); }
.counts strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.counts .bad { background: var(--danger-soft); }
.counts .warn { background: var(--warning-soft); }
.scroll { overflow-x: auto; max-width: 100%; }
.sample td, .sample th { white-space: nowrap; font-size: var(--fs-caption); }
.sample tr.header-row td { background: var(--accent-soft); font-weight: 700; }

/* Data quality items */
.issue { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--warning-border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow); }
.issue.resolved { border-left-color: #a9d4bb; }
.issue.research { border-left-color: #c9b8e6; }
.issue-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.issue-head h3 { margin: 0; }
.issue .explain { color: var(--text-2); }
.issue .interpretation { font-weight: 600; margin: 12px 0; }
.decisions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 12px; }
.decision { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-sunken); display: flex; flex-direction: column; gap: 8px; }
.decision p { margin: 0; font-size: var(--fs-caption); color: var(--text-2); }
.decision .btn { align-self: flex-start; }

details.disclosure { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 0 16px; margin-bottom: 10px; }
details.disclosure summary { cursor: pointer; padding: 12px 0; font-weight: 600; }
details.disclosure[open] { padding-bottom: 12px; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 12px 16px; background: var(--warning-soft); border-top: 2px solid var(--warning-border); z-index: 1000; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
    .goal-hero { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    :root { --page-pad-x: 20px; }
    .app-header-inner { flex-wrap: wrap; gap: 0 16px; }
    .brand { flex: 1; }
    .nav { order: 3; flex-basis: 100%; overflow-x: auto; border-top: 1px solid var(--border); }
    .nav a { padding: 12px 14px; }
    .toolbar { grid-template-columns: 1fr 1fr; }
    .toolbar .field-search { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    :root { --page-pad-x: 16px; --fs-page-title: 1.45rem; --fs-metric: 1.8rem; }
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dd { margin-bottom: 10px; }
    .toolbar { grid-template-columns: 1fr; }
    .header-actions .user { display: none; }
    .table th, .table td { padding: 10px 12px; }
    .hide-sm { display: none; }
    .goal-hero { padding: 20px; }
    .goal-hero .goal-number { font-size: 2.4rem; }
}
.block { display: block; }

/* ---------------------------------------------------------------- review fixes */
/* Blazor moves focus to the page heading after navigation (for screen readers); no ring for that programmatic focus. */
h1:focus, h1:focus-visible { outline: none; }
.grid-2 > .card, .grid-2 > .card + .card { margin-top: 0; }
.table tr.row-differs th { background: var(--warning-soft); }
.table a:not(.primary-link):not(.btn) { text-decoration-color: rgba(31, 103, 168, .35); text-decoration-thickness: 1px; }
.table a:not(.primary-link):not(.btn):hover { text-decoration-color: currentColor; }
/* Toolbar: wrapping flex so controls keep readable widths at every size. */
.toolbar { display: flex; flex-wrap: wrap; }
.toolbar > .field { flex: 1 1 150px; }
.toolbar > .field-search { flex: 2 1 300px; }
.toolbar > .field:has(select[name=sort]) { flex: 1 1 230px; }
.toolbar > .toolbar-actions { flex: 0 0 auto; }
.show-sm { display: none; }
@media (max-width: 640px) {
    .nav { flex-wrap: wrap; overflow-x: visible; }
    .nav a { padding: 10px 12px; }
    .show-sm { display: inline-flex; margin-top: 4px; }
}
main:focus { outline: none; }
.toolbar > .field:not(.field-search) { max-width: 300px; }
@media (max-width: 640px) { .toolbar > .field:not(.field-search) { max-width: none; } }

/* =====================================================================================================
   Set 002 — operational components
   ===================================================================================================== */
.table thead th { background: var(--surface-sunken); border-bottom: 1px solid var(--border); }
.table td { border-bottom-color: #efece6; }
.table .primary-link { color: var(--text); font-weight: 650; }
.table .primary-link:hover { color: var(--accent); }

/* Record header: the page's identity, key facts and next action in one band. */
.record { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 26px 18px; margin-bottom: 20px; box-shadow: var(--shadow); }
.record-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px 32px; align-items: flex-start; }
.record-eyebrow { font-size: var(--fs-caption); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.record h1 { margin: 4px 0 2px; }
.record .record-sub { color: var(--text-2); }
.record-figure { text-align: right; }
.record-figure .n { font-size: 2.6rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.record-figure .u { font-size: var(--fs-caption); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.record-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 24px; margin-top: 18px; padding-top: 16px; border-top: 1px solid #efece6; }
.record-facts .f-label { font-size: var(--fs-caption); color: var(--muted); display: block; }
.record-facts .f-value { font-weight: 600; overflow-wrap: anywhere; }
.record-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* State chips: always text, colour only reinforces. */
.chip { display: inline-flex; align-items: center; font-size: var(--fs-caption); font-weight: 600; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-sunken); color: var(--text-2); white-space: nowrap; }
.chip-attention { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.chip-open { background: var(--accent-soft); color: var(--accent-hover); border-color: #c5d8ec; }
.chip-done { background: var(--success-soft); color: var(--success); border-color: #b8dcc6; }
.chip-won { background: var(--success); color: #fff; border-color: var(--success); }
.chip-muted { color: var(--muted); font-style: italic; }

/* Sections inside workspaces */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; padding: 14px 20px; border-bottom: 1px solid #efece6; }
.panel-head h2, .panel-head h3 { margin: 0; font-size: var(--fs-sub); }
.panel-body { padding: 16px 20px; }
.panel-body > :last-child { margin-bottom: 0; }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.cols-even { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); gap: 18px; align-items: start; }

/* Inline composers (Blazor state; no dialogs). */
.composer { background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; margin: 10px 0; display: flex; flex-direction: column; gap: 12px; }
.composer .row { display: flex; flex-wrap: wrap; gap: 12px; }
.composer .row > .field { flex: 1 1 200px; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-actions .btn[aria-pressed=true] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 4px 16px; padding: 12px 0; border-bottom: 1px solid #efece6; }
.timeline li:last-child { border-bottom: none; }
.timeline .when { font-size: var(--fs-caption); color: var(--muted); }
.timeline .type { font-size: var(--fs-caption); font-weight: 700; color: var(--text-2); display: block; }
.timeline .ctx { font-size: var(--fs-caption); color: var(--muted); display: block; margin-top: 2px; }

/* Task rows */
.tasks { list-style: none; margin: 0; padding: 0; }
.task { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 16px; padding: 12px 0; border-bottom: 1px solid #efece6; }
/* Text takes the room it needs; in a narrow panel the actions wrap below it instead of squeezing it. */
.task > div:first-child { flex: 1 1 300px; min-width: 0; }
.task:last-child { border-bottom: none; }
.task-title { font-weight: 650; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-caption); color: var(--text-2); }
.task-due-overdue { color: var(--danger); font-weight: 700; }
.task-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 0 1 auto; }
.task .composer, .task > p { flex-basis: 100%; }

/* Suggestions (deterministic prompts) */
.focus-list { display: flex; flex-direction: column; gap: 12px; }
.suggestion { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 14px 18px; display: grid; grid-template-columns: 1fr auto; gap: 6px 20px; box-shadow: var(--shadow); }
.suggestion .what { font-weight: 700; font-size: 1.02rem; }
.suggestion .why { color: var(--text-2); }
.suggestion .evidence { font-size: var(--fs-caption); color: var(--muted); margin: 2px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 2px 14px; }
.suggestion .rel { font-size: var(--fs-caption); font-weight: 700; color: var(--text-2); white-space: nowrap; text-align: right; }
.suggestion .act { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.suggestion .composer { grid-column: 1 / -1; }

/* Pipeline stages */
.stages { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.stages a { padding: 14px 16px; border-right: 1px solid #efece6; text-decoration: none; color: var(--text); display: flex; flex-direction: column; gap: 2px; }
.stages a:hover { background: var(--surface-sunken); }
.stages a[aria-current=page] { background: var(--accent-soft); box-shadow: inset 0 -3px 0 var(--accent); }
.stages .s-name { font-size: var(--fs-caption); font-weight: 700; color: var(--text-2); }
.stages .s-doors { font-size: 1.45rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stages .s-count { font-size: var(--fs-caption); color: var(--muted); }
.stages .won { background: var(--success-soft); }

/* Won vs pipeline strip on the goal */
.goal-split { display: flex; flex-wrap: wrap; gap: 10px 26px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #efece6; }
.goal-split .gs { display: flex; flex-direction: column; }
.goal-split .gs-label { font-size: var(--fs-caption); color: var(--muted); }
.goal-split .gs-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.goal-split .gs-won .gs-value { color: var(--success); }
.goal-split .divider { border-left: 1px dashed var(--border-strong); }

/* Compact toolbar with native disclosure for secondary filters */
.toolbar-compact { background: var(--surface); border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.toolbar-compact .field { flex: 0 1 200px; }
.toolbar-compact .field-search { flex: 1 1 320px; }
.toolbar-compact details.more { flex-basis: 100%; }
.toolbar-compact details.more summary { cursor: pointer; font-weight: 600; font-size: var(--fs-caption); color: var(--accent); padding: 4px 0; display: inline-block; }
.toolbar-compact details.more .more-body { display: flex; flex-wrap: wrap; gap: 10px 12px; margin-top: 8px; }
.toolbar-compact details.more .more-body .field { flex: 0 1 190px; }
.toolbar-compact label { font-size: var(--fs-caption); font-weight: 650; color: var(--text-2); }

.checklist { list-style: none; padding: 0; margin: 0; max-height: 380px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.checklist li { border-bottom: 1px solid #efece6; }
.checklist label { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; }
.checklist input { width: 20px; height: 20px; flex: none; }
.checklist .doors { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 650; }

@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
    .record { padding: 16px; }
    .record-figure { text-align: left; }
    .timeline li { grid-template-columns: 1fr; }
    .suggestion { grid-template-columns: 1fr; }
    .suggestion .act, .suggestion .rel { align-items: flex-start; text-align: left; }
    .task > div:first-child { flex-basis: 100%; }
}
.goal-split a.gs { text-decoration: none; color: var(--text); }
.goal-split a.gs:hover .gs-value { text-decoration: underline; }

/* Show / Hide on password fields (password-toggle.js). The button is shown only when the script runs. */
.pw-field { display: flex; gap: 8px; align-items: stretch; min-width: 0; }
.pw-field input { flex: 1 1 auto; min-width: 0; }
.pw-toggle { display: none; flex: none; min-width: 76px; min-height: var(--control-h); padding: 0 14px; font: inherit; font-size: .95rem; font-weight: 600;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--accent); cursor: pointer; }
.has-password-toggle .pw-toggle { display: inline-flex; align-items: center; justify-content: center; }
.pw-toggle:hover { background: var(--accent-soft); }
.pw-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.pw-rules { margin: 0; padding-left: 20px; color: var(--text-2); font-size: var(--fs-caption); }
.pw-rules li + li { margin-top: 2px; }
