/* Ledgerline styles; the reasons: docs/UI.md "Design system" and "styles.css notes". */

:root {
  /* Tally Draft — approved brand colors */
  --brand-orange: #E87838;
  --brand-graphite: #202631;
  --brand-warm-white: #FAFAF8;

  /* Type */
  --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --fs-2xs: 10px;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-title: 26px;
  --fs-h2: var(--fs-lg);
  --fw-medium: 500;
  --fw-semibold: 600;
  --tracking-caps: 0.08em;

  /* Neutrals */
  --bg: #FAFAF8;
  --surface: #ffffff;
  --surface-2: #f4f3ef;
  --surface-3: #ecebe6;
  --surface-raised: #ffffff;
  --raised-hover: #f4f3ef;
  --border: #e3e2dd;
  --border-strong: #c8c7c1;
  --control-border: #7b8490;
  --text: #202631;
  --text-2: #47515e;
  --text-muted: #616c79;
  --row-selected: #fbe4d7;
  --ink-typed: #1747a6;

  /* One accent */
  --accent: #a84719;
  --accent-hover: #843611;
  --accent-soft: #fcebe1;
  --accent-text: #202631;
  --accent-fill: var(--brand-orange);
  --accent-fill-hover: #f18a4f;
  --accent-fill-weight: var(--fw-semibold);
  --focus: #ad4e20;
  --focus-halo: rgba(232, 120, 56, 0.24);

  /* Status */
  --danger: #b42318;
  --danger-text: #ffffff;
  --danger-hover: #9a1d14;
  --danger-soft: #fcebea;
  --warning: #8a5a00;
  --warning-soft: #fcf2df;
  --ok: #1c7141;
  --ok-soft: #e6f4ec;
  --info: #3b577c;
  --info-soft: #eaf0f7;
  --flash: #fbe7a1;
  --overlay: rgba(16, 22, 32, 0.38);
  --skeleton-shine: rgba(255, 255, 255, 0.55);
  --paper-line: #e9edf1;

  /* The graphite sidebar */
  --nav-bg: #202631;
  --nav-bg-hover: #2a3340;
  --nav-bg-active: #343e4b;
  --nav-text: #FAFAF8;
  --nav-text-muted: #c0c7d1;
  --nav-label: #a6b0bd;
  --nav-border: rgba(255, 255, 255, 0.08);
  --nav-focus: #f3945d;
  --nav-dot-ok: #5cc28c;
  --nav-dot-warning: #e3ae4f;
  --nav-dot-danger: #f07167;
  --rail-edge: transparent;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  /* Radii */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  /* Control and row heights */
  --control-h: 32px;
  --control-h-sm: 28px;
  --control-h-xs: 22px;
  --row-h: 28px;
  --table-row-h: 44px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-pop: 0 10px 28px rgba(16, 24, 40, 0.14), 0 1px 3px rgba(16, 24, 40, 0.08);

  /* Layers */
  --z-sticky: 4;
  --z-sidebar: 50;
  --z-header: 100;
  --z-side-panel: 800;
  --z-popover: 1100;
  --z-tooltip: 1150;
  --z-toast: 2000;

  /* Motion */
  --motion-instant: 80ms;
  --motion-fast: 120ms;
  --motion-enter: 160ms;
  --motion-base: 200ms;
  --motion-exit: 100ms;
  --motion-flash: 400ms;
  --motion-cue: 400ms;
  --wait-delay: 200ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: var(--ease);
  --ease-in: cubic-bezier(0.3, 0, 1, 1);
  --ease-fade: cubic-bezier(0, 0, 0.58, 1);

  /* Layout */
  --topbar-h: 44px;
  --rail-w: 240px;
  --side-w: 420px;
  --page-pad-x: 32px;
  --page-pad-top: 28px;
  --hairline: 1px solid var(--border);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a2029;
    --surface: #202631;
    --surface-2: #262e3a;
    --surface-3: #303a47;
    --surface-raised: #29323e;
    --raised-hover: #303a47;
    --border: #394351;
    --border-strong: #566171;
    --control-border: #8290a2;
    --text: #FAFAF8;
    --text-2: #d4d9e0;
    --text-muted: #adb7c4;
    --row-selected: #493428;
    --ink-typed: #8ab4f8;
    --accent: #f3945d;
    --accent-hover: #faab7c;
    --accent-soft: #493125;
    --accent-text: #202631;
    --accent-fill: var(--brand-orange);
    --accent-fill-hover: #f18a4f;
    --accent-fill-weight: var(--fw-semibold);
    --focus: #f3945d;
    --focus-halo: rgba(243, 148, 93, 0.24);
    --danger: #f28b82;
    --danger-text: #1b0a08;
    --danger-hover: #f5a19a;
    --danger-soft: #3b201e;
    --warning: #e3ae4f;
    --warning-soft: #362b16;
    --ok: #63c793;
    --ok-soft: #173124;
    --info: #9cb6d6;
    --info-soft: #1d2939;
    --flash: #5c4e14;
    --overlay: rgba(0, 0, 0, 0.55);
    --skeleton-shine: rgba(255, 255, 255, 0.05);
    --paper-line: #e9edf1;
    --nav-bg: #1a2029;
    --nav-bg-hover: #262e3a;
    --nav-bg-active: #303a47;
    --nav-text: #FAFAF8;
    --nav-text-muted: #c0c7d1;
    --nav-label: #a6b0bd;
    --nav-border: rgba(255, 255, 255, 0.07);
    --rail-edge: var(--nav-border);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-pop: 0 10px 28px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1a2029;
  --surface: #202631;
  --surface-2: #262e3a;
  --surface-3: #303a47;
  --surface-raised: #29323e;
  --raised-hover: #303a47;
  --border: #394351;
  --border-strong: #566171;
  --control-border: #8290a2;
  --text: #FAFAF8;
  --text-2: #d4d9e0;
  --text-muted: #adb7c4;
  --row-selected: #493428;
  --ink-typed: #8ab4f8;
  --accent: #f3945d;
  --accent-hover: #faab7c;
  --accent-soft: #493125;
  --accent-text: #202631;
  --accent-fill: var(--brand-orange);
  --accent-fill-hover: #f18a4f;
  --accent-fill-weight: var(--fw-semibold);
  --focus: #f3945d;
  --focus-halo: rgba(243, 148, 93, 0.24);
  --danger: #f28b82;
  --danger-text: #1b0a08;
  --danger-hover: #f5a19a;
  --danger-soft: #3b201e;
  --warning: #e3ae4f;
  --warning-soft: #362b16;
  --ok: #63c793;
  --ok-soft: #173124;
  --info: #9cb6d6;
  --info-soft: #1d2939;
  --flash: #5c4e14;
  --overlay: rgba(0, 0, 0, 0.55);
  --skeleton-shine: rgba(255, 255, 255, 0.05);
  --paper-line: #e9edf1;
  --nav-bg: #1a2029;
  --nav-bg-hover: #262e3a;
  --nav-bg-active: #303a47;
  --nav-text: #FAFAF8;
  --nav-text-muted: #c0c7d1;
  --nav-label: #a6b0bd;
  --nav-border: rgba(255, 255, 255, 0.07);
  --rail-edge: var(--nav-border);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 10px 28px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

/* == Base == */

*, *::before, *::after { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs)/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.005em; }
p { margin: 0 0 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--text-muted); }
.small, .palette-label { font-size: var(--fs-sm); }
.mono { font-family: var(--font-mono); font-size: 0.95em; }
.code { font-family: var(--font-ui); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.grid-scroll .code { font: inherit; letter-spacing: normal; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt-pos::after { content: ")"; visibility: hidden; }
.warn-text, .toast-warning .toast-glyph { color: var(--warning); }
.boot { padding: 48px; color: var(--text-muted); }
body.resizing-col { cursor: col-resize; user-select: none; }
.icon { flex: none; vertical-align: -3px; }
kbd, .kbd {
  display: inline-block; min-width: 18px; padding: 0 4px; border: var(--hairline); border-bottom-width: 2px;
  border-radius: 3px; font: 500 var(--fs-xs)/16px var(--font-ui); color: var(--text-muted); background: var(--surface);
  text-align: center; margin-left: 2px;
}

/* == Buttons and inputs == */

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: var(--control-h); padding: 0 var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
  color: var(--text); font-weight: var(--fw-medium); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--control-border); text-decoration: none; color: var(--text); }
