/* css/responsive.css — All @media queries (viewport-size, prefers-color-scheme, prefers-reduced-motion, print). Imported into the responsive layer (outermost — wins by layer order over components and themes). */

/* responsive layer wins over components and themes layers per @layer order in style.css; system-preference @media (prefers-*) overrides are intentional. */

/* Fix D: Mobile responsive rules for Stage theme elements */
@media (max-width: 768px) {
  /* Rail: compact */
  body.stage-mode .rail {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
  }
  body.stage-mode .rail__brand {
    font-size: 0.65rem;
  }
  body.stage-mode .rail__title {
    font-size: 0.95rem;
  }
  .rail__logo {
    max-height: 1.5rem;
    max-width: 6rem;
  }
  body.stage-mode .rail__chip {
    font-size: 0.6rem;
    padding: 2px 6px;
  }

  /* Ondeck: compact single row */
  body.stage-mode .ondeck {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
  }
  body.stage-mode .ondeck__label {
    font-size: 0.7rem;
  }
  body.stage-mode .ondeck__time {
    font-size: 0.75rem;
  }

  /* Minimap: reduce height */
  body.stage-mode .minimap {
    padding: var(--space-1) var(--space-3);
  }

  /* Stage table: hide drag handle and duration column */
  body.stage-mode .stage-row__drag,
  body.stage-mode .stage-header__drag,
  body.stage-mode .stage-row__duration,
  body.stage-mode .stage-header__duration {
    display: none;
  }
  body.stage-mode .stage-table {
    font-size: 0.78rem;
  }
  body.stage-mode .stage-input--time {
    width: 80px;
    font-size: 0.78rem;
  }
  body.stage-mode .stage-input--type {
    font-size: 0.78rem;
  }
  body.stage-mode .stage-header__actions { width: 60px; }

  /* Phase 14: receded tier hidden on phones; prominent tier (next + after-next) stays visible. */
  .upcoming-slot-card--receded {
    display: none;
  }
}


@media (max-width: 480px) {
  /* Minimap: hide on small phones to save screen space */
  body.stage-mode .minimap {
    display: none !important;
  }

  /* Type column: hide on very narrow screens */
  body.stage-mode .stage-row__type,
  body.stage-mode .stage-header__type {
    display: none;
  }

  /* Stage table: ensure scroll for overflow */
  body.stage-mode #timetable-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Settings row: already 1-col from 540px rule, ensure inputs full-width */
  body.stage-mode .settings-field__input,
  body.stage-mode .settings-field__select {
    width: 100%;
  }
}


/* Auto: follow OS preference (dark is default, so only override for light) */
@media (prefers-color-scheme: light) {
  body:not(.theme-dark):not(.theme-hc) {
    --bg-primary:     #f5f3ef;
    --bg-surface:     #eceae4;
    --bg-surface-2:   #e4e2dc;
    --text-primary:   #1a1a1a;
    --text-muted:     #4a4a4a;
    --clock-normal:   #1a1a1a;
    --clock-warning:  #b45309;
    --clock-positive: #16a34a;
    --accent-amber:   #b07300;
    --color-warning:  #d97706;
  }

  body:not(.theme-dark):not(.theme-hc) .hud {
    background: linear-gradient(to top, rgba(245, 243, 239, 0.98) 80%, transparent);
  }

  body:not(.theme-dark):not(.theme-hc) .timetable-panel {
    background: var(--bg-surface);
  }

  body:not(.theme-dark):not(.theme-hc) .timetable-panel__header {
    background: rgba(236, 234, 228, 0.97);
  }

  body:not(.theme-dark):not(.theme-hc) .upcoming-slot-card {
    border-color: rgba(0, 0, 0, 0.12);
  }

  body:not(.theme-dark):not(.theme-hc) .upcoming-slot-card--next {
    background: rgba(176, 115, 0, 0.08);
  }

  body:not(.theme-dark):not(.theme-hc) .hud__shortcut-toggle {
    border-color: rgba(0, 0, 0, 0.25);
  }

  body:not(.theme-dark):not(.theme-hc) .active-slot-card--ended {
    border-color: rgba(0, 0, 0, 0.1);
  }
}


/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .clock-display__digits--pulse,
  .clock-display__digits--pulse * {
    animation: none !important;
  }

  body.alert-flash {
    animation: none !important;
    background-color: rgba(239, 68, 68, 0.15);
  }
}


/* ── 13. Media queries ───────────────────────────────────── */

