:root {
  --bg: #f8fafc;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --header-bg: #e2e8f0;
  --time-col: #f1f5f9;
  --sel: rgba(2, 132, 199, 0.25);
  --font: system-ui, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

body.page--kiosk {
  min-height: 100dvh;
}

a {
  color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.toolbar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.toolbar-edit-target {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.toolbar-edit-target select {
  max-width: 11rem;
}

.reset-week-btn {
  font-weight: 600;
  background: #fff7ed;
  border-color: #fdba74;
}

.week-inherit-hint {
  margin: 0;
  padding: 0.35rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.toolbar label {
  font-size: 0.85rem;
  color: var(--muted);
}

select,
button,
input[type="text"] {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

button {
  cursor: pointer;
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Off-screen but focusable: receives keystrokes when multiple cells are selected to merge. */
.clone-from-input {
  width: 9rem;
}

.merge-capture-input {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0.01;
  z-index: 9999;
}

.status {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.status--err {
  color: #b91c1c;
}

/* Spreadsheet */
.sheet-wrap {
  overflow: auto;
  max-height: calc(100dvh - 120px);
  margin: 0 0.5rem 1rem;
  border: 1px solid var(--border);
  background: #fff;
}

.sheet-wrap:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px rgba(2, 132, 199, 0.35);
}

.sheet {
  border-collapse: collapse;
  table-layout: fixed;
  min-width: max(100%, 720px);
}

.sheet th,
.sheet td {
  border: 1px solid var(--border);
  vertical-align: top;
  padding: 0;
}

.sheet th {
  background: var(--header-bg);
  font-weight: 700;
  font-size: 0.75rem;
  text-align: center;
  position: sticky;
  z-index: 2;
}

.sheet thead th {
  top: 0;
}

.sheet .th-time {
  left: 0;
  z-index: 3;
  width: 4.25rem;
  min-width: 4.25rem;
  background: var(--time-col);
}

.sheet tbody th {
  left: 0;
  z-index: 1;
  width: 4.25rem;
  min-width: 4.25rem;
  font-weight: 600;
  font-size: 0.72rem;
  background: var(--time-col);
  color: var(--muted);
  text-align: right;
  padding: 0.2rem 0.35rem;
  position: sticky;
}

.sheet .th-person {
  min-width: 6.5rem;
  padding: 0.35rem;
}

.sheet .cell {
  min-height: 2.25rem;
  min-width: 6rem;
  position: relative;
  /* background comes from blend (mentions) or inline from JS */
  background: #fff;
}

/* Lift cell so hover “with:” strip paints above the row below */
.sheet .cell:hover,
.sheet .cell:focus-within {
  z-index: 6;
}

/* Drag here to select multiple rows in this column (clicks on text edit the cell). */
.sheet .cell-select-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  z-index: 3;
  cursor: ns-resize;
  touch-action: none;
  background: transparent;
}

.sheet .cell-select-handle:hover,
.sheet .cell-select-handle:focus-visible {
  background: rgba(2, 132, 199, 0.14);
}

/* Merged cell overlay: covers the whole cell; click=edit, drag=select. */
.sheet .cell-merge-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  cursor: text;
  touch-action: none;
}

/* Touch devices: disable browser pan/scroll on body cells so pointer events fire reliably
   for both tap-to-edit and drag-to-select. Scrolling still works via the sticky time column
   (<th>) which keeps its default touch-action. Also widen the drag handle affordance. */
@media (pointer: coarse) {
  .sheet .cell {
    touch-action: none;
  }
  .sheet .cell-select-handle {
    width: 28px;
  }
  .sheet .cell-inner {
    width: calc(100% - 28px) !important;
    margin-left: 28px !important;
  }
  .sheet .cell-with-hints {
    left: 28px;
  }
}

.sheet .cell-inner {
  width: calc(100% - 12px);
  margin-left: 12px;
  min-height: 2.25rem;
  padding: 0.25rem 0.35rem;
  border: none;
  resize: none;
  font: inherit;
  line-height: 1.25;
  background: transparent;
  display: block;
  box-sizing: border-box;
}

.sheet .cell-inner::placeholder {
  color: var(--muted);
}

.sheet .cell-inner:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sheet td.cell--merged .cell-inner {
  min-height: 3rem;
}

.sheet .cell-stack {
  position: relative;
  min-width: 0;
  overflow: visible;
}

/* Admin: floats at bottom inside the field (overlays textarea; no layout shift) */
.sheet .cell-with-hints {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
  position: absolute;
  left: 12px;
  right: 0;
  bottom: 0;
  padding: 0.3rem 0.45rem 0.35rem;
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  box-shadow: 0 -3px 12px rgba(15, 23, 42, 0.1);
  z-index: 5;
  pointer-events: auto;
}

.sheet .cell-with-hints-prefix {
  font-weight: 600;
  color: var(--text);
  margin-right: 0.15rem;
}

.sheet .cell:hover .cell-with-hints,
.sheet .cell:focus-within .cell-with-hints {
  display: flex;
}

.sheet .cell-with-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.sheet .cell-with-hint input {
  margin: 0;
  cursor: pointer;
}

/* Non-merged cells: highlight the textarea background on selection. */
.sheet .cell:not(.cell--merged).selected .cell-inner {
  background: var(--sel);
}

/* Per-slot indicators inside merged cells — each covers one time-slot's height.
   pointer-events:none so the overlay underneath still receives clicks/drags. */
.sheet .cell-slot-indicator {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 4;
  transition: background 80ms;
}

.sheet .cell-slot-indicator.selected {
  background: var(--sel);
}

.sheet .corner {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 4;
  background: var(--header-bg);
}

/* Kiosk */
.kiosk-title {
  text-align: center;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 800;
  margin: 0.75rem 1rem 0.25rem;
}

.kiosk-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 1rem 1rem;
}

.page--kiosk .sheet-wrap {
  max-height: calc(100dvh - 100px);
}

.page--kiosk .cell-inner {
  cursor: default;
  pointer-events: none;
}

.page--kiosk .th-person {
  font-size: 0.8rem;
}

/* Admin: week calendar */
.calendar-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  position: relative;
}

.week-nav-btn {
  padding: 0.25rem 0.45rem;
  font-weight: 700;
  line-height: 1;
  min-width: 2rem;
}

.week-range-btn {
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  max-width: min(240px, 42vw);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-popover {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 260px;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.calendar-month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  font-weight: 700;
  font-size: 0.9rem;
}

.calendar-icon-btn {
  padding: 0.2rem 0.45rem;
  font-weight: 700;
  line-height: 1;
  min-width: 2rem;
  background: var(--time-col);
}

.calendar-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  margin-bottom: 0.2rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.calendar-day {
  aspect-ratio: 1;
  min-height: 2rem;
  padding: 0;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
}

.calendar-day:hover {
  background: var(--time-col);
}

.calendar-day--muted {
  color: var(--muted);
  opacity: 0.65;
}

.calendar-day--today {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.calendar-day--in-week {
  background: #e0f2fe;
}

.calendar-day--selected {
  background: var(--accent);
  color: #fff;
}

.calendar-day--selected.calendar-day--today {
  box-shadow: inset 0 0 0 2px #0369a1;
}