.btn:active { background: var(--surface-3); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
/* [IMP-03] */
.btn.disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
:is(label, a).btn:is(.disabled, [aria-disabled="true"]) { pointer-events: none; }
.btn-primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-text); font-weight: var(--accent-fill-weight); }
.btn-primary:hover, .btn-primary:active { background: var(--accent-fill-hover); border-color: var(--accent-fill-hover); color: var(--accent-text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-text); }
.btn-danger:hover, .btn-danger:active { background: var(--danger-hover); border-color: var(--danger-hover); color: var(--danger-text); }
.btn-primary:disabled, .btn-primary[disabled], .btn-primary:is(.disabled, [aria-disabled="true"]), .btn-danger:disabled, .btn-danger[disabled] {
  opacity: 1; background: var(--surface-3); border-color: var(--border); color: var(--text-muted);
}
.btn-danger-ghost { color: var(--danger); border-color: var(--border); }
.btn-danger-ghost:hover { background: var(--danger-soft); color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-ghost:active { background: var(--surface-3); }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]:disabled { opacity: 1; }
.btn-primary[aria-busy="true"]:disabled { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-text); }
.btn-danger[aria-busy="true"]:disabled { background: var(--danger); border-color: var(--danger); color: var(--danger-text); }
.btn[aria-busy="true"] > .icon:first-child { display: none; }
.btn[aria-busy="true"]::before {
  content: ""; flex: none; width: 12px; height: 12px; margin: 0 2px; border-radius: 50%; animation: ll-spin 0.8s linear infinite;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
}
/* [SH-16] */
.table tbody tr:hover .btn:not(:hover, :active, :disabled, .on, .btn-primary, .btn-danger, .btn-ghost) { background: var(--surface); }
.table tbody tr:hover .btn-ghost:hover:not(:active) { background: var(--surface); }
.btn-sm { height: var(--control-h-sm); padding: 0 var(--space-2); font-size: var(--fs-sm); }
.btn-xs { height: var(--control-h-xs); padding: 0 7px; font-size: var(--fs-xs); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn-link, .link-btn {
  border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left;
}
.link-btn:hover, .btn-link:hover { text-decoration: underline; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: var(--control-h-sm); height: var(--control-h-sm); padding: 0;
  border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { background: var(--surface-3); }
.icon-btn:disabled { opacity: 0.4; cursor: default; background: transparent; }

.input, .select {
  height: var(--control-h); padding: 0 10px; border: 1px solid var(--control-border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); min-width: 0; width: 100%;
  transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.input:hover:not(:focus, :disabled, .invalid, [aria-invalid="true"]), .select:hover:not(:focus, :disabled) { border-color: var(--text-muted); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-muted); }
textarea.input { height: auto; padding: 8px 10px; }
select.input, .select { padding-right: 24px; }
.input::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, .combobox-input:focus {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus), 0 0 0 4px var(--focus-halo);
}
.input.invalid, .input[aria-invalid="true"] { border-color: var(--danger); }
input[type="checkbox"], input[type="radio"] { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
input[type="file"].input { height: auto; padding: 6px; }

.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field-label { font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--text-2); }
.field-hint, .menu-hint, .page-label { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { color: var(--danger); font-size: var(--fs-sm); }
.field-error::before { content: "\00d7  "; font-weight: 700; }
.req, .toast-error .toast-glyph, .drill-tie.bad { color: var(--danger); }
.check-row { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.field-check { justify-content: center; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); }
.form-grid .span-2 { grid-column: span 2; }
.inline-field { display: inline-flex; align-items: center; gap: var(--space-2); }
.inline-field > span { font-size: var(--fs-sm); color: var(--text-2); font-weight: var(--fw-semibold); }
.inline-field .input { width: auto; }

/* == App frame == */

.app { height: 100%; display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); background: var(--surface); }
.app-column { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: var(--z-header); flex: none; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 0 var(--space-4) 0 var(--space-5);
  background: var(--surface); border-bottom: var(--hairline); min-width: 0; overflow: visible;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--space-1); min-width: 0; }
