/* Shared component styles. Each block pairs with a js/ui module:
   sheet.js → .sheet-*, chips.js → .chip-*, cards.js → .cardlist/.cardrow,
   tabs.js → .tabstrip/.tab. The Setup hub cards (.hub-*) are static markup
   in index.html. */

/* ---- Sheet (sheet.js) ------------------------------------------------------
   One API, three presentations: anchored popover / centred dialog on desktop,
   full-width bottom sheet on compact. */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  background: var(--backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

/* Page scroll parks while a modal sheet (dialog / bottom) is open. */
body.sheet-open { overflow: hidden; }

/* Popover mode keeps the page visible: the backdrop only catches outside
   clicks; the sheet itself is positioned by JS. */
.sheet-backdrop--popover {
  background: transparent;
  display: block;
  padding: 0;
}

.sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-modal);
  padding: var(--space-5);
  width: 100%;
  max-width: 26rem;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
}

.sheet--popover {
  position: absolute;
  width: max-content;
  min-width: 16rem;
  max-width: 22rem;
  padding: var(--space-4);
  box-shadow: var(--shadow-pop);
}

.sheet-title {
  margin: 0 0 var(--space-4);
  font-size: var(--font-lg);
}

/* Title row with a trailing action button pinned to its top-right. */
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

.sheet-head .sheet-title {
  margin: 0;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

@media (max-width: 720px) {
  /* Bottom sheet: thumb-reachable, slides up, drag-handle affordance. */
  .sheet-backdrop,
  .sheet-backdrop--popover {
    background: var(--backdrop);
    display: flex;
    align-items: flex-end;
    justify-content: stretch;
    padding: 0;
  }

  .sheet,
  .sheet--popover {
    position: static;
    width: 100%;
    min-width: 0;
    max-width: none;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    /* Extra bottom padding keeps sheet actions clear of the iPhone home
       indicator (safe-area inset is 0 elsewhere). */
    padding: var(--space-4) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom));
    animation: sheet-rise 0.2s ease;
  }

  .sheet::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--border);
    margin: 0 auto var(--space-3);
  }

  .sheet-actions button {
    min-height: var(--touch-target);
    flex: 1;
  }
}

@keyframes sheet-rise {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---- Chips (chips.js) ------------------------------------------------------
   Role/skill chip: name plus optional 1–3 level pips (shown only where a
   level is set). Colour arrives per-chip via the --chip-color custom
   property, set from data by chips.js. */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-xs);
  font-weight: 500;
  line-height: 1.6;
  white-space: nowrap;
}

.chip--colored {
  background: var(--chip-color);
  border-color: var(--chip-color);
  color: var(--on-accent);
}

.chip-pips {
  display: inline-flex;
  gap: 2px;
}

.chip-pip {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
}

.chip-pip--on { opacity: 1; }

.chiprow {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* ---- Card list (cards.js) --------------------------------------------------
   Row-based lists render as stacked cards; below 720px they're the only
   presentation (tables collapse to these). */

.cardlist {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.cardrow {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  font-size: var(--font-sm);
  font-weight: 400;
  transition: none;
}

button.cardrow:hover,
a.cardrow:hover {
  background: var(--bg);
  cursor: pointer;
}

.cardrow-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
}

.cardrow-title {
  font-weight: 500;
  font-size: var(--font-md);
}

.cardrow-meta {
  color: var(--muted);
  font-size: var(--font-xs);
  flex: 0 0 auto;
}

.cardrow-sub {
  color: var(--muted);
  margin-top: 0.125rem;
}

.cardrow .chiprow {
  margin-top: var(--space-2);
}

/* ---- Setup hub cards (static markup) --------------------------------------- */

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.hub-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}

a.hub-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.hub-card--soon {
  opacity: 0.6;
}

.hub-card-title {
  font-weight: 600;
  font-size: var(--font-md);
}

.hub-card-desc {
  color: var(--muted);
  font-size: var(--font-sm);
}

.hub-card-badge {
  align-self: flex-start;
  margin-top: var(--space-1);
  padding: 0.075rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--font-xs);
  font-weight: 500;
}

/* ---- Tab strip (tabs.js) ----------------------------------------------------
   Generic underline tabs; the rota "day" variant renders two-line day cards. */

.tabstrip {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-sm);
  font-weight: 500;
}

.tab:hover {
  background: var(--bg);
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Day variant (rota builder + solved view): substantial two-line cards —
   weekday + date on the first row, allocated/available hours below — instead
   of thin underline tabs. */

.tabstrip--day {
  gap: var(--space-2);
  border-bottom: none;
  padding-bottom: var(--space-1);
}

.tabstrip--day .tab {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  row-gap: 0.125rem;
  min-width: 6.5rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: var(--font-md);
  font-weight: 600;
  text-align: left;
}

/* Per-day status dot: hollow grey before the day is solved, then a filled
   traffic light — red (breach) / amber (unassigned or imperfect) / green. */
.tabstrip--day .tab-status {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}

.tab-status--pending {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--muted);
}

