/* ============================================================
   WORKING HOURS — Settings › Working Hours
   Markup is generated by public/js/working-hours.js.

   Layout note: the old pane put the weekly schedule into one column of a
   2-column `.form-grid` (auto-fit minmax(360px, 1fr)). At the common desktop
   width that column was ~270px wide while `.hours-row` asked for
   `200px 1fr 1fr` + 32px of gap — so the two time inputs wrapped on top of
   each other and the toggle in the third column was pushed past the card's
   `overflow: hidden` edge and clipped. Everything here uses `minmax(0, 1fr)`
   for flexible tracks (a bare `1fr` has an auto minimum and refuses to shrink
   below its content, which is what caused the overflow) and collapses to a
   single column before the row can get tight.
   ============================================================ */

.wh-root { display: block; width: 100%; min-width: 0; }

.wh-card { width: 100%; min-width: 0; }

/* ── Header: tabs + dirty pill ── */
.wh-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-5);
}
.wh-tabs {
  display: flex; align-items: center; gap: 2px;
  min-width: 0; flex-wrap: wrap;
}
.wh-tab {
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 13px; font-weight: 500;
  color: var(--fg-dim); background: none; border: 1px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.wh-tab:hover { color: var(--fg); background: var(--bg-elev-2); }
.wh-tab.active {
  background: var(--accent-tint); color: var(--accent);
  border-color: var(--accent-border);
}
.wh-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wh-head-right { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.wh-dirty {
  font-size: 11px; font-weight: 500; letter-spacing: 0.02em;
  color: var(--warning);
  background: var(--warning-tint);
  border: 1px solid rgba(224, 163, 92, 0.28);
  padding: 3px 10px; border-radius: 999px;
  white-space: nowrap;
}

.wh-subhead {
  padding: 0 var(--space-5) var(--space-3);
  font-size: 12px; color: var(--fg-muted);
  border-bottom: 1px solid var(--border-soft);
}

.wh-banner {
  display: flex; align-items: center; gap: var(--space-2);
  margin: var(--space-4) var(--space-5) 0;
  padding: 10px 12px;
  background: var(--danger-tint);
  border: 1px solid rgba(216, 117, 117, 0.3);
  border-radius: var(--radius-md);
  font-size: 13px; color: var(--fg);
}
.wh-banner svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--danger); }

.wh-body { padding: var(--space-4) var(--space-5) var(--space-5); gap: var(--space-4); }

/* ── Quick-set / bulk action strip ── */
.wh-bulk {
  display: flex; align-items: center; gap: var(--space-2);
  flex-wrap: wrap;
}
.wh-bulk-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--fg-muted);
  margin-right: var(--space-1);
}
.wh-bulk .btn svg { width: 14px; height: 14px; }
/* The presets are destructive-ish (they rewrite all seven days), so they need to
   read as buttons rather than as the muted link text .btn-ghost renders here. */
.wh-bulk .btn-ghost {
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-3);
  color: var(--fg-muted);
}
.wh-bulk .btn-ghost:hover {
  color: var(--accent); border-color: var(--accent-border); background: var(--accent-tint);
}

/* ── Day rows ── */
/* Capped so a wide monitor does not strand the row actions a screen-width away
   from the times they act on. */
.wh-days, .wh-rules, .wh-overrides { max-width: 960px; }
.wh-days { display: flex; flex-direction: column; }

.wh-day {
  display: grid;
  /* minmax(0, …) on both flexible tracks — this is the overflow fix. */
  grid-template-columns: minmax(150px, 200px) minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: start;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-soft);
  min-width: 0;
}
.wh-day:first-child { padding-top: var(--space-2); }
.wh-day:last-child { border-bottom: none; padding-bottom: var(--space-2); }