.topbar-left { flex: 1 1 auto; }
.topbar-left .ctx-menu { flex: 0 1 auto; max-width: min(560px, 100%); min-width: 0; }
.topbar-right { flex: none; gap: var(--space-2); }
.topbar .btn { height: var(--control-h-sm); }
.tb-firm { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-btn { max-width: 100%; min-width: 0; gap: 6px; padding: 0 var(--space-2); font-size: var(--fs-sm); font-weight: 400; }
.ctx-client { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ctx-sep { color: var(--text-muted); }
.ctx-eng { color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ctx-loading, .no-tb { color: var(--text-muted); font-size: var(--fs-sm); }
.status-btn { padding: 0 6px; gap: 4px; }
.topbar .status-pill { margin-left: 0; }
.tb-count { min-width: 18px; justify-content: center; }
.tb-save { display: inline-flex; align-items: center; gap: var(--space-1); }
.palette-btn { padding: 0 var(--space-2); color: var(--text-muted); gap: 6px; font-weight: 400; }
@media (min-width: 1280px) {
  .topbar .palette-btn { width: 220px; border-color: var(--border); background: var(--surface-2); }
  .palette-btn .kbd-hint { margin-left: auto; }
}
.kbd-hint { font-size: var(--fs-xs); color: var(--text-muted); border: var(--hairline); border-radius: var(--radius-sm); padding: 0 4px; line-height: 16px; }
.user-btn { gap: var(--space-2); padding: 0 var(--space-1); font-size: var(--fs-sm); }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; background: var(--surface-3); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700;
}
.undo-redo { display: inline-flex; gap: 0; }
.undo-redo .icon-btn { width: 26px; height: 26px; }
.ai-toggle { gap: 6px; }
.brand-lockup { display: inline-flex; align-items: center; gap: 12px; max-width: 100%; color: inherit; }
.brand-mark { display: block; width: 42px; height: auto; flex: none; }
.brand-name { font-weight: 800; letter-spacing: -0.045em; line-height: 1.05; white-space: nowrap; }
.nav-brand .brand-mark { width: 38px; }
.login-brand .brand-mark { width: 52px; }
.skip-link { position: fixed; left: 8px; top: -40px; z-index: var(--z-toast); padding: 6px 10px; background: var(--surface); border: 1px solid var(--focus); border-radius: var(--radius); }
.skip-link:focus { top: 8px; }
.menu-id { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); margin-bottom: var(--space-1); }
.menu-id .avatar { width: 28px; height: 28px; font-size: var(--fs-xs); }
.menu-id b { display: block; font-weight: 600; }
.menu-id b + span { display: block; font-size: var(--fs-xs); color: var(--text-muted); }

.saved-ind { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.saved-glyph { font-weight: 700; }
.saved-saved .saved-glyph, .status-pill.st-final, .toast-success .toast-glyph, .drill-tie.ok { color: var(--ok); }
.saved-saving { color: var(--text-2); }
.saved-offline { color: var(--warning); font-weight: 600; }
.saved-readonly { color: var(--text-muted); border: var(--hairline); border-radius: 10px; padding: 0 8px; }

.diag-chip {
  display: inline-flex; align-items: center; gap: var(--space-2); height: 26px; padding: 0 10px; border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap; font-size: var(--fs-sm);
}
.diag-chip:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.diag-chip.tone-blocking { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.diag-chip.tone-warning { border-color: var(--warning); background: var(--warning-soft); color: var(--warning); }
.diag-chip.tone-ok { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.dc { display: inline-flex; align-items: center; gap: 3px; }
.dc-glyph {
  display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%;
  font-size: 10px; font-weight: 800; line-height: 1; border: 1.5px solid currentColor;
}
.dc-info .dc-glyph { font-style: italic; font-family: Georgia, serif; }
.diag-counts { display: inline-flex; gap: 10px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.diag-counts .dc-blocking.on { color: var(--danger); font-weight: 700; }
.diag-counts .dc-warning.on { color: var(--warning); font-weight: 700; }
.diag-counts .dc-info.on { color: var(--info); }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); position: relative; }
.workspace-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); }
.workspace-main:focus, .global-main:focus, .menu-item:focus { outline: none; }
.step-content { flex: 1; min-height: 0; overflow: auto; position: relative; scroll-padding-top: 40px; }
/* [SE-13] */
.workspace-side {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(var(--side-w), 44%); z-index: var(--z-side-panel);
  border-left: var(--hairline); background: var(--surface); box-shadow: var(--shadow-pop); overflow: hidden; display: flex;
}
.workspace-side > * { flex: 1; min-width: 0; }
.global-main { flex: 1; min-height: 0; overflow: auto; background: var(--bg); scroll-padding-top: 40px; }
.app-global .page-header { background: transparent; }

/* Page header */
.page-header { flex: none; padding: var(--page-pad-top) var(--page-pad-x) var(--space-4); background: var(--surface); }
.page > .page-header { padding: 0 0 var(--space-4); }
.ph-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.ph-text { min-width: 0; }
.ph-crumb { font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--space-2); }
.ph-title { font-size: var(--fs-title); font-weight: var(--fw-semibold); line-height: 1.2; letter-spacing: -0.01em; color: var(--text); }
.ph-crumb a { color: inherit; }
.ph-crumb a:hover { color: var(--accent); text-decoration: none; }
.ph-desc { margin: var(--space-2) 0 0; color: var(--text-muted); max-width: 90ch; }
.ph-actions, .step-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.ph-tabs { margin-top: var(--space-5); }
.ph-tabs .tabs { margin-bottom: 0; }
.ph-toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-4); }
.ph-toolbar .search-box { flex: 1 1 320px; max-width: 520px; }
.page-header.step-header { padding-bottom: var(--space-4); }
.page-header.ph-compact { padding: 12px var(--page-pad-x) 8px; }
.ph-compact .ph-top { align-items: center; }
.ph-compact .ph-crumb { display: inline; margin: 0 8px 0 0; }
.ph-compact .ph-title { display: inline; font-size: var(--fs-xl); }
.ph-compact .ph-tabs { margin-top: var(--space-3); }
.ph-compact .info-tip { margin-left: 2px; vertical-align: -5px; }
.info-tip .icon-btn { width: 24px; height: 24px; color: var(--text-muted); }

.step-intro h2.ph-title { font-size: var(--fs-xl); }