.tab-status--error {
  background: var(--danger);
}

.tab-status--warn {
  background: var(--warn);
}

.tab-status--ok {
  background: var(--ok);
}

/* Weekday + date lead, the hours line below — both leading-aligned. */
.tabstrip--day .tab-label {
  grid-row: 1;
  justify-self: start;
}

.tabstrip--day .tab-sub {
  grid-row: 2;
  justify-self: start;
  font-size: var(--font-xs);
  font-weight: 500;
  color: var(--muted);
}

.tabstrip--day .tab:hover {
  background: var(--bg);
}

.tabstrip--day .tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.tabstrip--day .tab.active .tab-sub {
  color: var(--accent);
}

/* The solved view's Summary tab sits apart from the seven day cards. */
.tabstrip--day .tab--summary {
  margin-left: var(--space-4);
}

@media (max-width: 720px) {
  .tab {
    min-height: var(--touch-target);
  }
}

/* ---- Screen head -----------------------------------------------------------
   Title + subtitle on the left, action buttons on the right. (Also defined in
   legacy style.css; this copy is what rebuilt screens rely on once that file
   shrinks.) */

.screen-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
}

/* .btn-inline is inert now that buttons default to intrinsic width; the class
   remains in JS call sites as a statement of intent. */

/* ---- Sheet forms -----------------------------------------------------------
   Inputs inside sheets follow the base text-input look; number/time/select
   aren't styled globally (legacy screens size their own), so cover them here. */

.sheet input[type="number"],
.sheet input[type="time"],
.sheet select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: var(--font-md);
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: var(--space-4);
}

.sheet-message {
  margin: 0;
  color: var(--text);
  font-size: var(--font-sm);
}

.sheet-note {
  margin: 0 0 var(--space-2);
  font-size: var(--font-xs);
}

.check-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-3);
  font-weight: 400;
}

.check-row input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.pop-modes {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.pop-modes .check-row {
  margin: 0;
}

/* Job count trailing each mode label — muted so it reads as a secondary note. */
.pop-mode-count {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--font-sm);
  font-variant-numeric: tabular-nums;
}

/* Radios show a :focus-visible box on click (browsers treat them as keyboard
   controls) — distracting here, and the native dot already marks selection. */
.pop-modes input[type="radio"]:focus-visible {
  outline: none;
}

.pop-days {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
}

.pop-days-all {
  font-weight: 600;
}

.pop-day-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 12rem;
  overflow-y: auto;
  padding-left: var(--space-3);
}

.pop-day-list .check-row {
  margin: var(--space-1) 0;
}

.radio-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.radio-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  font-weight: 400;
  margin-bottom: 0;
}

.radio-row:hover { background: var(--bg); }

.radio-row input { margin: 0; }

/* ---- Row-action menu (menu.js) -------------------------------------------- */

.menu-list {
  display: flex;
  flex-direction: column;
  min-width: 11rem;
}

.menu-item {
  background: transparent;
  color: var(--text);
  text-align: left;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 400;
}

.menu-item:hover { background: var(--bg); }

.menu-item--danger { color: var(--danger); }
.menu-item--danger:hover { background: var(--danger-soft); }

@media (max-width: 720px) {
  .menu-item { min-height: var(--touch-target); }
}

/* ---- Level picker (levels.js) ----------------------------------------------
   Segmented — / 1 / 2 / 3 control. */

.levelpick {
  display: inline-flex;
  gap: 0.25rem;
  margin-bottom: var(--space-3);
}

.levelpick-btn {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--font-sm);
  font-weight: 600;
  line-height: 1;
}

.levelpick-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.levelpick-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

@media (max-width: 720px) {
  .levelpick-btn {
    width: var(--touch-target);
    height: var(--touch-target);
  }
}

/* ---- Colour swatch picker --------------------------------------------------- */

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.swatch {
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}

.swatch.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  .swatch {
    width: 2.4rem;
    height: 2.4rem;
  }
}

/* ---- Assign-staff sheet ----------------------------------------------------- */

.assign-list {
  display: flex;
  flex-direction: column;
  max-height: 50vh;
  overflow-y: auto;
}

.assign-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) 0;
}

.assign-row .levelpick { margin-bottom: 0; }

.assign-name {
  font-size: var(--font-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Form grid --------------------------------------------------------------
   Two-column field grid on desktop, stacked on compact. */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-4);
}

.field label { margin-bottom: 0.375rem; }

.field input[type="number"],
.field input[type="time"],
.field select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: var(--font-sm);
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
}