.wh-day-head {
  display: flex; align-items: center; gap: var(--space-3);
  min-width: 0;
  /* Aligns the toggle with the first shift row rather than the block's centre. */
  min-height: 38px;
}
.wh-day-meta { min-width: 0; }
.wh-day-name {
  font-size: 14px; font-weight: 500; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wh-day-status {
  font-size: 11px; color: var(--fg-muted);
  font-variant-numeric: tabular-nums; margin-top: 1px;
}
.wh-day.is-closed .wh-day-name { color: var(--fg-muted); }

/* The switch is a <button> here (it was a bare <span> with onclick before, so it
   was unreachable by keyboard). Reset the button chrome, keep the .switch look. */
.wh-day-head .switch,
.wh-ov-closed .switch {
  flex-shrink: 0;
  padding: 0; margin: 0;
  -webkit-appearance: none; appearance: none;
  cursor: pointer;
}
.wh-day-head .switch:focus-visible,
.wh-ov-closed .switch:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ── Shifts ── */
.wh-shifts {
  display: flex; flex-direction: column; gap: var(--space-2);
  min-width: 0;
}
.wh-shift {
  display: flex; align-items: center; gap: var(--space-2);
  flex-wrap: wrap;
  min-width: 0;
}
.wh-sep { color: var(--fg-muted); font-size: 13px; flex-shrink: 0; }

.wh-closed-note {
  font-size: 13px; color: var(--fg-muted); font-style: italic;
  min-height: 38px; display: flex; align-items: center;
}

/* Select / input shell — mirrors .text-input but sized for inline use. */
.wh-select {
  position: relative;
  display: inline-flex; align-items: center;
  background: var(--bg-elev-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  height: 38px; min-height: 38px;
  min-width: 0;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.wh-select:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-gold-glow);
}
.wh-select select,
.wh-select input {
  appearance: none; -webkit-appearance: none;
  background: none; border: none; outline: none;
  font-family: var(--font-body); font-size: 13px; color: var(--fg);
  padding: 0 12px;
  height: 100%; width: 100%;
  min-width: 0;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.wh-select input { cursor: text; }
.wh-select select { padding-right: 30px; }
.wh-caret {
  position: absolute; right: 10px;
  width: 14px; height: 14px;
  color: var(--fg-muted); pointer-events: none;
}
/* Time selects get a stable width so the two sides of a range line up down
   the column instead of jittering with the label's length. */
.wh-shift .wh-select { flex: 0 1 132px; }
.wh-select-date { flex: 0 1 168px; }
.wh-select-grow { flex: 1 1 200px; min-width: 0; }

.wh-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  background: none; border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--fg-muted); cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}
.wh-icon-btn svg { width: 15px; height: 15px; }
.wh-icon-btn:hover:not(:disabled) {
  color: var(--fg); background: var(--bg-elev-3); border-color: var(--border);
}
.wh-icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.wh-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.wh-icon-danger:hover:not(:disabled) {
  color: var(--danger); background: var(--danger-tint); border-color: rgba(216, 117, 117, 0.3);
}
/* Keeps single-shift rows aligned with multi-shift rows that show a delete button. */
.wh-icon-spacer { width: 34px; height: 34px; flex-shrink: 0; display: inline-block; }

.wh-add-shift {
  display: inline-flex; align-items: center; gap: 6px;
  align-self: flex-start;
  padding: 5px 10px; margin-top: 2px;
  background: none; border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-body); font-size: 12px; color: var(--fg-muted);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}
.wh-add-shift svg { width: 13px; height: 13px; }
.wh-add-shift:hover { color: var(--accent); border-color: var(--accent-border); background: var(--accent-tint); }
.wh-add-shift:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wh-day-actions {
  display: flex; align-items: center; gap: var(--space-1);
  flex-shrink: 0;
  min-height: 38px;
}

.wh-row-error {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 6px;
  margin-top: var(--space-2);
  font-size: 12px; color: var(--danger);
}
.wh-row-error svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── Date overrides ── */
.wh-overrides { display: flex; flex-direction: column; gap: var(--space-3); }