/* The graphite sidebar */
.sidebar {
  position: relative; z-index: var(--z-sidebar); min-height: 0; overflow-y: auto; overflow-x: hidden; container: rail / inline-size;
  display: flex; flex-direction: column; padding: var(--space-4) var(--space-3) var(--space-3);
  background: var(--nav-bg); color: var(--nav-text); color-scheme: dark;
  box-shadow: inset -1px 0 0 var(--rail-edge);
}
.sidebar :focus-visible { outline-color: var(--nav-focus); }
.nav-brand { display: flex; align-items: center; gap: 10px; padding: var(--space-1) var(--space-2) var(--space-5); color: var(--nav-text); }
.nav-brand:hover, .nav-back:hover, .rail-toggle:hover { color: var(--nav-text); text-decoration: none; }
.nav-wordmark { font-size: 23px; }
.nav-client { padding: var(--space-1) var(--space-2) var(--space-5); border-bottom: 1px solid var(--nav-border); margin-bottom: var(--space-4); }
.nav-client-name { font-size: var(--fs-md); font-weight: 700; line-height: 1.3; color: #ffffff; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nav-client-meta { margin-top: var(--space-1); font-size: var(--fs-xs); color: var(--nav-text-muted); }
.nav-client .nav-skeleton { height: 44px; width: 70%; opacity: 0.25; }
.nav-section { padding: 0 var(--space-2) var(--space-2); font-size: var(--fs-xs); font-weight: 600; letter-spacing: var(--tracking-caps); color: var(--nav-label); }
.nav-sub { padding: 12px 8px 4px; text-transform: uppercase; }
.rail-list > .nav-sub:first-child { padding-top: 0; }
.rail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rail-scroll { flex: 1; min-height: 0; overflow-y: auto; margin: -4px; padding: 4px; scrollbar-width: thin; scrollbar-color: var(--nav-label) transparent; }
.rail-item {
  display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 6px var(--space-2); border-radius: var(--radius);
  color: var(--nav-text-muted); line-height: 1.25; font-size: var(--fs-sm);
  transition: background-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.rail-item:hover { background: var(--nav-bg-hover); color: var(--nav-text); text-decoration: none; }
.rail-item.current { background: var(--nav-bg-active); color: #ffffff; font-weight: 700; box-shadow: inset 3px 0 0 var(--brand-orange); }
.rail-icon { display: inline-flex; flex: none; color: inherit; opacity: 0.9; }
.rail-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-num { flex: none; font-size: var(--fs-2xs); color: var(--nav-label); font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.rail-item.current .rail-num { color: var(--nav-text-muted); }
.rail-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; }
.rail-dot.d-complete { background: var(--nav-dot-ok); opacity: 0.8; }
.rail-dot.d-in_progress { background: var(--nav-dot-warning); }
.rail-dot.d-blocking { background: var(--nav-dot-danger); box-shadow: 0 0 0 2px rgba(240, 113, 103, 0.25); }
.rail-foot { margin-top: auto; display: flex; align-items: center; justify-content: flex-end; gap: var(--space-1); padding-top: var(--space-4); }
.nav-back { flex: 1; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-2); color: var(--nav-text-muted); font-size: var(--fs-sm); }
.rail-toggle { display: none; color: var(--nav-text-muted); }
.rail-toggle:hover { background: var(--nav-bg-hover); }
.rail-fade .sidebar :is(.rail-label, .rail-num, .nav-section, .nav-client, .nav-wordmark) { animation: ll-fade-in var(--motion-fast) var(--ease); }
@media (max-height: 899px) {
  .rail-item { min-height: 28px; }
  .nav-sub { padding: 6px 8px 2px; }
  .nav-brand, .nav-client { padding-bottom: var(--space-3); }
  .nav-client { margin-bottom: var(--space-2); }
}
@container rail (max-width: 100px) {
  .rail-scroll { scrollbar-width: none; }
  .nav-brand { justify-content: center; padding: var(--space-1) 0 var(--space-4); }
  .nav-wordmark, .nav-client, .nav-section, .rail-num { display: none; }
  .nav-sub { display: block; height: 1px; padding: 0; margin: 6px 12px; overflow: hidden; color: transparent; background: var(--nav-border); }
  .rail-item { justify-content: center; padding: 8px 4px; gap: 4px; position: relative; }
  .rail-item .rail-label, .nav-back .rail-label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .rail-dot { position: absolute; top: 6px; right: 8px; }
  .nav-back { justify-content: center; position: relative; }
  .rail-foot { flex-direction: column; }
}

/* Side panels */
.side-panel { display: flex; flex-direction: column; min-height: 0; }
.side-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: var(--hairline); font-weight: 600; }
.side-panel-body { flex: 1; min-height: 0; overflow: auto; }

/* Notices and panels */
.notice { padding: 8px 12px; border: var(--hairline); border-radius: var(--radius); margin: var(--space-2) var(--page-pad-x) 0; font-size: var(--fs-sm); }
.page .notice { margin: 0 0 12px; }
.notice-info { background: var(--info-soft); border-color: transparent; color: var(--text); }
.notice-warn { background: var(--warning-soft); border-color: transparent; }
.notice-muted { background: var(--surface-2); border-color: transparent; color: var(--text-2); }
.error-panel {
  border: 1px solid var(--danger); border-left-width: 3px; background: var(--danger-soft); border-radius: var(--radius);
  padding: 12px 14px; margin: 12px 0; color: var(--text);
}
.error-panel strong::before { content: "\00d7  "; color: var(--danger); font-weight: 800; }
.error-panel p { margin: 6px 0; color: var(--text-2); }
.loading-panel { display: flex; align-items: center; gap: 10px; padding: 24px 4px; color: var(--text-muted); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: ll-spin 0.8s linear infinite; }
@keyframes ll-spin { to { transform: rotate(360deg); } }
.empty-panel { padding: 28px 16px; text-align: center; color: var(--text-muted); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.empty-panel strong, .empty-panel > .icon { display: block; color: var(--text-2); margin: 0 auto 4px; }
.empty-panel .btn { margin-top: 10px; }

/* Badges */
.badge, .status-pill, .chip, .tab-count, .tb-count, .qol-kind, .qol-status, .im-pill, .cz-badge, .ie-badge, .ai-draft-badge {
  display: inline-flex; align-items: center; gap: var(--space-1); height: 18px; padding: 0 6px; border-radius: var(--radius-pill);
  font: 600 var(--fs-xs)/16px var(--font-ui); font-variant-numeric: tabular-nums; border: 1px solid transparent; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.badge.tone-neutral, .badge-muted { background: var(--surface-2); color: var(--text-2); }
.badge.tone-accent, .chip-on { background: var(--accent-soft); color: var(--accent); }
.badge.tone-ok { background: var(--ok-soft); color: var(--ok); }
.badge.tone-warning, .badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge.tone-danger { background: var(--danger-soft); color: var(--danger); }
.badge.tone-info { background: var(--info-soft); color: var(--info); }
.status-pill { margin-left: 6px; background: transparent; border-color: currentColor; color: var(--text-2); }
.status-pill.st-in_review { color: var(--info); }
.status-pill.st-archived { color: var(--text-muted); }
.chip { margin: 0 4px 4px 0; max-width: 100%; height: auto; min-height: 18px; white-space: normal; }

/* Pages (global screens) */
.page { max-width: 1240px; margin: 0 auto; padding: var(--page-pad-top) var(--page-pad-x) 56px; }
.page-wide { max-width: none; height: 100%; display: flex; flex-direction: column; padding-bottom: var(--space-4); }
.breadcrumb { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--space-2); }
.toolbar { display: flex; align-items: center; gap: var(--space-2) var(--space-3); flex-wrap: wrap; margin: 0 0 var(--space-3); }
.toolbar .spacer, .ph-toolbar .spacer, .toolbar-row .spacer { flex: 1; }
.toolbar-row { display: flex; align-items: center; gap: var(--space-2) var(--space-3); flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }
.toolbar-row .inline-field .input, .ph-toolbar .inline-field .input, .toolbar .inline-field .input { max-width: 240px; }
.search-box { position: relative; display: inline-flex; align-items: center; flex: 0 1 380px; min-width: 200px; }
.search-box .icon { position: absolute; left: 10px; color: var(--text-muted); pointer-events: none; }
.search-box .input { padding-left: 32px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: var(--space-6) 0 var(--space-3); }
.section-title, .card-title, .modal-title { font-size: var(--fs-h2); font-weight: var(--fw-semibold); line-height: 1.3; }
.subsection-title { font-size: var(--fs); margin: 18px 0 8px; color: var(--text-2); }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 24px; margin: 0; padding: var(--space-4); background: var(--surface); border: var(--hairline); border-radius: var(--radius-lg); }
@media (min-width: 1024px) { .facts-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.facts dt { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.facts dd { margin: 2px 0 0; }
.card { background: var(--surface); border: var(--hairline); border-radius: var(--radius-lg); padding: var(--space-4); margin: 0 0 var(--space-4); }
.card-title { margin-bottom: var(--space-3); }
.deleted-section { margin-top: var(--space-6); }
.disclosure { padding-left: 4px; }
.strong-link, .combobox-option.current .opt-label, .preview-title { font-weight: 600; }

/* Tables (lists) */
.table-wrap { overflow-x: auto; border: var(--hairline); border-radius: var(--radius-lg); background: var(--surface); }
.table-wrap.fits { overflow: clip; }
.table-wrap.wide { max-height: calc(100vh - 330px); overflow: auto; scroll-padding-top: 40px; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 10px var(--space-3); text-align: left; border-bottom: var(--hairline); vertical-align: middle; }
.table tbody td { height: var(--table-row-h); }
.table thead th { background: var(--surface-2); font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; position: sticky; top: 0; z-index: 1; padding-top: 8px; padding-bottom: 8px;
  border-bottom: 0; box-shadow: inset 0 -1px 0 var(--border); }
.table td thead th { position: static; }
.table-top td, .table-top tbody th { vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table th.num, .table td.num, .grid-editor.num { text-align: right; }
.table .cell-main { font-weight: var(--fw-medium); color: var(--text); }
.row-go { cursor: pointer; }
.table .sub-link, .table .sub-link:hover { color: var(--text-2); }
.table .cell-sub { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--text-muted); font-weight: 400; }
.table-dense th, .table-dense td { padding: 4px 8px; }
.table-dense tbody td { height: auto; }
.table .vt-spacer td { padding: 0; border: 0; background: none; }
.table tbody tr.vt-spacer:hover td { background: none; }
.table tfoot th, .table tfoot td { border-top: 1px solid var(--border-strong); border-bottom: 0; font-weight: 600; background: var(--surface); }
.th-btn { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.th-sort { font-size: 9px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn { margin-left: 4px; }
.row-actions > * { vertical-align: middle; }
.row-marked td { background: var(--row-selected); --text-muted: var(--text-2); }

/* Tabs (underlined) and segmented controls */
.tabs { display: flex; gap: var(--space-5); border-bottom: var(--hairline); margin-bottom: var(--space-3); }
.tab {
  border: 0; background: none; padding: var(--space-2) 0; cursor: pointer; color: var(--text-muted); font-weight: var(--fw-medium);
  border-bottom: 2px solid transparent; margin-bottom: -1px; position: relative; transition: color var(--motion-fast) var(--ease);
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); }
.tab.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; background: var(--accent); }
.tab-count { margin-left: 6px; }
.segmented { display: inline-flex; border: 1px solid var(--control-border); border-radius: var(--radius); overflow: hidden; }
.seg { border: 0; background: var(--surface); height: calc(var(--control-h) - 2px); padding: 0 var(--space-3); cursor: pointer; color: var(--text-2); }
.seg:hover { background: var(--surface-2); }
.seg:active { background: var(--surface-3); }
.seg + .seg { border-left: 1px solid var(--control-border); }
.seg.on { background: var(--accent-soft); color: var(--accent); }
.seg:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus); }
.segmented.is-disabled .seg { cursor: not-allowed; opacity: 0.6; }
.segmented.is-disabled .seg.on { opacity: 0.8; }

/* Skeletons */
.skeleton { display: block; background: var(--surface-3); border-radius: var(--radius-sm); position: relative; overflow: hidden; }
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  animation: ll-shimmer 1.6s linear 3;
}
.skeleton-line { height: 12px; margin: 6px 0; }
.skeleton-title { height: 26px; width: 38%; margin: 10px 0 12px; }
.skeleton-crumb { height: 9px; width: 90px; }
.skeleton-row { height: var(--table-row-h); border-bottom: var(--hairline); display: flex; align-items: center; gap: var(--space-4); padding: 0 var(--space-3); }
.skeleton-row .skeleton { height: 10px; }
.skeleton-page { padding: var(--page-pad-top) var(--page-pad-x); }
.skeleton-table { border: var(--hairline); border-radius: var(--radius-lg); margin-top: var(--space-5); overflow: hidden; }
@keyframes ll-shimmer { to { transform: translateX(100%); } }
.skeleton-rows { padding: var(--space-1) 0; }
.skeleton-rows .skeleton-table { margin-top: 0; }
.skeleton-pagebox { display: flex; justify-content: center; padding: var(--space-6); }
.skeleton-paper { width: min(420px, 100%); aspect-ratio: 8.5 / 11; background: var(--surface); box-shadow: var(--shadow-sm); border: var(--hairline); padding: var(--space-7) var(--space-6); }
.skeleton-paper-row { display: flex; justify-content: space-between; gap: var(--space-4); }