/* Tablet and up */
@media (min-width: 768px) {
  :root {
    --timetable-width: 480px;
  }

  /* Phase 23 (D-DRAWER-01..04 / D-LAYOUT-01): switch the timetable panel from a
     bottom-sheet (base rule in css/timetable-panel.css) to a side drawer sliding
     in from the right. Main clock view stays visible to the left of the drawer.
     No backdrop on desktop — operator can interact with the main view. */
  .timetable-panel {
    /* Override the bottom-sheet base */
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--timetable-width);
    height: 100%;
    border-radius: 0;
    /* Slide in from the right; off-screen → translateX(0) */
    transform: translateX(100%);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
  }

  .timetable-panel.is-open {
    transform: translateX(0);
  }

  /* Hide the bottom-sheet backdrop on desktop — drawer doesn't block the main view */
  .timetable-panel.is-open::before {
    display: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .timetable-panel,
    .timetable-panel.is-open {
      transform: none;
    }
  }
}

/* Large desktop — give the clock more room */
@media (min-width: 1400px) {
  :root {
    --timetable-width: 520px;
  }
}

/* ── Print / PDF export (F18) ────────────────────────────── */
@media print {
  .hud, .timetable-panel, .shortcut-overlay, .clock-screen { display: none !important; }

  body::before {
    content: attr(data-show-title);
    display: block;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1rem;
  }

  .print-timetable {
    display: block !important;
    font-family: sans-serif;
    font-size: 11pt;
    color: #000;
  }

  .print-timetable table {
    width: 100%;
    border-collapse: collapse;
  }

  .print-timetable th,
  .print-timetable td {
    border: 1px solid #ccc;
    padding: 4pt 8pt;
    text-align: left;
  }

  .print-timetable th {
    background: #eee;
    font-weight: 600;
  }
}

/* Touch-target floor for editing rows on small-tablet portrait + phone — WCAG 2.5.5 (Phase 35, MOB-EDIT-02) */
@media (max-width: 768px) {
  .timetable-row--editing input,
  .timetable-row--editing select,
  .timetable-row--editing-extra input,
  .timetable-row--editing-extra select {
    min-height: 44px;
  }
  .timetable-row--editing .timetable-row__actions .btn {
    min-height: 44px;
  }

  /* Switcher list + name-bar touch targets — WCAG 2.5.5 (Phase 36, MOB-PANEL-03) */
  .tt-item {
    min-height: 44px;
  }
  .tt-item__actions .btn {
    min-height: 44px;
  }
  .tt-name-btn {
    min-height: 44px;
  }
}

/* Mobile — tighter HUD spacing */
@media (max-width: 600px) {
  .hud {
    padding: var(--space-3) var(--space-3) var(--space-4);
    gap: var(--space-2);
  }

  .hud__mode-tab {
    font-size: 0.8rem;
    padding: var(--space-1) var(--space-3);
  }

  .hud__offset-row {
    gap: var(--space-1);
  }

  .timetable-row--editing .edit-time {
    width: 100px;
  }

  .btn--xs {
    padding: 6px 10px;
    min-height: 36px;
    font-size: 0.8rem;
  }
}

