/* Piano & guitar lesson booking — hand-written, no framework, no webfonts.
 *
 * Colour carries meaning here: every slot on the grid is one of three states, and a visitor
 * has to tell them apart at a glance, on a phone, in daylight. So the three states differ in
 * hue *and* value *and* texture — booked slots are hatched — which keeps them legible in
 * greyscale and to colourblind readers, not just to a calibrated monitor.
 */

:root {
  /* Ink and paper */
  --ink: #16262c;          /* petrol ink */
  --ink-soft: #5d6f75;
  --paper: #eceef0;
  --card: #ffffff;
  --line: #ccd6d9;
  --line-faint: #e3eaec;
  --hour-rule: rgba(22, 38, 44, .3);

  /* Slot states */
  --open: #cfe7e2;         /* available */
  --open-edge: #8fc3ba;
  --open-hover: #7cc0b4;
  --booked: #dbe1e3;       /* already taken — recessive on purpose */
  --booked-hatch: #c2cbcf;

  /* Brass: the single accent. Your pick, and the button that acts on it. */
  --brass: #a96a1f;
  --brass-soft: #f3e2c6;

  --danger: #9d2f26;
  --refused: #f0d6d1;      /* a lesson will not fit here */
  --radius: 8px;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Hoefler Text", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 var(--serif);
  -webkit-text-size-adjust: 100%;
}

.page { max-width: 64rem; margin: 0 auto; padding: 3rem 1.25rem 4rem; }

header h1 {
  margin: 0 0 .5rem;
  font-size: clamp(2rem, 5vw, 2.9rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-weight: 600;
}
.lede { margin: 0 0 2.75rem; color: var(--ink-soft); max-width: 34rem; font-size: 1.05rem; }

h2 {
  font-family: var(--sans);
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--ink);
  margin: 0 0 .9rem;
}

.step { margin-bottom: 2.5rem; }

/* ---------------------------------------------------------- duration toggle */

.duration-toggle { display: flex; gap: .5rem; flex-wrap: wrap; }

.duration {
  font-family: var(--sans);
  font-size: .95rem;
  padding: .55rem 1.15rem;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--ink);
}
.duration:hover { border-color: var(--ink-soft); }
.duration.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* ---------------------------------------------------------------- the grid */

/* One continuous timetable rather than 64 floating lozenges: no gaps, shared hairlines,
   and runs of the same state merging into a single readable block. */
.grid {
  display: flex;
  align-items: stretch;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--sans);
}

.time-col { width: 4.5rem; flex: none; background: var(--paper); border-right: 1px solid var(--line); }
.day-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.day-col + .day-col { border-left: 1px solid var(--line); }

.col-head {
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--ink);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
}

.time-col .time-label {
  height: 1.75rem;
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  text-align: right;
  padding-right: .5rem;
}
/* Same counted rhythm in the gutter: the hour reads louder than the half hour. */
.time-col .time-label:nth-child(4n+2) { color: var(--ink); font-weight: 600; }
.time-col .time-label:nth-child(4n+4) { color: var(--ink-soft); }

.cell {
  position: relative;
  height: 1.75rem;
  border: 0;
  border-bottom: 1px solid var(--line-faint);
  background: transparent;
  padding: 0;
  cursor: not-allowed;
}

/* The pointer's own cell names when its lesson would start, in the same ink the hour
   lines are drawn with. */
.cell-time {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--hour-rule);
  font-family: var(--mono);
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}

/* At rest a cell is open or booked, nothing more. Whether a lesson fits is a question
   about where the pointer is, and is answered on hover. */
.cell.free {
  background: var(--open);
  border-bottom-color: rgba(15, 107, 99, .18);
}

.cell.taken {
  background:
    repeating-linear-gradient(135deg, transparent 0 5px, rgba(255,255,255,.7) 5px 10px),
    var(--booked);
  /* Near-invisible divider, so a run of booked slots reads as one engagement. */
  border-bottom-color: rgba(255,255,255,.6);
  cursor: not-allowed;
}
.cell.bookable { cursor: pointer; }
.cell.bookable:hover, .cell.preview {
  background: var(--open-hover);
  border-bottom-color: rgba(15, 107, 99, .3);
}

/* The lesson would run past the end of the day, or straight through something already
   booked. Only `background-color` is set, so a booked cell keeps its hatching and the
   obstruction stays visible through the refusal. */
.cell.preview-blocked {
  background-color: var(--refused);
  border-bottom-color: rgba(157, 47, 38, .2);
}

.cell.chosen, .cell.bookable.chosen:hover {
  background: var(--open-hover);
  border: 3px solid #0f6b63;
}
/* The picked lesson is one block, not two or three stacked cells: only its outer
   edge gets the thick border. Zeroing the seam's width (not just its color) avoids
   the mitred-corner artifact a transparent-but-present border would leave biting
   into the still-solid side borders. */
.cell.chosen + .cell.chosen { border-top-width: 0; }
.cell.chosen:has(+ .cell.chosen) { border-bottom-width: 0; }

/* Hour lines, so you can carry a time across four columns without counting rows.
   This counts rather than computes: schedule.json runs 15-minute slots from 3:00 PM, so
   every fourth cell starts an hour. The +6 offset skips the column header and the 3:00 PM
   line, which the header band already draws. Retune if schedule.json's slot length or
   start time ever changes.
   An inset shadow rather than a border, so nothing reflows; and never over the picked
   lesson, which should read as one unbroken block. */