/* == Grid == */

.grid { position: relative; height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border: var(--hairline); border-radius: var(--radius-lg); overflow: hidden; }
.grid-scroll { flex: 1; min-height: 0; overflow: auto; position: relative; outline: none; font-variant-numeric: tabular-nums;
  scroll-padding-top: 32px; user-select: none; }   /* [GRD-01] */
.grid-cell.editing, .grid-editor { user-select: text; }
.grid-scroll:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.grid-canvas { position: relative; min-width: 100%; }
.grid-header { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; background: var(--surface-2); border-bottom: var(--hairline); }
.grid-hcell {
  position: relative; display: flex; align-items: center; gap: var(--space-1); padding: 0 var(--space-3); font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-muted); border-right: 1px solid transparent; white-space: nowrap; overflow: hidden; user-select: none; background: var(--surface-2);
}
.grid-header:hover .grid-hcell { border-right-color: var(--border); }
.grid-hcell.sortable { cursor: pointer; }
.grid-hcell.sortable:hover { color: var(--text); }
.grid-hlabel { overflow: hidden; text-overflow: ellipsis; }
.grid-sort { font-size: var(--fs-2xs); color: var(--accent); }
.grid-sort sub { font-size: 8px; }
.grid-hcell.sticky, .grid-cell.sticky { position: sticky; z-index: 2; }
.grid-hcell.sticky { z-index: 5; }
.grid-hcell.sticky-r, .grid-cell.sticky-r { border-left: var(--hairline); }
.grid-resize { position: absolute; right: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 6; touch-action: none; }
.grid-resize:hover::after { content: ""; position: absolute; left: 3px; top: 0; bottom: 0; width: 2px; background: var(--accent); }
.grid-body { position: relative; }
.grid-row { position: absolute; left: 0; display: flex; border-bottom: var(--hairline); background: var(--surface); }
.grid-row:hover { background: var(--surface-2); }
.grid-row.selected { background: var(--row-selected); --text-muted: var(--text-2); }
.grid-row.row-inactive .grid-cell { color: var(--text-muted); }
.grid-cell {
  display: flex; align-items: center; gap: 6px; padding: 0 var(--space-3); min-width: 0; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; border-right: 1px solid transparent; background: inherit; cursor: default;
}
.grid-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-cell.editable { cursor: cell; }
.grid-row .grid-cell.sticky { background: inherit; }
.grid-cell.al-right, .grid-hcell.al-right { justify-content: flex-end; text-align: right; }
.grid-cell.al-center, .grid-hcell.al-center { justify-content: center; }
.grid-cell.active { box-shadow: inset 0 0 0 1px var(--control-border); }
.grid-row.selected .grid-cell.active { box-shadow: inset 0 0 0 1px var(--text-2); }
.grid-scroll:focus .grid-cell.active, .grid-scroll:focus-within .grid-cell.active { box-shadow: inset 0 0 0 2px var(--focus); }
.grid-cell.editing { padding: 0; overflow: visible; z-index: 3; }
.grid-editor-wrap { position: relative; width: 100%; height: 100%; }
.grid-editor { height: 100%; width: 100%; border-radius: 0; border-color: var(--accent); }
.grid-editor-error {
  position: absolute; top: 100%; left: 0; z-index: 8; min-width: 180px; padding: var(--space-1) var(--space-2); background: var(--danger);
  color: var(--danger-text); font-size: var(--fs-xs); border-radius: 0 0 var(--radius) var(--radius); white-space: normal;
}
.grid-cell .combobox { width: 100%; height: 100%; }
.grid-cell .combobox-input { height: 100%; border-radius: 0; border-color: var(--accent); }
.grid-group { background: var(--surface-2); font-weight: 600; }
.grid-group:hover { background: var(--surface-3); }
.grid-group.active .grid-group-label { box-shadow: inset 0 0 0 2px var(--accent); }
.grid-group-label { gap: var(--space-2); cursor: pointer; background: inherit; }
.grid-group-count { color: var(--text-muted); font-weight: 400; font-size: var(--fs-xs); }
.grid-group-sum { font-weight: 600; justify-content: flex-end; }
.grid-twisty { display: inline-flex; color: var(--text-muted); }
.grid-footer { position: sticky; bottom: 0; z-index: 4; display: flex; background: var(--surface-2); border-top: 1px solid var(--border-strong); font-weight: 600; }
.grid-footer .grid-cell.sticky { background: var(--surface-2); }
.grid-empty { padding: var(--space-6) var(--space-3); color: var(--text-muted); }
.grid-check { cursor: pointer; }
.grid-handle-cell, .grid-select-cell { justify-content: center; padding: 0; }
.grid-handle { cursor: grab; color: var(--text-muted); display: inline-flex; padding: var(--space-1) 2px; }
.grid-handle:active { cursor: grabbing; }
.grid-row.dragging { opacity: 0.45; }
.grid-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.grid-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.grid-readonly .grid-cell.editable { cursor: default; }
.cell-actions { display: inline-flex; gap: 2px; }
.cell-actions .icon-btn { width: 24px; height: 22px; }