/* Phone portrait — stacked edit-row (Phase 35, D-V1.9-EDIT-PATTERN-LOCK) */
@media (max-width: 480px) {
  /* Wrap the new fields container as a column flex: input stack above, button stack below */
  .timetable-row--editing .timetable-row__fields {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  /* Input stack — each field full-width on its own row */
  .timetable-row__fields-primary {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: 100%;
  }
  .timetable-row__fields-primary > * {
    width: 100%;
  }

  /* Note: 44px input min-height already applied at ≤768px (see block above) — no need to repeat here */

  /* Override fixed widths from base edit-row CSS so stacked inputs span the row */
  .timetable-row--editing .edit-time,
  .timetable-row--editing .edit-slot-offset {
    width: 100%;
  }

  /* Action stack — full-width buttons, Save → Cancel → Delete (DOM order is the visual order) */
  .timetable-row--editing .timetable-row__actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    width: 100%;
    white-space: normal;
  }
  .timetable-row--editing .timetable-row__actions .btn {
    width: 100%;
    /* min-height: 44px already applied at ≤768px (see block above) */
    justify-content: center;
  }

  /* Extra row: stack the mode/duration/alert/aa/picked-by labels for a clean phone layout */
  .timetable-row__mode-fields {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }
  .edit-mode-label,
  .edit-duration-label,
  .edit-picked-by-label {
    white-space: normal;
  }
  /* Checkboxes (alert + aa) stay inline-flex; their natural row-level layout is fine */

  /* D-V1.9-PHONE-CHROME-HIDE — operator-only rows hidden at ≤480px;
     only the active table + Add slot remain accessible on the phone. */
  .timetable-panel__warn-setting,
  .timetable-panel__settings-row,
  .timetable-panel__io,
  .logo-row {
    display: none;
  }

  /* D-V1.9-PHONE-FULL-VH — panel fills the viewport on phone portrait so the
     operator can see/edit slots without the bottom-sheet eating 30% of the screen. */
  .timetable-panel {
    top: 0;
    height: 100dvh;
  }
  .timetable-panel.is-open::before {
    /* Backdrop top edge also moves up since panel fills the viewport */
    bottom: 100dvh;
  }

  /* HUD utility row on phone: icon-only buttons, breathing gap.
     .btn__label spans hidden at ≤480px; emoji-only via aria-hidden="true" spans remain visible.
     Applies to: wakelock chip, Timetable, Fullscreen, Theme, Stage. 24h and ? stay as-is (already short). */
  .hud__utility .btn__label {
    display: none;
  }

  .hud__utility {
    gap: var(--space-2);
  }

  /* Keyboard-shortcut hint hidden on phone — there's no keyboard. */
  .hud__offset-hint {
    display: none;
  }

  /* Mode tabs: tighter padding on phone for the 3-tab pill. Still ≥44px touch via min-height inherited from base + tap area. */
  .hud__mode-tab {
    font-size: 0.75rem;
    padding: var(--space-1) var(--space-3);
    min-height: 44px; /* HUD-01: WCAG 2.5.5 touch target */
  }

  /* Offset row: tighter gaps, remove the 100px min-width on the no-offset badge. */
  .hud__offset-row {
    gap: var(--space-1);
  }
  .hud__offset-badge {
    min-width: auto;
    font-size: 0.7rem;
  }

  /* HUD-02: offset buttons 44px touch target — scoped to .hud__offset-row only (never bare .btn) */
  .hud__offset-row .btn {
    min-height: 44px;
  }

  /* HUD-03: active slot card — touch floor + tighter padding + label legibility on phone */
  .active-slot-card {
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
  }
  .active-slot-card__label {
    font-size: 1rem;
  }

  /* HUD-03: upcoming slot cards — explicit 44px floor for tap tolerance */
  .upcoming-slot-card--next,
  .upcoming-slot-card--after-next {
    min-height: 44px;
  }

  /* HUD-03: end-slot action buttons — operator tap surface ≥44px */
  .end-slot-btn,
  .end-slot-confirm-btn,
  .end-slot-notime-btn {
    min-height: 44px;
  }

  /* BAND-01: share-notifier panel on phone — tighter padding + push-subscribe button 44px + full-width.
     Picker already has min-height:44px in base. Double-gated body.shared-view + @media. */
  body.shared-view .share-notifier-panel {
    padding: var(--space-2) var(--space-3);
  }
  body.shared-view .share-notifier-panel__push-subscribe-btn {
    min-height: 44px;
    width: 100%;
    justify-content: center;
  }

  /* BAND-02: #share-sunset on phone — allow wrap on narrow viewports (avoid clipped digits at ≤360px).
     .sunset-readout__enable already has min-height: 44px in base — no override needed. */
  body.shared-view #share-sunset {
    white-space: normal;
    max-width: 100%;
  }

  /* Force the editing-row colspan=4 cell to use the full panel width on phone.
     Without this the underlying <table> auto-sizes its columns from the data rows,
     stranding the edit form in the narrowest column. */
  .timetable-table {
    width: 100%;
    table-layout: fixed;
  }
  .timetable-row--editing > .timetable-row__fields {
    width: 100%;
  }

  /* Action buttons in ONE horizontal row on phone — Phase 35 stacked them vertically;
     operator feedback: prefers single row. Each gets flex: 1 for equal width. */
  .timetable-row--editing .timetable-row__actions {
    flex-direction: row;
    gap: var(--space-2);
  }
  .timetable-row--editing .timetable-row__actions .btn {
    flex: 1;
  }
}

/* Edit-field label — visible above each primary input on all viewports (matches the extra-row label style).
   Applied universally (not media-query-gated) for visual consistency between desktop and phone. */
.edit-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.edit-field__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

