/* Presentation-only adapters for the existing modules.
 * Central --ui-* tokens are defined in design.css. No scheduling, permissions,
 * visibility, employee palette, table width or data-entry behavior is changed.
 * Screen layouts plus narrowly scoped print colours; print/export geometry stays unchanged.
 */
@media screen {
  :root[data-theme] body[data-ui-module="planner"],
  :root[data-theme] body[data-ui-module="overview"],
  :root[data-theme] body[data-ui-module="diary"],
  :root[data-theme] body[data-ui-module="finder"] {
    color: var(--ui-text);
    background: var(--ui-bg);
    font-size: 1rem;
    line-height: 1.5;
  }

  /* Call / driving planners: retain all column sizes and sticky offsets. */
  :root[data-theme] body[data-ui-module="planner"] :is(.app-header, .table-shell, .metric-card, .employee-summary > div, .password-card, .portal-lock),
  :root[data-theme] body[data-ui-module="overview"] :is(.table-shell, .legend, .empty, .mobile-plan-card) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-border);
    box-shadow: none;
  }
  :root[data-theme] body[data-ui-module="planner"] .tabs {
    background: var(--ui-bg);
    border-color: var(--ui-border);
  }
  :root[data-theme] body[data-ui-module="overview"] :is(button, .button-link) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="overview"] :is(button, .button-link):hover {
    color: var(--ui-text);
    background: var(--ui-hover);
    border-color: var(--ui-focus);
  }
  :root[data-theme] body[data-ui-module="planner"] .tab {
    background: var(--ui-raised);
    color: var(--ui-text);
    border-color: var(--ui-control-border);
    font-size: .875rem;
  }
  :root[data-theme] body[data-ui-module="planner"] .tab.active {
    background: var(--ui-surface);
    border-bottom-color: var(--ui-surface);
    box-shadow: inset 0 3px var(--ui-focus);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(label, .metric-label, .employee-summary span, .employee-summary small, .portal-save-status, .locked-label, .availability-slot strong, .employee-office-entry span, .editable-label),
  :root[data-theme] body[data-ui-module="overview"] :is(label, .legend, .eyebrow, .subline, .office-cover-readonly span, .office-cover-readonly small, .mobile-plan-title small, .mobile-shift-label small) {
    font-size: .875rem;
    line-height: 1.45;
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.metric-label, .employee-summary span, .employee-summary small, .muted-cell, .empty-state),
  :root[data-theme] body[data-ui-module="overview"] :is(.subline, .legend, .empty, .office-cover-readonly span, .office-cover-readonly small, .mobile-plan-title small, .mobile-shift-label small) {
    color: var(--ui-muted);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.table-shell th, .table-shell td),
  :root[data-theme] body[data-ui-module="overview"] :is(.table-shell th, .table-shell td) {
    color: var(--ui-text);
    border-color: var(--ui-border);
    font-size: .875rem;
    line-height: 1.4;
  }
  :root[data-theme] body[data-ui-module="planner"] .table-shell th,
  :root[data-theme] body[data-ui-module="overview"] .table-shell th {
    color: var(--ui-text);
    background: var(--ui-raised);
    white-space: normal;
  }
  :root[data-theme] body[data-ui-module="planner"] .table-shell :is(input, select, button),
  :root[data-theme] body[data-ui-module="overview"] .table-shell :is(input, select, button) {
    font-size: .875rem;
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.office-cover-card, .availability-slot, .row-action-menu-panel, .mobile-shift-row),
  :root[data-theme] body[data-ui-module="overview"] .mobile-shift-row {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.office-cover-card:hover, .office-cover-add:hover, .row-action-trigger:hover) {
    background: var(--ui-hover);
    border-color: var(--ui-focus);
  }
  :root[data-theme] body[data-ui-module="planner"] .office-cover-card small {
    color: var(--ui-muted);
    font-size: .875rem;
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.status-pill, .mini-btn, .toggle),
  :root[data-theme] body[data-ui-module="overview"] .mobile-status {
    font-size: .875rem;
    line-height: 1.4;
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.status-ok, .toggle.on),
  :root[data-theme] body[data-ui-module="overview"] .mobile-status.is-ok {
    color: var(--ui-success-text);
    background: var(--ui-success-bg);
    border-color: var(--ui-success-border);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.status-check, .portal-save-status.is-pending, .warning-item) {
    color: var(--ui-warning-text);
    background: var(--ui-warning-bg);
    border-color: var(--ui-warning-border);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.status-open, .toggle.off, .portal-save-status.is-error),
  :root[data-theme] body[data-ui-module="overview"] .mobile-status.is-open {
    color: var(--ui-danger-text);
    background: var(--ui-danger-bg);
    border-color: var(--ui-danger-border);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.locked-label, .locked-availability-row, .shift-select:disabled, .toggle:disabled) {
    color: var(--ui-muted);
    background: var(--ui-raised);
    border-color: var(--ui-control-border);
    opacity: 1;
  }
  /* Only reserved status values override inline colours, never employee identity. */
  :root[data-theme] body[data-ui-module="planner"] .shift-select:has(option[value="OFFEN"]:checked) {
    background-color: var(--ui-danger-bg) !important;
    color: var(--ui-danger-text) !important;
    border-color: var(--ui-danger-border);
  }
  :root[data-theme] body[data-ui-module="planner"] .assignment-wrap:has(.shift-select option[value="OFFEN"]:checked) > .color-dot {
    background: var(--ui-danger-border) !important;
  }
  :root[data-theme] body[data-ui-module="planner"] .shift-select:has(option[value="GESPERRT"]:checked) {
    background-color: var(--ui-neutral-bg) !important;
    color: var(--ui-neutral-text) !important;
    border-color: var(--ui-neutral-border);
  }
  :root[data-theme] body[data-ui-module="planner"] .assignment-wrap:has(.shift-select option[value="GESPERRT"]:checked) > .color-dot {
    background: var(--ui-neutral-border) !important;
  }
  :root[data-theme] body[data-ui-module="planner"] .employee-summary div.summary-highlight {
    color: var(--ui-info-text);
    background: var(--ui-info-bg);
  }
  :root[data-theme] body[data-ui-module="planner"] .employee-total-row td {
    background: var(--ui-raised);
    color: var(--ui-text);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.shift-mark, button.primary),
  :root[data-theme] body[data-ui-module="overview"] .primary-action {
    color: var(--ui-on-primary);
    background: var(--ui-primary);
    border-color: var(--ui-primary);
  }
  :root[data-theme] body[data-ui-module="planner"] :is(.form-error, .office-cover-error) {
    color: var(--ui-danger-text);
    font-size: .875rem;
  }
  :root[data-theme] body[data-ui-module="planner"] dialog {
    box-sizing: border-box;
    width: min(38rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    overflow: auto;
    padding: 1.25rem;
    color: var(--ui-text);
    background: var(--ui-surface);
    border: 1px solid var(--ui-control-border);
    border-radius: .75rem;
    line-height: 1.5;
  }
  :root[data-theme] body[data-ui-module="planner"] dialog :is(input, select, textarea) {
    box-sizing: border-box;
    max-width: 100%;
    min-width: 0;
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
    font-size: 1rem;
  }
  :root[data-theme] body[data-ui-module="planner"] dialog h2 {
    margin-top: 0;
    color: var(--ui-text);
    font-size: 1.25rem;
  }
  :root[data-theme] body[data-ui-module="planner"] .office-cover-calculation {
    color: var(--ui-text);
    background: var(--ui-raised);
    border-color: var(--ui-border);
  }
  :root[data-theme] body[data-ui-module="planner"] #toast {
    color: var(--ui-text);
    background: var(--ui-surface);
    border: 1px solid var(--ui-control-border);
    max-width: min(38rem, calc(100vw - 2rem));
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  /* Pinboards / diaries retain user-selected note colors and status wording. */
  :root[data-theme] body[data-ui-module="diary"] :is(.board-shell, .dashboard-main, .pinboard, .entry-form) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-border);
    box-shadow: none;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(.dashboard-main, .board-shell) {
    background: var(--ui-bg);
  }
  :root[data-theme] body[data-ui-module="diary"] .dashboard-quick-action {
    color: var(--ui-text);
    background: var(--ui-raised);
    border-color: var(--ui-control-border);
    white-space: normal;
    text-overflow: clip;
    min-height: 44px;
    font-size: .875rem;
  }
  :root[data-theme] body[data-ui-module="diary"] .dashboard-quick-action:hover {
    color: var(--ui-text);
    background: var(--ui-hover);
    border-color: var(--ui-focus);
  }
  :root[data-theme] body[data-ui-module="diary"] :is(h1, h2, .confirm-line, .todo-done-toggle strong) {
    color: var(--ui-text);
  }
  :root[data-theme] body[data-ui-module="diary"] h1 {
    font-size: clamp(1.5rem, 3vw, 2rem);
    line-height: 1.25;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(label, .subline, .form-kicker, .eyebrow, .todo-editor-head) {
    color: var(--ui-muted);
    font-size: .875rem;
    line-height: 1.5;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(input, select, textarea, option) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
    font-size: 1rem;
  }
  /* Beat legacy input:not(...) specificity without touching native checkboxes. */
  :root[data-theme] body[data-ui-module="diary"] input:not([type="checkbox"]):not([type="radio"]) {
    border-color: var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="diary"] :is(input, textarea)::placeholder {
    color: var(--ui-muted);
    opacity: 1;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(.confirm-line, .note-confirmation) {
    color: var(--ui-text);
    background: var(--ui-raised);
    border-color: var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-card {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-border);
    border-radius: .5rem;
    box-shadow: none;
    transform: none;
    overflow-wrap: anywhere;
  }
  :root[data-theme] body[data-ui-module="diary"] .note-card::before {
    background: var(--ui-control-border);
    border-color: var(--ui-surface);
    box-shadow: none;
  }
  :root[data-theme] body[data-ui-module="diary"] .note-gelb {
    color: var(--ui-warning-text);
    background: var(--ui-warning-bg);
    border-color: var(--ui-warning-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-blau {
    color: var(--ui-info-text);
    background: var(--ui-info-bg);
    border-color: var(--ui-info-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-rosa {
    color: var(--ui-rose-text);
    background: var(--ui-rose-bg);
    border-color: var(--ui-rose-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-rot {
    color: var(--ui-danger-text);
    background: var(--ui-danger-bg);
    border-color: var(--ui-danger-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-gruen {
    color: var(--ui-success-text);
    background: var(--ui-success-bg);
    border-color: var(--ui-success-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-card :is(.note-title, .note-text, .note-meta, .note-progress, .todo-progress, .note-message, .note-head strong) {
    color: inherit;
    opacity: 1;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(.note-meta, .note-deleted-meta, .note-confirmation-meta, .note-expand-toggle, .status-pill, .note-confirmed-badge, .note-confirm-button, .todo-details dt, .todo-progress) {
    font-size: .875rem;
    line-height: 1.45;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(.note-confirmation-meta, .todo-details dt, .todo-details dd, .todo-item, .note-deleted-meta) {
    color: var(--ui-text);
  }
  :root[data-theme] body[data-ui-module="diary"] :is(.note-deleted-meta, .todo-details, .todo-item, .todo-done-toggle) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-deleted {
    opacity: 1;
    filter: none;
    border-style: dashed;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(button, .button-link, .note-order-actions button, .note-actions button, .note-expand-toggle) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
    font-size: .875rem;
    box-shadow: none;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(button, .button-link):hover {
    color: var(--ui-text);
    background: var(--ui-hover);
    border-color: var(--ui-focus);
  }
  :root[data-theme] body[data-ui-module="diary"] :is(.primary, .note-confirm-button) {
    color: var(--ui-on-primary);
    background: var(--ui-primary);
    border-color: var(--ui-primary);
  }
  :root[data-theme] body[data-ui-module="diary"] button.is-active {
    color: var(--ui-text);
    background: var(--ui-selected);
    border-color: var(--ui-focus);
  }
  :root[data-theme] body[data-ui-module="diary"] .status-pill {
    color: var(--ui-text);
    background: var(--ui-surface);
    border: 1px solid var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .note-confirmed-badge {
    color: var(--ui-success-text);
    background: var(--ui-success-bg);
    border-color: var(--ui-success-border);
  }
  :root[data-theme] body[data-ui-module="diary"] .todo-remove-button {
    color: var(--ui-danger-text);
  }
  :root[data-theme] body[data-ui-module="diary"] :is(button:disabled, .todo-item.is-done span) {
    color: var(--ui-muted);
    opacity: 1;
  }

  /* Finder has an independent inline legacy palette and dynamic result cards. */
  :root[data-theme] body[data-ui-module="finder"] {
    --finder-bg: var(--ui-bg);
    --finder-card: var(--ui-surface);
    --finder-result: var(--ui-surface);
    --finder-line: var(--ui-control-border);
    --finder-text: var(--ui-text);
    --finder-title: var(--ui-text);
    --finder-muted: var(--ui-muted);
    --finder-soft: var(--ui-raised);
    --finder-primary: var(--ui-primary);
    --finder-primary-text: var(--ui-on-primary);
  }
  :root[data-theme] body[data-ui-module="finder"] :is(.card, .result) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-border);
    border-radius: .75rem;
    box-shadow: none;
  }
  :root[data-theme] body[data-ui-module="finder"] :is(h1, .name, .address) {
    color: var(--ui-text);
  }
  :root[data-theme] body[data-ui-module="finder"] h1 {
    font-size: clamp(1.5rem, 3vw, 2rem);
    line-height: 1.25;
  }
  :root[data-theme] body[data-ui-module="finder"] :is(.subtitle, .meta, .small, .status, #status) {
    color: var(--ui-muted);
    font-size: .875rem;
  }
  :root[data-theme] body[data-ui-module="finder"] input {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
    min-width: 0;
    max-width: 100%;
  }
  :root[data-theme] body[data-ui-module="finder"] button {
    color: var(--ui-on-primary);
    background: var(--ui-primary);
    filter: none;
  }
  :root[data-theme] body[data-ui-module="finder"] :is(.secondary, .back-link) {
    color: var(--ui-text);
    background: var(--ui-raised);
    border: 1px solid var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="finder"] .badge {
    color: var(--ui-info-text);
    background: var(--ui-info-bg);
    border-color: var(--ui-info-border);
    font-size: .875rem;
  }
  :root[data-theme] body[data-ui-module="finder"] .badge.good {
    color: var(--ui-success-text);
    background: var(--ui-success-bg);
    border-color: var(--ui-success-border);
  }
  :root[data-theme] body[data-ui-module="finder"] .badge.warn {
    color: var(--ui-warning-text);
    background: var(--ui-warning-bg);
    border-color: var(--ui-warning-border);
  }
  :root[data-theme] body[data-ui-module="finder"] :is(.error, .status.error, #status.error) {
    color: var(--ui-danger-text);
  }
  :root[data-theme] body[data-ui-module="finder"] a:not(.back-link) {
    color: var(--ui-link);
  }

  /* Accounting remains the familiar dense layout, with full financial content. */
  :root[data-theme] body[data-ui-module="accounting"] .accounting-main {
    --account-surface: var(--ui-surface);
    --account-raised: var(--ui-raised);
    --account-text: var(--ui-text);
    --account-muted: var(--ui-muted);
    --account-border: var(--ui-border);
    --account-field: var(--ui-surface);
    --account-disabled: var(--ui-neutral-bg);
    --account-weekend: var(--ui-warning-bg);
    --account-selected: var(--ui-selected);
    --account-on-selected: var(--ui-text);
    --account-focus: var(--ui-focus);
    --account-warning: var(--ui-warning-text);
    --account-error: var(--ui-danger-text);
    --account-value: var(--ui-success-text);
    background: var(--ui-bg);
    color: var(--ui-text);
  }
  :root[data-theme="light"] body[data-ui-module="accounting"] .accounting-main { --account-scheme: light; }
  :root[data-theme="dark"] body[data-ui-module="accounting"] .accounting-main { --account-scheme: dark; }
  :root[data-theme] body[data-ui-module="accounting"] .accounting-classic :is(.classic-tab, .classic-tools a, .classic-tools button, .accounting-filters label, .accounting-filters button, .accounting-filters input, .accounting-filters select, .accounting-period, .accounting-warning, .accounting-areas button, .accounting-table th, .accounting-table td, .accounting-table small, .classic-employee-summary span, .classic-employee-badge, .accounting-actions button) {
    font-size: .875rem;
    line-height: 1.45;
  }
  :root[data-theme] body[data-ui-module="accounting"] .accounting-main :is(.accounting-filters button, .classic-tab, .classic-tools button, .classic-tools a, .accounting-areas button) {
    min-height: 40px;
  }
  :root[data-theme] body[data-ui-module="accounting"] .accounting-main .button {
    color: var(--ui-on-primary);
    background: var(--ui-primary);
    border-color: var(--ui-primary);
  }
  :root[data-theme] body[data-ui-module="accounting"] .classic-employee-badge:not([style]) {
    color: var(--ui-text);
    background: var(--ui-raised);
    border: 1px solid var(--ui-control-border);
  }
  :root[data-theme] body[data-ui-module="accounting"] .classic-shift-mark {
    color: var(--ui-on-primary);
    background: var(--ui-primary);
  }
  :root[data-theme] body[data-ui-module="accounting"] .accounting-duty {
    border-left-color: var(--ui-info-border);
  }
  :root[data-theme] body[data-ui-module="accounting"] .classic-employee-summary strong {
    font-size: 1rem;
  }
  :root[data-theme] body[data-ui-module="accounting"] :is(.accounting-table td, .classic-employee-summary strong) {
    font-variant-numeric: tabular-nums;
  }
  :root[data-theme] body[data-ui-module="accounting"] :is(.accounting-main, #accountingContent) {
    min-width: 0;
    max-width: 100%;
  }

  /* Focus retains native semantics; no rules alter hidden, permissions or tabs. */
  :root[data-theme] body[data-ui-module] :is(button, a, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--ui-focus);
    outline-offset: 3px;
  }
  @media (max-width: 760px) {
    :root[data-theme] body[data-ui-module="planner"] .app-header {
      grid-template-columns: minmax(0, 1fr);
    }
    :root[data-theme] body[data-ui-module="planner"] .header-actions {
      min-width: 0;
      max-width: 100%;
      flex-wrap: wrap;
    }
    :root[data-theme] body[data-ui-module="planner"] .header-actions > * {
      max-width: 100%;
    }
    :root[data-theme] body[data-ui-module="planner"] .cycle-control select {
      min-width: 0;
      max-width: 100%;
    }
    :root[data-theme] body[data-ui-module="diary"] .entry-layout {
      grid-template-columns: minmax(0, 1fr);
    }
    :root[data-theme] body[data-ui-module="diary"] .entry-form {
      position: static;
    }
    :root[data-theme] body[data-ui-module="diary"] .note-board {
      grid-template-columns: minmax(0, 1fr);
    }
    :root[data-theme] body[data-ui-module="finder"] .card {
      padding: 1rem;
    }
    :root[data-theme] body[data-ui-module="finder"] .top-actions,
    :root[data-theme] body[data-ui-module="overview"] .header-actions {
      flex-wrap: wrap;
      min-width: 0;
    }
    :root[data-theme] body[data-ui-module="finder"] .search > * {
      width: 100%;
    }
    :root[data-theme] body[data-ui-module="planner"] .office-cover-time-grid {
      grid-template-columns: minmax(0, 1fr);
    }
    :root[data-theme] body[data-ui-module="accounting"] .classic-employee-summary {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    :root[data-theme] body[data-ui-module="accounting"] .accounting-header-actions {
      flex-wrap: wrap;
    }
    :root[data-theme] body[data-ui-module] :is(.header-actions, .toolbar, .accounting-filters, .note-actions, .note-order-actions, .form-actions, .search) :is(button, .button-link, input:not([type="checkbox"]), select) {
      min-height: 44px;
    }
    :root[data-theme] body[data-ui-module="planner"] .toggle {
      min-height: 44px;
    }
  }
}

/* Paper-safe colour corrections only: no table/calendar geometry or visibility changes. */
@media print {
  :root[data-theme] body[data-ui-module="diary"] :is(.confirm-line, .note-confirmation, .note-card) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
    box-shadow: none;
  }
  :root[data-theme] body[data-ui-module="diary"] :is(.confirm-line span, .note-meta, .note-confirmation-meta, .todo-progress) {
    color: var(--ui-text);
  }
  :root[data-theme] body[data-ui-module="finder"] :is(button, button:hover, button:focus) {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-control-border);
    box-shadow: none;
  }
}