.wh-override {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: start;
  padding: var(--space-4);
  background: var(--bg-elev-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  min-width: 0;
}
.wh-override.is-closed { background: var(--bg-elev-2); }
.wh-ov-main { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.wh-ov-fields { display: flex; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
.wh-ov-shifts { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.wh-ov-side {
  display: flex; align-items: center; gap: var(--space-2);
  flex-shrink: 0;
}
.wh-ov-closed {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--fg-muted); cursor: pointer;
  white-space: nowrap;
}

.wh-empty {
  padding: var(--space-7) var(--space-5);
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}
.wh-empty-title { font-size: 14px; font-weight: 500; color: var(--fg); }
.wh-empty-sub {
  font-size: 12px; color: var(--fg-muted);
  margin-top: 6px; max-width: 46ch; margin-inline: auto; line-height: 1.5;
}

/* ── Booking rules ── */
.wh-rules { display: flex; flex-direction: column; }
.wh-rules + .wh-crossref, .wh-rules .wh-crossref { max-width: 960px; }
.wh-rule {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 220px);
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-soft);
  min-width: 0;
}
.wh-rule:first-child { padding-top: var(--space-1); }
.wh-rule:last-child { border-bottom: none; padding-bottom: var(--space-1); }
.wh-rule-text { min-width: 0; }
.wh-rule-label { font-size: 14px; font-weight: 500; color: var(--fg); display: block; }
.wh-rule-hint { font-size: 12px; color: var(--fg-muted); margin-top: 3px; line-height: 1.5; }
.wh-rule-control { min-width: 0; }
.wh-rule-control .wh-select { width: 100%; }

.wh-crossref {
  margin-top: var(--space-4);
  padding: 10px 12px;
  background: var(--bg-elev-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  font-size: 12px; color: var(--fg-muted); line-height: 1.5;
}

/* ── Saving state on the shared Settings action bar ── */
#settingsBtnSave:disabled,
#settingsBtnDiscard:disabled { opacity: 0.5; cursor: not-allowed; }
#settingsBtnSave.is-loading { position: relative; pointer-events: none; }

/* ============================================================
   RESPONSIVE
   Collapse before the 3-column row can get tight, not at an
   arbitrary device width.
   ============================================================ */
@media (max-width: 900px) {
  .wh-day {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-3);
    row-gap: var(--space-3);
  }
  /* Day name + toggle span the row; shifts sit below, actions stay top-right. */
  .wh-day-head { grid-column: 1; grid-row: 1; }
  .wh-day-actions { grid-column: 2; grid-row: 1; }
  .wh-shifts { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 768px) {
  .wh-head { padding: var(--space-2) var(--space-4); }
  .wh-subhead { padding: 0 var(--space-4) var(--space-3); }
  .wh-body { padding: var(--space-4); }
  .wh-banner { margin: var(--space-3) var(--space-4) 0; }

  .wh-tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .wh-tabs::-webkit-scrollbar { display: none; }
  .wh-tab { flex: 0 0 auto; }

  /* Full-width time selects: two per row with the dash between them. */
  .wh-shift .wh-select { flex: 1 1 0; min-width: 96px; }
  .wh-select-date, .wh-select-grow { flex: 1 1 100%; }

  .wh-override { grid-template-columns: minmax(0, 1fr); }
  .wh-ov-side { justify-content: space-between; width: 100%; }

  .wh-rule {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
    align-items: stretch;
  }
  .wh-rule-control .wh-select { width: 100%; }

  /* Comfortable touch targets (44px) without changing the desktop rhythm. */
  .wh-icon-btn { width: 40px; height: 40px; }
  .wh-icon-spacer { width: 40px; height: 40px; }
  .wh-select { height: 42px; min-height: 42px; }
  .wh-add-shift { padding: 8px 12px; }
}

@media (max-width: 420px) {
  .wh-shift { gap: 6px; }
  .wh-sep { order: 0; }
  .wh-day-actions { gap: 0; }
}