.day-col .cell:nth-child(4n+6):not(.chosen) { box-shadow: inset 0 1px 0 var(--hour-rule); }

.cell:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

.legend {
  display: flex;
  gap: 1.1rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: .9rem;
  font-family: var(--sans);
  font-size: .82rem;
  color: var(--ink-soft);
}
.legend-item { display: inline-flex; gap: .45rem; align-items: center; }
.swatch {
  width: 1.05rem; height: 1.05rem;
  border-radius: 3px;
  border: 1px solid var(--line);
  display: inline-block;
  flex: none;
}
.swatch.free { background: var(--open); border-color: var(--open-edge); }
.swatch.taken {
  background:
    repeating-linear-gradient(135deg, transparent 0 3px, rgba(255,255,255,.7) 3px 6px),
    var(--booked);
  border-color: var(--booked-hatch);
}
.legend-note { color: var(--ink-soft); }

/* Day tabs only matter on narrow screens; see the media query at the bottom. */
.day-tabs { display: none; gap: .4rem; margin-bottom: .75rem; flex-wrap: wrap; }
.day-tab {
  font-family: var(--sans);
  font-size: .9rem;
  padding: .45rem .8rem;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--ink);
}
.day-tab.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ------------------------------------------------------------------- form */

.booking-form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 34rem;
  font-family: var(--sans);
}
.booking-form h2 { margin-top: 0; }
.chosen-time {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0 0 1.5rem;
  padding-left: .75rem;
  border-left: 4px solid var(--brass);
  color: var(--ink);
}

.field { display: block; margin-bottom: 1rem; }
.field-label { display: block; font-size: .85rem; color: var(--ink-soft); margin-bottom: .3rem; }
.field input, .field select, .field textarea {
  font: inherit;
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--ink);
  outline-offset: 0;
  border-color: var(--ink);
}
.field-error { color: var(--danger); font-size: .85rem; margin: -.7rem 0 1rem; }

.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.5rem; }
.form-actions button {
  font-family: var(--sans);
  font-size: .95rem;
  padding: .7rem 1.4rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.primary { background: var(--brass); border: 1px solid var(--brass); color: #fff; font-weight: 600; }
.primary:hover { background: #955c19; border-color: #955c19; }
.primary:disabled { opacity: .6; cursor: progress; }
.secondary { background: transparent; border: 1px solid var(--line); color: var(--ink-soft); }
.secondary:hover { border-color: var(--ink-soft); color: var(--ink); }

/* ----------------------------------------------------------------- status */

.status {
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  font-family: var(--sans);
}
.status.error { border-color: #e0bdb8; background: #fbf1ef; color: var(--danger); }
.status.error.inline { padding: .75rem 1rem; margin-bottom: 1rem; }
.status.success { border-color: var(--open-edge); background: #f0f8f6; }
.status.success h2 {
  font-family: var(--serif);
  color: var(--ink);
  font-size: 1.5rem;
  margin-top: 0;
}
.status button {
  font-family: var(--sans);
  margin-top: 1rem;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
}

/* ------------------------------------------------------------ admin table */

body.admin { font-family: var(--sans); }
body.admin main { max-width: 70rem; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }
body.admin h1 { font-family: var(--serif); font-size: 2rem; margin: 0 0 .6rem; letter-spacing: -0.02em; }
body.admin table {
  border-collapse: collapse;
  width: 100%;
  background: var(--card);
  font-size: .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
body.admin th, body.admin td {
  text-align: left;
  padding: .7rem .8rem;
  border-bottom: 1px solid var(--line-faint);
  vertical-align: top;
}
body.admin thead th {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
body.admin tbody tr:last-child td { border-bottom: 0; }
/* Status is the thing you scan this table for, so it gets an edge marker as well as a pill. */
body.admin tbody td:first-child { border-left: 4px solid transparent; font-variant-numeric: tabular-nums; }
body.admin tr.pending td:first-child { border-left-color: var(--brass); }
body.admin tr.confirmed td:first-child { border-left-color: #0f6b63; }
body.admin tr.declined td:first-child { border-left-color: var(--booked-hatch); }
body.admin tr.declined { color: var(--ink-soft); }
body.admin small { color: var(--ink-soft); }
body.admin code {
  font-size: .85em;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .1rem .3rem;
}
body.admin a { color: #0f6b63; }
.muted { color: var(--ink-soft); max-width: 46rem; }
.pill {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.pill.pending { background: var(--brass-soft); color: #7d4d13; border-color: #e3c18b; }
.pill.confirmed { background: #cfe7e2; color: #0b544d; border-color: var(--open-edge); }
.pill.declined { background: var(--booked); color: #46545a; border-color: var(--booked-hatch); }

/* ------------------------------------------------------------ narrow screens */

@media (max-width: 640px) {
  .page { padding: 1.75rem 1rem 3rem; }
  .lede { margin-bottom: 2rem; }
  .day-tabs { display: flex; }
  /* One day at a time; four columns are unreadable at this width. */
  .day-col:not(.is-active) { display: none; }
  .day-col .col-head { display: none; }
  .cell, .time-col .time-label { height: 2.5rem; }
  .time-col .col-head { display: none; }
  .booking-form { padding: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
