/* grid.css: week grid, participant steps and summary. Colours come from the base.css tokens; grid-only tokens live here. */
:root {
  --wg-axis-w: 42px;
  --wg-head-h: 56px;
  --wg-on: var(--primary);
  --wg-on-ink: #ffffff;
  --wg-sel: #1f5446;
  --wg-line: #e8ebe7;
  --wg-line-hour: #cdd4ce;
  --wg-off-bg: #eceee9;
  --wg-none-hatch: rgba(201, 138, 43, 0.38);
  --wg-pending: var(--focus);
  --wg-heat-1: #d6e9df;
  --wg-heat-2: #a9d2bf;
  --wg-heat-3: #6fb297;
  --wg-heat-4: var(--primary);
}

/* ---------- component shell ---------- */
.wg { --wg-cell-h: 30px; position: relative; }
.wg[data-slot="60"] { --wg-cell-h: 40px; }
.wg[data-slot="15"] { --wg-cell-h: 22px; }
.wg.is-day-edit { --wg-cell-h: 38px; }
.wg.is-day-edit[data-slot="60"] { --wg-cell-h: 52px; }
.wg.is-day-edit[data-slot="15"] { --wg-cell-h: 30px; }

.wg-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.wg-nav-group { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; justify-content: center; }
.wg-nav {
  appearance: none; position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; touch-action: manipulation;
}
.wg-nav:hover { background: #f1f4f1; }
.wg-nav:disabled { opacity: 0.35; cursor: not-allowed; }
/* CSS chevrons: text arrows would be mirrored by the bidi algorithm in RTL */
.wg-nav::before { content: ''; width: 10px; height: 10px; border: solid currentColor; border-width: 3px 3px 0 0; }
.wg-nav-prev::before { transform: rotate(45deg); margin-inline-end: 4px; }
.wg-nav-next::before { transform: rotate(-135deg); margin-inline-start: 4px; }
.wg-weeklabel { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 190px; font-weight: 650; text-align: center; }
.wg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.wg-nav .wg-dot { position: absolute; top: 5px; inset-inline-end: 5px; }
.wg-modes { display: inline-flex; gap: 6px; }
.wg-daybar { flex-direction: column; align-items: stretch; }
.wg-daybar > .btn { align-self: flex-start; }
.wg-daytitle { margin: 0; font-size: 1.15rem; text-align: center; }
.wg-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.wg-actions .btn { min-height: 44px; }
.wg-act-hint { font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.wg-banner { margin: 0; }

/* ---------- prominent day buttons (phones: precise marking never depends on a narrow column) ---------- */
.wg-dayrow { margin-bottom: 12px; }
.wg-dayrow-head { margin-bottom: 8px; }
.wg-dayrow-btns { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.wg-daybtn { flex-direction: column; gap: 0; min-height: 64px; padding: 6px 8px; line-height: 1.3; }
.wg-daybtn-name { font-weight: 650; }
.wg-daybtn-date { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.wg-daybtn-state { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.wg-daybtn.has-ranges { border-color: var(--primary); }
.wg-daybtn.has-ranges .wg-daybtn-state { color: var(--primary); }
.wg-daybtn.is-none { background-image: repeating-linear-gradient(45deg, var(--wg-none-hatch) 0 4px, transparent 4px 9px); }

/* ---------- the grid ---------- */
.wg-grid {
  display: grid; grid-template-columns: var(--wg-axis-w) repeat(var(--wg-cols, 6), minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  touch-action: pan-y pinch-zoom; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.wg-grid.is-day { --wg-axis-w: 54px; }
.wg-col { display: flex; min-width: 0; }
.wg-day { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; border-inline-start: 1px solid var(--wg-line); }
.wg-axis { min-width: 0; }

.wg-head {
  appearance: none; position: sticky; top: var(--wg-sticky-top, 0px); z-index: 3; width: 100%; height: var(--wg-head-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; margin: 0;
  background: var(--surface); border: 0; border-bottom: 2px solid var(--wg-line-hour); color: var(--text); font: inherit; line-height: 1.15;
}
button.wg-head { cursor: pointer; touch-action: manipulation; }
button.wg-head:hover { background: var(--primary-soft); }
button.wg-head::after { content: ''; margin-top: 3px; border-inline: 4px solid transparent; border-top: 5px solid var(--muted); }
.wg-head-name { font-weight: 650; font-size: 0.95rem; }
.wg-head-num { font-size: 0.78rem; color: var(--muted); }
.wg-head-flag { font-size: 0.85rem; color: var(--accent); font-weight: 700; }
.wg-col.is-split .wg-head-name { font-size: 0.85rem; }
.wg-day.is-wide .wg-head-name { font-size: 1.05rem; }
.wg-head.is-none { background-image: repeating-linear-gradient(45deg, var(--wg-none-hatch) 0 4px, transparent 4px 9px); }

.wg-tick { position: relative; height: var(--wg-cell-h); }
.wg-tick-label {
  position: absolute; top: -0.62em; inset-inline-end: 6px; font-size: 0.72rem; color: var(--muted);
  font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap;
}

.wg-cell { position: relative; height: var(--wg-cell-h); border-top: 1px solid var(--wg-line); scroll-margin-top: calc(var(--wg-head-h) + var(--wg-sticky-top, 0px) + 8px); scroll-margin-bottom: 96px; }
.wg-cell.is-hour { border-top-color: var(--wg-line-hour); }
.wg-edit .wg-cell[role="option"] { cursor: pointer; } /* also makes iOS Safari deliver click for taps */
.wg-cell::before { content: ''; position: absolute; inset-block: 0; inset-inline: 2px; pointer-events: none; }
.wg-cell.is-on::before { background: var(--wg-on); }
.wg-cell.is-on:not(.is-first)::before { top: -1px; }
.wg-cell.is-on.is-first::before { border-radius: 6px 6px 0 0; }
.wg-cell.is-on.is-last::before { border-radius: 0 0 6px 6px; }
.wg-cell.is-on.is-first.is-last::before { border-radius: 6px; }
.wg-cell.is-sel::before { background-color: var(--wg-sel); background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.2) 0 4px, transparent 4px 8px); }
.wg-cell.is-preview::before { background: var(--primary-soft); box-shadow: inset 0 0 0 2px var(--primary); border-radius: 4px; top: 0; }
.wg[data-tool="erase"] .wg-cell.is-preview::before { background: var(--danger-soft); box-shadow: inset 0 0 0 2px var(--danger); }
.wg-cell.is-pending::before { background: var(--primary-soft); box-shadow: inset 0 0 0 3px var(--wg-pending); border-radius: 4px; top: 0; }
.wg-cell:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; z-index: 1; }
.wg-cell-label {
  position: absolute; inset-inline: 10px; top: 3px; z-index: 1; color: var(--wg-on-ink); font-size: 0.85rem; font-weight: 650;
  direction: ltr; unicode-bidi: isolate; text-align: right; white-space: nowrap; pointer-events: none;
}

/* day states: disabled = flat grey, 'no availability' = hatch pattern plus a flag icon in the header (never colour alone) */
.wg-day.is-disabled { background: var(--wg-off-bg); }
.wg-day.is-disabled .wg-head, .wg-day.is-disabled .wg-cells { opacity: 0.5; }
.wg-day.is-disabled .wg-cells { background-image: repeating-linear-gradient(135deg, transparent 0 7px, rgba(37, 48, 43, 0.07) 7px 8px); }
.wg-day.is-none .wg-cells { background-image: repeating-linear-gradient(45deg, var(--wg-none-hatch) 0 5px, transparent 5px 11px); }

/* heat mode (read only): extension point for the organizer */
.wg-heat-0 { background: transparent; }
.wg-heat-1 { background: var(--wg-heat-1); }
.wg-heat-2 { background: var(--wg-heat-2); }
.wg-heat-3 { background: var(--wg-heat-3); }
.wg-heat-4 { background: var(--wg-heat-4); }
.wg-cell.is-all { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- legend and action bar ---------- */
.wg-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0; margin: 10px 0 0; }
.wg-sw { display: inline-block; width: 14px; height: 14px; margin-inline-end: 6px; border-radius: 3px; vertical-align: -2px; border: 1px solid var(--wg-line-hour); }
.wg-sw-on { background: var(--wg-on); border-color: var(--wg-on); }
.wg-sw-none { background-image: repeating-linear-gradient(45deg, var(--wg-none-hatch) 0 3px, transparent 3px 6px); }
.wg-sw-off { background: var(--wg-off-bg); }

.wg-actionbar {
  position: sticky; bottom: var(--wg-bottom-offset, 0px); z-index: 15; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin-top: 10px; padding: 8px 12px; background: var(--surface); border: 2px solid var(--wg-pending); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.wg-actionbar.is-erase { border-color: var(--danger); }
.wg-actionbar-text { flex: 1 1 180px; font-weight: 600; }

/* ---------- day menu ---------- */
.wg-sheet { border: 0; padding: 0; width: min(92vw, 380px); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 8px 40px rgba(37, 48, 43, 0.3); }
.wg-sheet::backdrop { background: rgba(37, 48, 43, 0.45); }
.wg-sheet-body { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.wg-sheet-title { margin: 0 0 4px; }
.wg-sheet-body .btn { width: 100%; justify-content: space-between; }

/* ---------- participant steps ---------- */
.pt-step { --pt-head-h: 56px; --wg-sticky-top: var(--pt-head-h); --wg-bottom-offset: 78px; }
.pt-head {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; height: var(--pt-head-h);
  margin-inline: -16px; padding-inline: 16px; background: var(--bg); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden;
}
.pt-name { flex: 0 1 auto; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.pt-hint { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 0.9rem; }
.pt-title { font-size: 1.1rem; margin: 12px 0 8px; }
.pt-step .notice { margin-bottom: 10px; }
.pt-foot { position: sticky; bottom: 0; z-index: 20; margin-top: 12px; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.pt-continue { width: 100%; }
.pt-desc { white-space: pre-wrap; }
.pt-chips { gap: 10px; }
.pt-chip { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; padding: 6px 22px; font-size: 1.1rem; }
.pt-chip:disabled { text-decoration: none; opacity: 0.75; }
.pt-chip:disabled .pt-chip-name { text-decoration: line-through; }
.pt-chip-hint { font-size: 0.78rem; font-weight: 400; color: var(--muted); }
.pt-link { direction: ltr; text-align: left; font-size: 0.95rem; }

/* ---------- summary ---------- */
.sm-section { margin-top: 8px; }
.sm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sm-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.sm-day { font-weight: 600; }
.sm-flag { color: var(--accent); font-weight: 700; }
.sm-range { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 600; border: 1px solid transparent; }
.sm-range-btn { min-height: 44px; font: inherit; font-weight: 600; cursor: pointer; touch-action: manipulation; border-color: var(--primary); }
.sm-range-btn:hover { background: #d3e6dc; }
.sm-x { font-size: 0.85rem; }
.sm-chips { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.sm-chip { padding: 2px 10px; border-radius: 999px; background: #ecefec; font-size: 0.9rem; }
.sm-actions { margin-top: 12px; }
.sm-msg:empty { display: none; }

@media (max-width: 480px) {
  .wg-dayrow-btns { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .wg-daybtn { min-height: 58px; padding: 4px 2px; overflow-wrap: anywhere; }
  .wg-daybtn-name { font-size: 0.88rem; }
  .wg-daybtn-date, .wg-daybtn-state { font-size: 0.7rem; }
  .wg-weeklabel { min-width: 0; font-size: 0.95rem; }
  .wg-grid { --wg-axis-w: 38px; }
  .wg-grid.is-day { --wg-axis-w: 48px; }
  .wg-tick-label { inset-inline-end: 4px; font-size: 0.68rem; }
}