/* == Number cells, overrides, tooltips == */

.num-cell {
  position: relative; display: inline-flex; align-items: center; justify-content: flex-end; min-width: 90px; width: 100%;
  height: calc(var(--row-h) - 4px); padding: 0 var(--space-2); border: 1px solid transparent; border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums; white-space: nowrap; outline: none;
}
.num-cell.al-left { justify-content: flex-start; }
.num-cell.editable { background: var(--surface); border-color: var(--border); cursor: text; }
.num-cell.editable:hover { border-color: var(--border-strong); }
.num-cell.editable:focus { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus), 0 0 0 4px var(--focus-halo); }
.num-cell.derived { color: var(--text-2); background: transparent; }
.num-cell.derived[title], .num-cell.derived .tt-anchor { cursor: help; }
.num-cell.pulled { color: var(--text-muted); }
.num-cell.editing { padding: 0; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus), 0 0 0 4px var(--focus-halo); }
.num-input { width: 100%; height: 100%; border: 0; padding: 0 var(--space-2); text-align: right; background: var(--surface); outline: none; font-variant-numeric: tabular-nums; }
.num-input.invalid { background: var(--danger-soft); }
.num-error {
  position: absolute; top: 100%; right: 0; z-index: 8; padding: var(--space-1) var(--space-2); background: var(--danger); color: var(--danger-text);
  font-size: var(--fs-xs); border-radius: 0 0 var(--radius) var(--radius); white-space: nowrap;
}
.num-cell .tt-anchor { display: inline-flex; align-items: center; justify-content: flex-end; width: 100%; height: 100%; }

.ovr-marker { position: relative; box-shadow: inset 2px 0 0 var(--accent); padding-left: var(--space-2); }
.ovr-corner {
  position: absolute; top: 0; right: 0; width: 0; height: 0; border-style: solid; border-width: 0 6px 6px 0;
  border-color: transparent var(--accent) transparent transparent;
}
.ovr-highlight { background: var(--accent-soft); outline: 1px dashed var(--accent); outline-offset: -1px; }
.ovr-tip { min-width: 220px; }
.ovr-dl { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--space-3); margin: var(--space-1) 0 var(--space-2); }
.ovr-dl dt { color: var(--text-muted); }
.ovr-dl dd { margin: 0; }

.tt-anchor { position: relative; }
.tooltip {
  position: fixed; z-index: var(--z-tooltip); max-width: 380px; padding: var(--space-2) var(--space-3); background: var(--surface-raised); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: var(--fs-sm); line-height: 1.4;
  box-shadow: var(--shadow-pop); white-space: normal; text-align: left; font-style: normal; font-weight: 400;
}
.tip-label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.tip-formula { color: var(--text); }
.tip-extra { margin-top: var(--space-1); color: var(--text-2); }

/* == Combobox, menus, dialogs, toasts, palette == */

.combobox { position: relative; }
.combobox-list {
  position: fixed; z-index: var(--z-popover); max-height: 320px; overflow-y: auto; margin: 0; padding: var(--space-1) 0; list-style: none;
  background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}
.combobox-option { display: flex; align-items: baseline; gap: var(--space-2); padding: var(--space-1) var(--space-3); cursor: pointer; line-height: 1.3; }
.combobox-option:hover { background: var(--raised-hover); }
/* [SH-10, V3a-06] */
.combobox-option.active { background: var(--accent-soft); }
[data-kbd] .active { box-shadow: inset 2px 0 0 var(--accent); }
.combobox-option.disabled { cursor: not-allowed; color: var(--text-muted); }
.opt-code { font-family: var(--font-ui); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; font-size: var(--fs-sm); min-width: 44px; color: var(--text-2); }
.opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* CMB-02 */
.opt-hit { background: none; color: inherit; font-weight: 600; text-decoration: underline 1px; text-underline-offset: 2px; }
.opt-group { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.opt-reason { font-size: var(--fs-xs); color: var(--warning); white-space: nowrap; }
.opt-reason::before { content: "! "; font-weight: 700; }
.combobox-empty { padding: var(--space-2) var(--space-3); color: var(--text-muted); }

.menu { position: relative; display: inline-block; }
.menu-list {
  position: fixed; top: 0; left: 0; z-index: calc(var(--z-toast) + 1); min-width: 240px; max-width: min(420px, calc(100vw - 16px)); margin: 0; padding: var(--space-1) 0; list-style: none;
  background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  max-height: 70vh; overflow-y: auto; font-size: var(--fs);
}
.menu-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: 6px var(--space-3); line-height: 1.3; border: 0; background: none; cursor: pointer;
  text-align: left; color: var(--text);
}
.menu-item:hover { background: var(--raised-hover); }
.menu-item:focus-visible { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); outline: none; }
.menu-item:disabled { color: var(--text-muted); cursor: default; background: none; }
.menu-item.danger { color: var(--danger); }
.menu-check { width: 14px; display: inline-flex; color: var(--accent); }
.menu-label { flex: 1; }
.menu-sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }
.menu-heading { padding: var(--space-2) var(--space-3) 2px; font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.menu-seg { padding: var(--space-1) var(--space-3) var(--space-2); }
.menu-seg .segmented { display: flex; }
.menu-seg .seg { flex: 1; height: calc(var(--control-h-sm) - 2px); }

dialog.modal, dialog.palette {
  padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text);
  max-height: calc(100vh - 48px); box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: var(--overlay); }
