:root { --ui-font-scale: 1; }
:root[data-font-size="90"] { --ui-font-scale: .9; }
:root[data-font-size="110"] { --ui-font-scale: 1.1; }
:root[data-font-size="120"] { --ui-font-scale: 1.2; }

:root[data-theme="sage"] { --navy:#182d36; --green:#196b59; --green-dark:#105444; --mint:#e4f0e9; --ink:#243d45; --muted:#495c59; --border:#cbd8cf; --bg:#f5f7f5; }
:root[data-theme="ocean"] { --navy:#16364a; --green:#287ca2; --green-dark:#1d617f; --mint:#eaf4f9; --ink:#263d4b; --muted:#4b6270; --border:#c8d8e1; --bg:#f3f7fa; }
:root[data-theme="violet"] { --navy:#332d48; --green:#7057a6; --green-dark:#594287; --mint:#f1edfa; --ink:#373348; --muted:#5a526b; --border:#d4cce4; --bg:#f7f5fa; }
:root[data-theme="sand"] { --navy:#49382d; --green:#a46c35; --green-dark:#805126; --mint:#f8f0e5; --ink:#45392f; --muted:#655548; --border:#dfd0bc; --bg:#faf7f2; }
:root[data-theme="vivid-blue"] { --navy:#102b58; --green:#1769e0; --green-dark:#0b4aa2; --mint:#eaf2ff; --ink:#14213d; --muted:#35445f; --border:#bdcff0; --bg:#f3f7ff; }
:root[data-theme="vivid-green"] { --navy:#073b31; --green:#00845f; --green-dark:#006347; --mint:#e2f8f0; --ink:#102c26; --muted:#31534a; --border:#acdcca; --bg:#f1fcf7; }
:root[data-theme="vivid-orange"] { --navy:#582600; --green:#e65300; --green-dark:#a93e00; --mint:#fff0e6; --ink:#321a0b; --muted:#60402f; --border:#efc5a7; --bg:#fff8f3; }
:root[data-theme="vivid-purple"] { --navy:#3d125e; --green:#a327c9; --green-dark:#79189e; --mint:#f7eaff; --ink:#291338; --muted:#513a61; --border:#ddc1e9; --bg:#fcf7ff; }
:root[data-theme="portal"] { --navy:#202428; --green:#1760ad; --green-dark:#104783; --mint:#e9edf2; --ink:#233348; --muted:#4b5c70; --border:#c7cfda; --bg:#f4f5f7; --portal-active:#dfeafa; }

:root[data-theme] body { background-color:var(--bg); color:var(--ink); }
:root[data-theme] .sidebar { background-color:var(--navy); }
:root[data-theme] .brand-icon { background:color-mix(in srgb,var(--green) 38%,var(--navy)); border-color:color-mix(in srgb,var(--green) 56%,var(--navy)); }
:root[data-theme] .nav-item.active,
:root[data-theme] .nav-item:hover { background:color-mix(in srgb,var(--green) 28%,var(--navy)); }
:root[data-theme] .summary.active { background:color-mix(in srgb,var(--green) 8%,white); border-color:color-mix(in srgb,var(--green) 28%,white); }
:root[data-theme] .settlement-heading,
:root[data-theme] .business-table thead th,
:root[data-theme] .result-table thead th,
:root[data-theme] #document-review-table th,
:root[data-theme] #document-input-table thead th { background:color-mix(in srgb,var(--green) 10%,white); }
:root[data-theme] button:focus-visible,
:root[data-theme] input:focus-visible,
:root[data-theme] select:focus-visible,
:root[data-theme] summary:focus-visible { outline-color:var(--green); }

/* Keep utility-calculator colors vivid while preserving dark, legible text. */
:root[data-theme] .utility-fields label,
:root[data-theme] .utility-guidance,
:root[data-theme] .guidance-card,
:root[data-theme] .guidance-card p,
:root[data-theme] .guidance-card li,
:root[data-theme] .guidance-footer { color:var(--ink); }
:root[data-theme] .utility-fields select,
:root[data-theme] .input-unit { border-color:var(--border); background:#fff; color:var(--ink); }
:root[data-theme] .input-unit input { color:var(--ink); }
:root[data-theme] .input-unit:focus-within { border-color:var(--green); box-shadow:0 0 0 3px color-mix(in srgb,var(--green) 16%,transparent); }
:root[data-theme] .charge-card { border-color:var(--border); background:color-mix(in srgb,var(--green) 9%,white); }
:root[data-theme] .charge-label,
:root[data-theme] .charge-amount,
:root[data-theme] .charge-meta strong,
:root[data-theme] .classification strong,
:root[data-theme] .utility-results td:last-child { color:var(--green-dark); }
:root[data-theme] .charge-label>span,
:root[data-theme] .charge-amount small,
:root[data-theme] .charge-meta,
:root[data-theme] .charge-formula,
:root[data-theme] .charge-help,
:root[data-theme] .classification span,
:root[data-theme] .classification p,
:root[data-theme] .utility-results td:nth-child(2) { color:var(--muted); }
:root[data-theme] .utility-results .subtotal th,
:root[data-theme] .utility-results .subtotal td,
:root[data-theme] .utility-results .total th,
:root[data-theme] .utility-results .total td { background:color-mix(in srgb,var(--green) 8%,white); border-color:var(--border); }
:root[data-theme] .utility-reference .selected { background:color-mix(in srgb,var(--green) 14%,white); color:var(--green-dark); }
:root[data-theme] .guidance-card { border-color:var(--border); background:color-mix(in srgb,var(--green) 4%,white); }
:root[data-theme] .guidance-card h3 { color:var(--green-dark); }
:root[data-theme] .guidance-callout { border-color:color-mix(in srgb,var(--green) 26%,white); background:color-mix(in srgb,var(--green) 10%,white); }
:root[data-theme] .guidance-pdf-link { border-color:var(--green); color:var(--green-dark); }
:root[data-theme] .heading-buttons .primary,
:root[data-theme] .dialog-footer .primary { border-color:var(--green-dark); background:var(--green-dark); color:#fff; }

/* Crisp, square-cornered office-portal palette inspired by the supplied reference. */
:root[data-theme="portal"] :is(.panel,.summary,.charge-card,.classification,.guidance-card,.input-unit,button,.button,select,dialog,.ui-preferences-dialog,.summary,.badge,.source-tag) { border-radius:2px !important; box-shadow:none; }
:root[data-theme="portal"] .panel { border-color:var(--border); background:#fff; }
:root[data-theme="portal"] .panel-head { background:#e9edf2; border-bottom-color:#c7cfda; }
:root[data-theme="portal"] .panel-head h2,
:root[data-theme="portal"] .panel-title,
:root[data-theme="portal"] .heading h1,
:root[data-theme="portal"] .summary-label { color:#20344e; }
:root[data-theme="portal"] .heading p,
:root[data-theme="portal"] .breadcrumbs,
:root[data-theme="portal"] .topbar { color:#35465a; }
:root[data-theme="portal"] .topbar { background:#fff; border-bottom-color:var(--border); }
:root[data-theme="portal"] .summary { border-color:var(--border); background:#fff; }
:root[data-theme="portal"] .summary.active { border-color:#9db8dc; background:#eef4fc; }
:root[data-theme="portal"] .sheet-tools,
:root[data-theme="portal"] .calculation-flow { background:#f0f2f5; border-color:var(--border); color:var(--ink); }
:root[data-theme="portal"] .sheet-formula-bar { background:#fff; border-color:var(--border); }
:root[data-theme="portal"] .sheet-formula-bar strong,
:root[data-theme="portal"] .sheet-formula-bar>span { color:var(--ink); }
:root[data-theme="portal"] .business-table thead th,
:root[data-theme="portal"] .result-table thead th,
:root[data-theme="portal"] #document-review-table th,
:root[data-theme="portal"] #document-input-table thead th,
:root[data-theme="portal"] .utility-results thead th,
:root[data-theme="portal"] .utility-reference thead th { background:#e9edf2; color:#24364d; border-color:#c7cfda; }
:root[data-theme="portal"] .business-table,
:root[data-theme="portal"] .result-table,
:root[data-theme="portal"] .business-table th,
:root[data-theme="portal"] .business-table td,
:root[data-theme="portal"] .result-table th,
:root[data-theme="portal"] .result-table td { border-color:#d1d8e1; }
:root[data-theme="portal"] .business-table td[data-row-amount],
:root[data-theme="portal"] .business-table td.formula-cell,
:root[data-theme="portal"] .result-table td.formula-cell { background:#edf2f8 !important; color:#173f70; }
:root[data-theme="portal"] .result-table .subtotal td { background:#e9edf2; color:#24364d; }
:root[data-theme="portal"] .result-table .total td { background:#dce6f2; color:#173f70; }
:root[data-theme="portal"] .charge-card { border-color:var(--border); background:#fff; }
:root[data-theme="portal"] .guidance-card { background:#fff; }
:root[data-theme="portal"] .guidance-callout { background:#edf3fb; }
:root[data-theme="portal"] .classification { background:#fff; }
:root[data-theme="portal"] .utility-results .subtotal th,
:root[data-theme="portal"] .utility-results .subtotal td,
:root[data-theme="portal"] .utility-results .total th,
:root[data-theme="portal"] .utility-results .total td { background:#edf2f8; color:#173f70; }
:root[data-theme="portal"] .utility-reference .selected { background:#dfeafa; color:#104783; }
:root[data-theme="portal"] .input-unit,
:root[data-theme="portal"] .utility-fields select,
:root[data-theme="portal"] .business-table input,
:root[data-theme="portal"] .business-table td select { border-color:#b9c7d8; border-radius:2px; background:#fff; color:#233348; }
:root[data-theme="portal"] button:hover,
:root[data-theme="portal"] .button:hover { background:#e9eff7; }
:root[data-theme="portal"] .primary:hover { background:#0e4c8f; color:#fff; }
:root[data-theme="portal"] .ui-preferences-dialog header { background:#e9edf2; }
:root[data-theme="portal"] .ui-preferences-dialog footer,
:root[data-theme="portal"] .dialog-footer { background:#f1f3f6; }
:root[data-theme="portal"] #cost-sheet { border-color:#c7cfda; }
:root[data-theme="portal"] #cost-sheet th,
:root[data-theme="portal"] #cost-sheet td { border-color:#d1d8e1; }
:root[data-theme="portal"] #cost-sheet thead th,
:root[data-theme="portal"] #cost-sheet thead .sheet-corner,
:root[data-theme="portal"] #cost-sheet thead th:last-child,
:root[data-theme="portal"] #cost-sheet thead .settlement-heading,
:root[data-theme="portal"] #cost-sheet thead th.is-active-column { background:#e9edf2; color:#24364d; box-shadow:none; }
:root[data-theme="portal"] #cost-sheet tbody th { background:#fff; color:#233348; }
:root[data-theme="portal"] #cost-sheet .sheet-row-number { background:#f0f2f5; color:#35465a; }
:root[data-theme="portal"] #cost-sheet .sheet-major,
:root[data-theme="portal"] #cost-sheet .sheet-category { background:#edf0f4; color:#34465c; }
:root[data-theme="portal"] #cost-sheet .sheet-item,
:root[data-theme="portal"] #cost-sheet .sheet-wide-item { background:#fff; box-shadow:1px 0 0 #c7cfda; }
:root[data-theme="portal"] #cost-sheet td { color:#26384e; }
:root[data-theme="portal"] #cost-sheet td.settlement-cell { background:#f7f9fc; }
:root[data-theme="portal"] #cost-sheet td.sheet-editable { background:#fff6d9; }
:root[data-theme="portal"] #cost-sheet td.sheet-editable:focus-within { box-shadow:inset 0 0 0 2px #1760ad; background:#fff0c4; }
:root[data-theme="portal"] #cost-sheet tr.subtotal td,
:root[data-theme="portal"] #cost-sheet tr.subtotal .sheet-item,
:root[data-theme="portal"] #cost-sheet tr.subtotal .sheet-wide-item { background:#edf1f5; color:#233348; }
:root[data-theme="portal"] #cost-sheet tr.total td,
:root[data-theme="portal"] #cost-sheet tr.total .sheet-wide-item { background:#dfe7f0; color:#173f70; border-color:#9fb2c9; }
:root[data-theme="portal"] #cost-sheet tr.is-active-row .sheet-item,
:root[data-theme="portal"] #cost-sheet tr.is-active-row .sheet-wide-item,
:root[data-theme="portal"] #cost-sheet tr.is-active-row .sheet-row-number,
:root[data-theme="portal"] #cost-sheet td.is-active-column:not(.sheet-editable) { background:#e6eef9; color:#173f70; }

/* Improve contrast of pale green helper text without changing its typography. */
:root[data-theme] :is(
  .sheet-rate-rule,.sheet-shortcuts,.sheet-format-hint,.rate-hint,.column-sub,.linked-rate,.mode-note,.rate-print,.inline-rate,
  .expense-help-eyebrow,.expense-help-body,.expense-help-body h4,.expense-help-source,.expense-help-foot,
  .project-meta,.settings p,.settings summary span,.scroll-hint,.calculation-flow b,.rates-grid .linked,.helper-note,.condition-results span,
  .utility-fields small,.input-unit span,.field-hint,.panel-note,.source-tag,.utility-print-basis,.charge-meta,.charge-help,.classification span,.classification p,.utility-results th[scope=row],.utility-results th small,.utility-results td:nth-child(2),.usage-content>span,
  .document-intro,.document-picker .document-local-note,#document-review-table small,
  .document-force-ocr,.document-source-details,#document-import-dialog .dialog-footer span,
  .document-check-strip .document-counts,
  #cost-sheet .sheet-row-number,.business-table td small,.business-table th small,
  .result-table td small,.result-table th small
) { color:#111111 !important; }

.ui-sidebar-toggle { width:100%; justify-content:flex-start; margin:0 0 22px; padding:9px 12px; color:#d3dedc; background:transparent; border-color:#ffffff25; }
.ui-sidebar-toggle:hover { color:#fff; background:#ffffff12; }
.ui-sidebar-toggle svg,.ui-preferences-button svg { width:17px; height:17px; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
.ui-preferences-button { order:4; }
.ui-preferences-dialog { width:min(440px,calc(100% - 32px)); padding:0; border:1px solid var(--border); border-radius:14px; color:var(--ink); background:#fff; box-shadow:0 24px 70px #142c3033; }
.ui-preferences-dialog::backdrop { background:#152d3960; backdrop-filter:blur(3px); }
.ui-preferences-dialog form { margin:0; }
.ui-preferences-dialog header,.ui-preferences-dialog footer { display:flex; align-items:center; justify-content:space-between; padding:17px 20px; }
.ui-preferences-dialog header { border-bottom:1px solid var(--border); }
.ui-preferences-dialog h2 { margin:0; font-size:calc(18px * var(--ui-font-scale, 1)); }
.ui-preferences-dialog .ui-close { padding:2px 8px; font-size:calc(21px * var(--ui-font-scale, 1)); }
.ui-preferences-fields { display:grid; gap:16px; padding:20px; }
.ui-preferences-fields label { display:grid; gap:7px; font-size:calc(13px * var(--ui-font-scale, 1)); font-weight:650; }
.ui-preferences-fields select { width:100%; padding:10px 12px; border:1px solid var(--border); border-radius:7px; background:#fff; color:var(--ink); font:inherit; }
.ui-preferences-dialog p { margin:0; padding:0 20px 17px; color:var(--muted); font-size:calc(12px * var(--ui-font-scale, 1)); line-height:1.7; }
.ui-preferences-dialog footer { justify-content:flex-end; border-top:1px solid var(--border); background:var(--bg); }

:root[data-sidebar-collapsed="true"] .sidebar { width:72px; padding:16px 8px 18px; }
:root[data-sidebar-collapsed="true"] .main { width:calc(100% - 72px); margin-left:72px; }
.sidebar { transition:width 280ms cubic-bezier(.22,.61,.36,1), padding 280ms cubic-bezier(.22,.61,.36,1); }
.main { transition:width 280ms cubic-bezier(.22,.61,.36,1), margin-left 280ms cubic-bezier(.22,.61,.36,1); }
:root[data-sidebar-collapsed="true"] .ui-sidebar-toggle { justify-content:center; padding:9px 7px; }
:root[data-sidebar-collapsed="true"] .ui-sidebar-toggle span,
:root[data-sidebar-collapsed="true"] .sidebar .brand-text,
:root[data-sidebar-collapsed="true"] .sidebar .brand-sub,
:root[data-sidebar-collapsed="true"] .sidebar .nav-caption,
:root[data-sidebar-collapsed="true"] .sidebar .nav-label,
:root[data-sidebar-collapsed="true"] .sidebar .nav-dot,
:root[data-sidebar-collapsed="true"] .sidebar .local-card,
:root[data-sidebar-collapsed="true"] .sidebar .version { display:none; }
:root[data-sidebar-collapsed="true"] .sidebar .brand { justify-content:center; padding:0; }
:root[data-sidebar-collapsed="true"] .sidebar nav { margin-top:26px; }
:root[data-sidebar-collapsed="true"] .sidebar .nav-item { justify-content:center; padding:13px 8px; }

@media (max-width:800px) {
  .ui-sidebar-toggle { justify-content:center; padding:9px 6px; }
  .ui-sidebar-toggle span { display:none; }
  .ui-sidebar-toggle { margin-bottom:16px; }
}

@media (prefers-reduced-motion:reduce) {
  .sidebar,.main { transition-duration:1ms; }
}
