/* Shared screen foundations. Workspace-specific geometry and printable documents
   keep their own styles; these tokens are the reference for new interface work. */
@media screen {
  :root {
    --ui-canvas: #242424;
    --ui-surface: #2b3035;
    --ui-surface-raised: #30373e;
    --ui-field: #23292e;
    --ui-line: #434d56;
    --ui-line-subtle: #ffffff12;
    --ui-text: #e4eaf0;
    --ui-text-secondary: #bdc8d2;
    --ui-text-muted: #a6b4c0;
    --ui-accent: #8cc8ff;
    --ui-action: #1973d1;
    --ui-action-hover: #2784e5;
    --ui-selected: #2d4356;
    --ui-success: #a6d7bb;
    --ui-warning: #efc08e;
    --ui-danger: #ffb0a7;
    --ui-focus: #aad8ff;
    --ui-radius-control: 7px;
    --ui-radius-panel: 12px;
    --ui-space-1: 4px;
    --ui-space-2: 8px;
    --ui-space-3: 12px;
    --ui-space-4: 16px;
    --ui-space-5: 24px;
    --ui-space-6: 32px;
    --ui-type-body: 14px;
    --ui-type-label: 13px;
    --ui-type-help: 12px;
    --ink: var(--ui-text);
    --muted: var(--ui-text-muted);
    --paper: var(--ui-canvas);
    --white: var(--ui-surface);
    --line: var(--ui-line);
  }

  html, body { background: var(--ui-canvas); }
  body { color: var(--ui-text); font-size: var(--ui-type-body); line-height: 1.55; }
  .sidebar { background: var(--ui-canvas); }
  .workspace > .topbar { background: var(--ui-canvas); }
  .topbar .breadcrumb { display: flex; align-items: center; min-width: 0; }
  .topbar .breadcrumb #page-group { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ui-text-muted); }
  .topbar .breadcrumb .breadcrumb-separator { flex: none; }
  .topbar .breadcrumb #page-title { flex: none; white-space: nowrap; }
  .topbar .top-actions { flex-shrink: 0; }
  .workspace .card { background: var(--ui-surface); border-color: var(--ui-line); box-shadow: none; }
  .workspace > main > .page-heading { margin-bottom: 20px; }
  .page-heading h1 { font-size: 24px; line-height: 1.3; letter-spacing: -.3px; font-weight: 600; }
  #page-description { font-size: 13px; line-height: 1.65; color: var(--ui-text-secondary); margin-top: 9px; }
  #page-description:empty { display: none; }

  /* Preserve each workspace's compact controls, hit areas and component sizing. */
  .primary { background: var(--ui-action); box-shadow: none; }
  .primary:hover:not(:disabled) { background: var(--ui-action-hover); }
  .secondary { background: var(--ui-surface-raised); color: var(--ui-text); border-color: var(--ui-line); border-radius: var(--ui-radius-control); box-shadow: none; }
  .secondary:hover:not(:disabled) { background: #3a444d; border-color: #647583; }
  .text-button { color: var(--ui-accent); }
  .text-button:hover:not(:disabled) { color: #c9e6ff; }
  .primary:disabled, .secondary:disabled {
    opacity: 1;
    color: #94a2ae;
    background: #30363b;
    border-color: #444d55;
    box-shadow: none;
    cursor: not-allowed;
  }
  .text-button:disabled { opacity: 1; color: #94a2ae; cursor: not-allowed; }
  button:disabled, input:disabled, select:disabled { cursor: not-allowed; }
  button[aria-busy=true]:disabled { cursor: progress; }
  :is(button, a, input, select, summary):focus-visible {
    outline: 2px solid var(--ui-focus);
    outline-offset: 3px;
  }
  :where(input, select):disabled { opacity: 1; color: #94a2ae; -webkit-text-fill-color: #94a2ae; }
  :where(input, select)[readonly] { color: var(--ui-text-secondary); }

  /* These common form rules exclude drawing workspaces and report previews.
     More specific component rules remain responsible for dense tables/editors. */
  :where(#view:not(:has(.floor-plan, .report-preview))) .hint,
  :where(#view:not(:has(.floor-plan, .report-preview))) .note,
  :where(#view:not(:has(.floor-plan, .report-preview))) .card-head p {
    font-size: var(--ui-type-help);
    color: var(--ui-text-secondary);
    line-height: 1.7;
  }
  :where(#view:not(:has(.floor-plan, .report-preview))) .fields > label { font-size: var(--ui-type-help); }
  :where(#view:not(:has(.floor-plan, .report-preview))) .fields > label > .unit { font-size: 11px; color: var(--ui-text-muted); }
  :where(#view:not(:has(.floor-plan, .report-preview))) .fields :is(input:not([type=checkbox], [type=range]), select) {
    border-color: #596773;
    color: var(--ui-text);
    background: var(--ui-field);
  }
  :where(#view:not(:has(.floor-plan, .report-preview))) .fields :is(input:not([type=checkbox], [type=range]), select):focus {
    border-color: var(--ui-accent);
    box-shadow: none;
  }
  :where(#view:not(:has(.floor-plan, .report-preview))) .fields input:invalid { border-color: var(--ui-danger); }
  :where(#view:not(:has(.floor-plan, .report-preview))) .fields :is(input, select):disabled { color: #94a2ae; }
}
@media screen and (max-width: 700px) {
  .topbar .breadcrumb { display: none; }
  .page-heading h1 { font-size: 22px; }
  .workspace > main > .page-heading { margin-bottom: 16px; }
}

/* Compact engineering workspaces: shared legibility without changing drawings
   or the white report document. Page-specific structure remains in its owner. */
@media screen {
  #view[data-page] { min-width: 0; }
  #view[data-page] :is(input[type=number], .metric strong, .mini-kpi strong) { font-variant-numeric: tabular-nums; }
  #view[data-page] input::placeholder { color: var(--ui-text-muted); opacity: 1; }
  #view[data-page] .card-head { gap: 12px; }

  /* Rooms: readable construction and gain controls; preserve canvas geometry. */
  #view[data-page=rooms] .rooms-layout :is(label, .hint, [data-activity-summary], .room-gain-detail-body>.hint:first-child) { font-size: 12px; }
  #view[data-page=rooms] .rooms-layout label .unit { font-size: 11px; color: var(--ui-text-secondary); }
  #view[data-page=rooms] .facade-card>summary { gap: 10px; }
  #view[data-page=rooms] .facade-card>summary small { font-size: 12px; justify-content: flex-start; text-align: left; }
  #view[data-page=rooms] .facade-wall-summary { font-size: 12px; }
  #view[data-page=rooms] .room-gain-detail-body :is(input, select) { font-size: 13px; }
  .fp-inspector :is(.fp-size-fields label, .fp-wall-fields label, .fp-search label) { font-size: 12px; }
  .fp-size-fields .fp-size-label { overflow: visible; }
  .fp-size-fields .fp-size-label small { display: block; font-size: 10px; line-height: 1.5; font-weight: 400; color: var(--ui-text-secondary); }
  .fp-inspector :is(.hint, .fp-boundaries small, .fp-shared-link small) { font-size: 12px; line-height: 1.6; }
  .fp-inspector :is(input, select, button, summary) { scroll-margin-block: 116px 104px; }
  .fp-inspector { scroll-padding-bottom: 104px; }
  .floor-plan :is(.fp-heading p, .fp-active-readout span, .fp-legend, .fp-layout-note) { font-size: 12px; }
  .floor-plan .fp-room-key button { font-size: 12px; }

  /* Overview: scan statuses by their words, with room names kept intact. */
  .room-status .rs-room-name small, .room-status .rs-quick-check>b { font-size: 12px; }
  .room-status .rs-room-name small { max-width: none; overflow-wrap: anywhere; }
  .room-status .rs-room-navigation button { min-height: 36px; }
  .room-status .rs-finding :is(p, li) { max-width: 76ch; }
  .overview-brief-scope, .overview-design-details .design-summary p { font-size: 12px; }

  /* Selection: ordinary sentence case and a more readable room navigator. */
  .selection-active-position { text-transform: none; letter-spacing: 0; font-size: 12px; }
  .selection-room-link strong { font-size: 13px; }
  .selection-room-link small { font-size: 12px; line-height: 1.5; }
  .selection-workspace .selection-room-head { margin-bottom: 16px; }
  .selection-workspace .selection-room-title>.selection-room-swatch { margin-top: 22px; }
  .selection-comparison .selection-compare-column h3 { font-size: 13px; }
  .selection-workspace :is(.selection-generic-help .hint, .equipment-data-help dd, .equipment-missing-inputs) { font-size: 12px; max-width: 76ch; }

  /* Weather and analysis: labels read as labels, not miniature chart ticks. */
  #view[data-page=climate] .mini-kpi small { font-size: 12px; }
  #view[data-page=climate] :is(.tag, .chart-legend) { font-size: 11px; }
  #view[data-page=climate] .note { max-width: 78ch; }
  #view[data-page=analysis] :is(.analysis-toolbar label, .analysis-toolbar select, .metric p, .metric>span, .room-comparison label) { font-size: 12px; }
  #view[data-page=analysis] .metric>span { text-transform: none; letter-spacing: 0; }
  #view[data-page=analysis] .analysis-toolbar { gap: 12px; align-items: end; flex-wrap: wrap; }
  #analysis-psychrometrics .psych-shr-panel { border: 0; border-block: 1px solid var(--ui-line); border-radius: 0; background: transparent; padding: 18px 0; margin: 20px 0; }
  #analysis-psychrometrics .psych-shr-values { gap: 0; }
  #analysis-psychrometrics .psych-shr-value { border: 0; border-radius: 0; background: transparent; padding: 0 18px 0 0; }
  #analysis-psychrometrics .psych-shr-value:nth-child(even) { border-left: 1px solid var(--ui-line); padding: 0 0 0 18px; }
  #analysis-psychrometrics .psych-shr-value:nth-child(n+3) { margin-top: 18px; }
  #analysis-psychrometrics .psych-shr-value>strong { color: var(--ui-text); }
  #analysis-psychrometrics .psych-shr-value small { font-size: 12px; color: var(--ui-text-secondary); }

  /* Airflow: keep the drawing and its node geometry; make toolbar groups wrap. */
  #view[data-page=airflow] .network-tools { gap: 10px; }
  #view[data-page=airflow] .network-tools button { font-size: 12px; min-height: 36px; }
  #view[data-page=airflow] .network-inspector :is(label, .hint, p),
  #view[data-page=airflow] :is(.pressure-controls label, .ventilation-report label) { font-size: 12px; }

  /* Plant and annual: consistent units, aligned controls and restrained KPIs. */
  #view[data-page=plant] :is(.plant-chart-controls>label, .plant-chart-scrubber label, .plant-day-controls label, .plant-study-controls label, .plant-day-summary small) { font-size: 12px; }
  #view[data-page=plant] :is(.plant-chart-reading small, .plant-chart-readout-head small, .plant-chart-help) { font-size: 12px; }
  #view[data-page=plant] .plant-chart-reading { align-items: baseline; }
  #view[data-page=annual] .annual-kpis { gap: 0; border-block: 1px solid var(--ui-line); }
  #view[data-page=annual] .annual-kpis>div { border: 0; border-radius: 0; background: transparent; padding: 16px; }
  #view[data-page=annual] .annual-kpis>div+div { border-left: 1px solid var(--ui-line); }
  #view[data-page=annual] .annual-kpis small { font-size: 12px; }
  #view[data-page=annual] .annual-kpis strong { color: var(--ui-text); font-variant-numeric: tabular-nums; }
  #view[data-page=annual] .annual-action-main p { max-width: 75ch; }

  /* Report chrome only. Printable sheet colors, typography and pagination stay
     owned by report.css and must not inherit dark workspace form styles. */
  #view[data-page=report] .report-toolbar { flex-direction: column; gap: 12px; align-items: stretch; }
  #view[data-page=report] .report-export-actions { display:flex; flex-wrap:wrap; gap:10px; align-items:center; }
  #view[data-page=report] .report-toolbar :is(label, button, select) { font-size: 12px; }
  #view[data-page=report] .report-options { gap: 8px 20px; line-height: 1.6; }

  /* References: show the selected category and make source records readable. */
  #view[data-page=library] .library-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
  #view[data-page=library] .library-tabs button { font-size: 12px; min-height: 36px; padding: 8px 12px; }
  #view[data-page=library] .library-tabs [aria-pressed=true] { color: var(--ui-text); background: var(--ui-selected); border-color: #7893a8; }
  #view[data-page=library] :is(.construction-result-count, .construction-record-toggle, .construction-source>a, .construction-source-empty, .construction-record p, .construction-library-note) { font-size: 12px; }
  #view[data-page=library] :is(.construction-record-toggle small, .construction-basis) { font-size: 11px; white-space: normal; }
  #view[data-page=library] .construction-record { border: 0; border-left: 2px solid var(--ui-line); border-radius: 0; background: transparent; }
  #view[data-page=library] .source-card { max-width: 78ch; }

  /* Methods: bounded reading measure and visible shortcuts to real headings. */
  #view[data-page=about] section :is(p, li) { max-width: 76ch; line-height: 1.75; }
  #view .about-topic-index { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; overflow: visible; padding: 0 0 18px; margin: 0; }
  #view .about-topic-index strong { color: var(--ui-text-secondary); font-size: 12px; flex-basis: 100%; }
  #view .about-topic-index button { display: inline-flex; text-align: left; font-size: 12px; min-height: 32px; padding: 5px 0; border: 0; background: transparent; line-height: 1.5; white-space: normal; }
  #view .about-topic-index button:before { content: none; }
  #view[data-page=about] h2[id] { scroll-margin-top: calc(var(--toolbar-height,60px) + 24px); }
  #view[data-page=about] h2[id]:focus { outline: 2px solid var(--ui-focus); outline-offset: 5px; }
}
@media screen and (min-width: 1100px) {
  #view[data-page=about] { display: grid; grid-template-columns: minmax(0,76ch) minmax(180px,1fr); gap: 24px; align-items: start; }
  #view[data-page=about]>section { grid-column: 1; margin: 0; }
  #view[data-page=about] .about-topic-index { grid-column: 2; position: sticky; top: calc(var(--toolbar-height,60px) + 20px); flex-direction: column; align-items: flex-start; gap: 8px; padding-left: 8px; }
  #view[data-page=about] .about-topic-index strong { flex-basis: auto; }
}
@media screen and (max-width: 700px) {
  #view[data-page]:not([data-page=report]) .fields :is(input:not([type=checkbox], [type=range]), select),
  #view[data-page=library] .construction-filters input,
  #view[data-page=rooms] .room-gain-detail-body :is(input, select) { font-size: 16px; min-height: 44px; }
  #view[data-page=climate] .mini-kpi { flex-wrap: wrap; gap: 16px 24px; }
  #view[data-page=airflow] .network-tools button { min-height: 40px; }
  #analysis-psychrometrics .psych-shr-value { padding: 0; }
  #analysis-psychrometrics .psych-shr-value:nth-child(even) { border-left: 0; border-top: 1px solid var(--ui-line-subtle); padding: 14px 0 0; margin-top: 14px; }
  .floor-plan .fp-legend { font-size: 11px; }
  .room-status .rs-quick-check>span, .room-status .rs-room-name small { font-size: 11px; }
  .room-status .rs-quick-check>b { font-size: 11px; }
  #view[data-page=annual] .annual-kpis>div { padding: 12px 8px; }
  #view[data-page=annual] .annual-kpis strong { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  #view[data-page] *, .fp-room-sheet * { scroll-behavior: auto!important; transition-duration: 0s!important; animation-duration: 0s!important; }
}
@media print { .about-topic-index { display: none!important; } }