.modal-sm { width: min(440px, calc(100vw - 32px)); }
.modal-md { width: min(620px, calc(100vw - 32px)); }
.modal-lg { width: min(900px, calc(100vw - 32px)); }
.modal-xl { width: min(1180px, calc(100vw - 32px)); }
.modal-frame { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: var(--hairline); }
.modal-body { padding: var(--space-4); overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-top: var(--hairline); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.confirm-body p { margin-bottom: var(--space-3); }
.confirm-body .check-row { margin-top: var(--space-2); align-items: flex-start; }

.toast-host { position: fixed; right: 16px; bottom: 16px; z-index: var(--z-toast); pointer-events: none; }
.toast-stack { display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-end; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); width: 380px; max-width: calc(100vw - 32px); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  background: var(--surface-raised); color: var(--text); border: 1px solid var(--border-strong); border-left-width: 3px;
  border-radius: var(--radius); box-shadow: var(--shadow-pop); font-size: var(--fs-sm);
}
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info { border-left-color: var(--accent); }
.toast-glyph {
  display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; flex: none;
  font-weight: 800; font-size: var(--fs-xs); border: 1.5px solid currentColor;
}
.toast-info .toast-glyph { color: var(--accent); font-family: Georgia, serif; font-style: italic; }
.toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-close { width: 22px; height: 22px; }

dialog.palette { width: min(680px, calc(100vw - 32px)); margin-top: 12vh; }
.palette-frame { display: flex; flex-direction: column; max-height: 70vh; }
.palette-search { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: var(--hairline); color: var(--text-muted); }
.palette-input { flex: 1; border: 0; background: none; font-size: var(--fs-md); outline: none; color: var(--text); padding: var(--space-1) 0; }
.palette-list, .palette-list ul { list-style: none; margin: 0; padding: 0; }
.palette-list { padding-bottom: var(--space-2); overflow-y: auto; }
.palette-head { padding: var(--space-3) var(--space-4) var(--space-1); }
.palette-item { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: var(--space-3); align-items: center; padding: 6px var(--space-4); cursor: pointer; }
.palette-item:hover { background: var(--raised-hover); }
.palette-item.active { background: var(--accent-soft); }
.drill-kicker { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.palette-title, .palette-hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-hint, .palette-item .icon { font-size: var(--fs-xs); color: var(--text-muted); max-width: 240px; }
.pal-hit { background: none; color: var(--text); font-weight: 600; }
.palette-empty { padding: var(--space-4); color: var(--text-muted); }
.palette-foot { display: flex; gap: var(--space-4); padding: var(--space-2) var(--space-4); border-top: var(--hairline); font-size: var(--fs-xs); color: var(--text-muted); background: var(--surface-2); }

/* == Split pane and preview == */

.split { display: flex; height: 100%; min-height: 0; width: 100%; }
.split-pane { min-width: 0; min-height: 0; overflow: auto; position: relative; }
.split-divider {
  flex: none; width: 9px; position: relative; cursor: col-resize; background: var(--surface-2);
  border-left: var(--hairline); border-right: var(--hairline); outline: none; touch-action: none;
}
.split-divider:hover, .split-divider:focus-visible { background: var(--accent-soft); }
.split-divider:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.split-buttons { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--space-1); }
.split-btn { width: 20px; height: 24px; background: var(--surface); border: var(--hairline); }
.split-stacked { flex-direction: column; }
.split-switch { flex: none; padding: var(--space-2) var(--space-3); border-bottom: var(--hairline); background: var(--surface); }
.split-stacked .split-pane { flex: 1; }
.split-pane[hidden] { display: none; }

.preview-pane { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--surface-3); }
.preview-toolbar {
  flex: none; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); background: var(--surface); border-bottom: var(--hairline);
  font-size: var(--fs-sm);
}
.preview-meta { flex: 1; display: inline-flex; gap: var(--space-2); align-items: center; color: var(--text-muted); }
.preview-tools { display: inline-flex; gap: var(--space-1); }
.preview-note { order: 9; flex: 1 0 100%; font-size: var(--fs-xs); color: var(--text-muted); }
.preview-toolbar:has(> .preview-note) { flex-wrap: wrap; row-gap: var(--space-1); }
.figures-draggable .ll-hit[draggable="true"] { cursor: grab; }
.preview-scroll { flex: 1; min-height: 0; overflow: auto; scrollbar-gutter: stable both-edges; padding: var(--space-6); outline: none; }
.preview-state { padding: var(--space-7); text-align: center; color: var(--text-muted); }
.page-list { display: flex; flex-direction: column; align-items: safe center; gap: var(--space-6); min-width: max-content; }
.page-wrap { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.page-frame { position: relative; overflow: hidden; background: #ffffff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.14); flex: none; color-scheme: light; }
.page-scale { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #ffffff; }
.page-scale > svg, .page-scale > * { display: block; width: 100% !important; height: 100% !important; }
.page-thumbs { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: center; }
.page-thumb { border: 0; padding: 0; background: none; cursor: zoom-in; display: flex; flex-direction: column; align-items: center; gap: var(--space-1); }
.page-thumb:focus-visible .page-frame { box-shadow: 0 0 0 2px var(--focus); }
.page-modal { display: flex; justify-content: center; background: var(--surface-3); padding: var(--space-4); }

/* Drill-down */
.drilldown { display: flex; flex-direction: column; min-height: 0; height: 100%; background: var(--surface); }
.drill-head { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4) var(--space-3); border-bottom: var(--hairline); }
.drill-title { font-size: var(--fs-md); margin-top: 2px; }
.drill-body { flex: 1; min-height: 0; overflow: auto; padding: var(--space-3) var(--space-4); }
.drill-scroll { overflow-x: auto; }
.drill-table { font-size: var(--fs-sm); }
.drill-table td, .drill-table th { white-space: nowrap; }
.drill-table tbody td:nth-child(2) { white-space: normal; min-width: 120px; }
.drill-total td:first-child, .drill-total tfoot th { white-space: normal; overflow-wrap: anywhere; }
.drill-total tbody td:nth-child(2) { white-space: nowrap; min-width: 0; }
.drill-note, .drill-members { font-size: var(--fs-sm); color: var(--text-2); }
.drill-tie { margin-top: var(--space-3); font-size: var(--fs-sm); font-weight: 600; }
.drill-typed { margin: 0; padding: var(--space-2) var(--space-4); border-bottom: var(--hairline); background: var(--surface-2); }
.drill-foot { flex: none; display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-top: var(--hairline); }

/* Master chart */
.scope-field { margin-bottom: 0; }
.scope-field .input { min-width: 200px; }
.catalog-grid { flex: 1; min-height: 380px; }
.keys-help { margin-top: var(--space-2); }
.affected-wrap { max-height: 320px; overflow: auto; margin-bottom: var(--space-3); }
.import-report { margin-top: var(--space-3); }

/* Login */
.login-page { height: 100%; display: flex; align-items: center; justify-content: center; padding: var(--space-4); overflow: auto; background: var(--bg); }
.login-card { width: min(440px, 100%); background: var(--surface); border: var(--hairline); border-radius: 12px; padding: var(--space-7); box-shadow: var(--shadow-md); }
.login-brand { display: flex; align-items: center; font-size: 32px; color: var(--text); margin-bottom: var(--space-7); }
.login-title { font-size: var(--fs-xl); margin-bottom: var(--space-2); }
.login-sub { color: var(--text-muted); margin-bottom: var(--space-5); }
.login-form { display: flex; flex-direction: column; gap: var(--space-4); }
.login-form .btn { height: 36px; }
.login-err { min-height: 18px; margin: -8px 0 8px; line-height: 18px; }
.login-label { display: flex; justify-content: space-between; gap: var(--space-2); }
.login-recovery { align-self: flex-end; font-size: var(--fs-sm); }
.login-recovery[aria-disabled="true"] { opacity: .5; cursor: default; }
.login-footer { margin-top: var(--space-5); text-align: center; }

/* == Motion (docs/UI.md "Motion") == */
@keyframes ll-pop { from { opacity: 0; transform: translateY(-4px); } }
@keyframes ll-pop-up { from { opacity: 0; transform: translateY(4px); } }
@keyframes ll-fade-in { from { opacity: 0; } }
@keyframes ll-reveal { from { opacity: 0; } to { opacity: 1; } }
@keyframes ll-dialog-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes ll-rise-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes ll-drawer-in { from { opacity: .6; transform: translateX(24px); } }
@keyframes ll-settle { from { opacity: .6; transform: translateY(4px); } }
@keyframes ll-flash { 0%, 20% { background-color: var(--flash); } to { background-color: transparent; } }
@keyframes ll-bump { 40% { transform: scale(1.06); } }
@keyframes ll-sweep { from { transform: translateX(-100%); } to { transform: translateX(330%); } }
@keyframes ll-unfold { from { opacity: .6; transform: translateY(-4px); } }
@keyframes ll-tab-grow { from { transform: scaleX(.4); } }
.menu-list, .combobox-list, .tooltip, .toast { contain: layout paint; }
.menu-list, .combobox-list { animation: ll-pop var(--motion-fast) var(--ease); }
.menu-list[data-placement="above"], .combobox-list.above { animation-name: ll-pop-up; }
.tooltip { animation: ll-fade-in var(--motion-instant) var(--ease); }
.tooltip:not(.tooltip-interactive) { pointer-events: none; }
dialog.modal[open], dialog.palette[open] { animation: ll-dialog-in var(--motion-enter) var(--ease); }
dialog[open]::backdrop { animation: ll-fade-in var(--motion-enter) linear; }
.toast { animation: ll-rise-in var(--motion-enter) var(--ease); }
.diag-chip.bump { animation: ll-bump 300ms var(--ease); }
.diag-chip.bump .dc.up { animation: ll-flash var(--motion-flash) var(--ease-fade); }
.workspace-side { animation: ll-drawer-in var(--motion-enter) var(--ease); }
/* waits (M20, M21, M23) */
.skeleton-rows, .skeleton-page, .skeleton-pagebox, .route-progress { animation: ll-reveal 1ms linear var(--wait-delay) both; }
.nav-skeleton, .ctx-loading > .skeleton { animation: ll-fade-in 1ms linear var(--wait-delay) both; }
.wait-slot .badge, .m7-card > h3 .badge[role="status"] { animation: ll-fade-in var(--motion-fast) var(--ease) calc(200ms + var(--wait-delay)) both; }
.preview-toolbar, .m8-viewer-bar { position: relative; }
.wait-slot .badge { position: absolute; z-index: 2; top: calc(100% + 4px); right: var(--space-3); pointer-events: none; }
.route-progress { position: absolute; top: 100%; left: 0; right: 0; height: 2px; overflow: hidden; pointer-events: none; }
.route-progress::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 30%; background: var(--accent); animation: ll-sweep 1100ms linear infinite; }
.icon-btn, .seg, .chip, .m8-tpl, .m7-drop, .im-drop, .cz-chip, .split-divider { transition: background-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease); }
.btn:active, .icon-btn:active, .seg:active { transition-duration: 0s; }
.tabs.moved > .tab.on::after { animation: ll-tab-grow var(--motion-fast) var(--ease); }
.chev { display: inline-block; }
.chev, .grid-twisty { transition: transform var(--motion-fast) var(--ease); }
[aria-expanded="true"] > .chev, [aria-expanded="true"] .grid-twisty { transform: rotate(90deg); }
[open] > summary > .chev { transform: rotate(90deg); }
.saved-ind { transition: color var(--motion-fast) var(--ease); }
.saved-glyph { animation: ll-fade-in var(--motion-fast) var(--ease); }
.btn.is-done { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.m7-block-body { animation: ll-unfold var(--motion-fast) var(--ease); }

/* == Responsiveness (§3.5) == */

@media (max-width: 1365px) {
  :root { --rail-w: 232px; --page-pad-x: 24px; }
}

@media (min-width: 1024px) and (max-width: 1279px) {
  .rail-toggle { display: inline-flex; }
  .rail-collapsed { --rail-w: 64px; }
  .rail-collapsed .sidebar { padding: var(--space-3) var(--space-2); }
}

@media (max-width: 1439px) {
  .user-name { display: none; }
}

@media (max-width: 1279px) {
  .workspace-side { position: fixed; top: var(--topbar-h); width: min(var(--side-w), 92vw); }
  .ai-toggle .ai-label, .palette-label { display: none; }
  .topbar .saved-text {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .topbar .saved-offline .saved-text { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; }
}

/* icon rail */
@media (max-width: 1023px) {
  :root { --rail-w: 64px; --page-pad-x: 16px; }
  .sidebar { padding: var(--space-3) var(--space-2); }
  .kbd-hint { display: none; }
  .table-wrap.fits { overflow-x: auto; }
}

@media (max-width: 767px) {
  :root { --rail-w: 52px; --topbar-h: 52px; }
  .topbar { gap: 2px 6px; padding: 2px 8px; height: auto; min-height: var(--topbar-h); flex-wrap: wrap; }
  .topbar-left { flex: 1 1 100%; }
  .topbar-right { flex: 1 1 100%; justify-content: flex-end; flex-wrap: wrap; row-gap: 2px; }
  .workspace-side { top: 0; width: 100vw; z-index: 1200; }
  .ctx-eng { display: none; }
  .page { padding: 14px 12px 40px; }
  .page-header, .step-intro { padding: 14px 12px 10px; }
  .step-intro, .ph-top { flex-direction: column; }
  .ph-title { font-size: var(--fs-xl); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .undo-redo { display: none; }
  /* 44 px targets, read-only */
  .narrow .btn, .narrow .rail-item, .narrow .icon-btn, .narrow .tab, .narrow .seg,
  .narrow .menu-item, .narrow .palette-item, .narrow .link-btn, .narrow .diag-chip, .narrow .table a {
    min-height: 44px;
  }
  .narrow .icon-btn { min-width: 44px; }
  .narrow .se-toggle, .narrow .check-row { min-height: 44px; padding: 0 4px; }
  .narrow .se-toggle input[type="checkbox"], .narrow .check-row input[type="checkbox"],
  .narrow .se-toggle input[type="radio"], .narrow .check-row input[type="radio"] { width: 20px; height: 20px; }
  .narrow .table td, .narrow .table th { padding: 10px 10px; }
  .narrow .table a, .narrow .link-btn { display: inline-flex; align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  dialog::backdrop, .diag-chip.bump { animation: none !important; }
  .skeleton::after { display: none; }
  .route-progress::before { animation: none !important; width: 100%; opacity: .8; transform: none; }
}

@media print {
  .topbar, .rail, .sidebar, .step-intro, .page-header, .preview-toolbar, .toast-host { display: none !important; }
  .app { display: block; }
  body { overflow: visible; background: #fff; }
}
