:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #2563eb;

  /* Day-type identity: #F9C74F free, #90BE6D open, #F9844A booked, #277DA1 buffer.
     Ink is darkened from each until the label clears WCAG AA on its own fill. */
  --free: #866b2b;
  --free-bg: #fef4dc;
  --open: #567241;
  --open-bg: #e9f2e2;
  --booked: #9f542f;
  --booked-bg: #fee6db;
  --buffer: #226c8a;
  --buffer-bg: #d4e5ec;

  /* Source colours, used where a swatch carries no text and should stay vivid. */
  --free-key: #f9c74f;
  --open-key: #90be6d;
  --booked-key: #f9844a;
  --buffer-key: #277da1;

  /* Preferred days on the client view: same green as Available, deeper tint. */
  --pref: #485f36;
  --pref-bg: #c2dbaf;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --tag: #be185d;
  --tag-KIDS: #be185d;
  --tag-ENRG: #6d28d9;
  --tag-CPB: #0f766e;
  --tag-MQCE: #334155;

  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* Dark values are defined once here. A blocking script in <head> stamps data-theme
   on <html> from the saved preference, falling back to the system setting, so the
   palette never has to be maintained in two places. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a1f;
  --surface-2: #1e222a;
  --border: #2b313b;
  /*
   * The quieter rule inside a card. It was missing from this palette entirely — declared
   * once in shell.css against the light theme and never overridden — so every
   * `border: 1px solid var(--line)` in the app drew #eaedf1 in dark mode: a near-white
   * hairline where a barely-there one was meant. Twenty-four rules, including every
   * `.part` divider on the session sheet.
   *
   * Quieter than --border means closer to the surface, which is darker here and lighter
   * in the light theme. That inversion is exactly why it needed declaring rather than
   * inheriting.
   */
  --line: #232830;
  --text: #e6e8eb;
  --muted: #9099a8;
  --accent: #60a5fa;

  /* Dark mode shows the source colours almost neat as ink, on deep tinted fills. */
  --free: #f9c74f;
  --free-bg: #443d29;
  --open: #90be6d;
  --open-bg: #2f3b2f;
  --booked: #f9844a;
  --booked-bg: #442f28;
  --buffer: #5b9cb8;
  --buffer-bg: #1a2e39;

  --free-key: #f9c74f;
  --open-key: #90be6d;
  --booked-key: #f9844a;
  --buffer-key: #4a9ec4;

  --pref: #bcd8a7;
  --pref-bg: #4a5f40;
  --danger: #fca5a5;
  --danger-bg: #3f1616;
  --tag: #f472b6;
  --tag-KIDS: #db2777;
  --tag-ENRG: #7c3aed;
  --tag-CPB: #0d9488;
  --tag-MQCE: #475569;
}

/*
 * `hidden` means hidden. This is the fourth time it has not.
 *
 * The browser hides `[hidden]` from its own stylesheet, and any author rule that sets
 * `display` beats it outright — specificity never enters into it, because author styles
 * always win over the user-agent sheet. So a rule as ordinary as
 * `.chip{display:inline-block}` quietly un-hid every chip the JavaScript had just
 * hidden, and the session sheet showed an AIR TRAVEL flag on a venue eight miles from
 * Clay's house, on a day whose record says no air travel in all three places it is
 * stored.
 *
 * The first three were patched one component at a time — .sect, .field, .ro, .datesbox —
 * which is exactly how there came to be a fourth. One rule, for everything, so the
 * attribute means what it says and no component has to remember.
 *
 * It lives here rather than in shell.css because this is the sheet every page loads.
 * start.html, the only page a client ever sees, loads this one and nothing else.
 */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 20px 60px; }

/* ---- header ---- */
header.bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 0 18px;
}

/*
 * The application header.
 *
 * The same bar on every page, so moving between them does not mean re-reading the
 * navigation to find out what exists. The mark returns to the planner; the tabs are in
 * a fixed order; the page you are on is underlined rather than merely bolder, because
 * bold on its own is not a strong enough signal at this size.
 */
.appbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 0 0; border-bottom: 1px solid var(--border); margin-bottom: 18px;
}
.appbar .mark {
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em; color: var(--text);
  text-decoration: none; padding-bottom: 12px;
}
.appbar .tabs { display: flex; gap: 2px; margin-right: auto; flex-wrap: wrap; }
/*
 * Every item in the bar, in one rule — the links and the Setup menu together.
 *
 * They were styled apart, and drifted: this file turned the bar into underline tabs with
 * `4px 10px 12px` and a 2px bottom border, while the Setup summary kept the older pill
 * padding of `6px 12px` from shell.css. Two pixels of padding is two pixels of text, so
 * "Setup" sat lower than its three neighbours and carried no underline when it was the
 * page you were on.
 *
 * One selector list is the fix and also the guard. A tab and a menu that must look
 * identical cannot be described in two places and stay identical — the only way they keep
 * matching is by being the same rule.
 */
.appbar .tabs a,
.appbar .tabs .setup > summary {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 550; color: var(--muted); text-decoration: none;
  padding: 4px 10px 12px; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .12s, border-color .12s;
}
.appbar .tabs a:hover,
.appbar .tabs .setup > summary:hover { color: var(--text); }
/* Only the colour of the marker — whatever the bar looks like otherwise is untouched. */
.appbar .tabs a[aria-current="page"],
.appbar .tabs .setup > summary[aria-current="page"] {
  color: var(--text); border-bottom-color: var(--accent);
}
.appbar .badge {
  font-size: 10.5px; font-weight: 700; line-height: 1; padding: 3px 6px;
  border-radius: 20px; background: var(--booked-bg); color: var(--booked);
}
.appbar > .btn { margin-bottom: 11px; font-size: 12.5px; padding: 5px 10px; }
@media (max-width: 44rem) {
  .appbar { gap: 10px; }
  .appbar .tabs a,
  .appbar .tabs .setup > summary { padding: 4px 8px 10px; font-size: 12.5px; }
  .appbar > .btn { display: none; }
}

/* The planner's month controls sit under the bar; the month is its own title. */
.monthbar { padding-top: 0; padding-bottom: 14px; }

.nav-month { display: flex; align-items: center; gap: 6px; }
.nav-month h2 { margin: 0; font-size: 17px; min-width: 190px; text-align: center; font-weight: 600; }

.btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; font-size: 14px;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
select.btn { padding: 6px 8px; border-radius: 8px; background: var(--surface); }

/* Theme picker sits below the calendar as a quiet page-level setting. */
.themebar {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted);
}
.themebar select.btn { font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- brush palette ---- */
.palette { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.brush {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 6px 14px 6px 10px; font-size: 13.5px; font-weight: 500;
}
.brush .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.brush kbd {
  font: 600 10.5px var(--font); background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; margin-left: 2px;
}
.brush[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.brush[data-type="free"]   .dot { background: var(--free-key); }
.brush[data-type="open"]   .dot { background: var(--open-key); }
.brush[data-type="booked"] .dot { background: var(--booked-key); }
.brush[data-type="buffer"] .dot { background: var(--buffer-key); }
.brush[data-type="clear"]  .dot { background: var(--muted); }

.hint { color: var(--muted); font-size: 12.5px; margin-left: auto; }
/* Day types on one row, tags on their own beneath. */
.palette-tags { margin-top: -4px; }
.rowlabel {
  font-size: 11px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); margin-right: 2px;
}

/* Tags sit alongside day types but are a separate axis, so they read differently. */
.brush.tag { border-style: dashed; }
.brush.tag .dot { background: var(--tag); border-radius: 999px; }
.brush.tag[aria-pressed="true"] {
  border-style: solid; border-color: var(--tag);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tag) 20%, transparent);
}

.badges { position: absolute; top: 6px; right: 7px; display: flex; align-items: center; gap: 4px; }
.chip {
  font-size: 9px; font-weight: 750; letter-spacing: .06em;
  background: var(--tag); color: #fff;
  border-radius: 4px; padding: 2px 5px; line-height: 1.25;
}
.chip[data-tag="KIDS"]  { background: var(--tag-KIDS); }
.chip[data-tag="ENRG"]  { background: var(--tag-ENRG); }
.chip[data-tag="CPB"]   { background: var(--tag-CPB); }
.chip[data-tag="M/QCE"] { background: var(--tag-MQCE); }

.brush.tag[data-tag="KIDS"]  .dot { background: var(--tag-KIDS); }
.brush.tag[data-tag="ENRG"]  .dot { background: var(--tag-ENRG); }
.brush.tag[data-tag="CPB"]   .dot { background: var(--tag-CPB); }
.brush.tag[data-tag="M/QCE"] .dot { background: var(--tag-MQCE); }

/* Up to four chips plus two status icons must not overflow a day cell. */
.badges { flex-wrap: wrap; justify-content: flex-end; max-width: 74%; row-gap: 2px; }

/* ---- grid ---- */
.weekhead, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekhead { margin-bottom: 6px; }
.weekhead div {
  text-align: center; font-size: 11px; font-weight: 650; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); padding: 4px 0;
}

.day {
  position: relative; min-height: 92px; text-align: left;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 7px 8px;
  display: flex; flex-direction: column; gap: 3px;
  transition: transform .08s, box-shadow .12s, border-color .12s;
  user-select: none; overflow: hidden;
}
.day:hover { border-color: var(--accent); }
.day:active { transform: scale(.985); }
.day.out { opacity: .38; }
.day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.day .num { font-size: 13px; font-weight: 620; }
.day .label { font-size: 10.5px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; }
.day .meta { font-size: 11px; color: var(--muted); margin-top: auto; }
.day .note {
  font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Subtle by design — supporting detail, not a second status line. */
.day .loc {
  font-size: 10.5px; color: var(--muted); opacity: .85; font-style: italic;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.day[data-type="free"]   { background: var(--free-bg);   border-color: color-mix(in srgb, var(--free) 45%, transparent); }
.day[data-type="free"]   .label { color: var(--free); }
.day[data-type="open"]   { background: var(--open-bg);   border-color: color-mix(in srgb, var(--open) 45%, transparent); border-style: dashed; }
.day[data-type="open"]   .label { color: var(--open); }
.day[data-type="booked"] { background: var(--booked-bg); border-color: color-mix(in srgb, var(--booked) 55%, transparent); }
.day[data-type="booked"] .label { color: var(--booked); }

.day[data-type="buffer"] { background: var(--buffer-bg); border-color: color-mix(in srgb, var(--buffer) 45%, transparent); }
.day[data-type="buffer"] .label { color: var(--buffer); }

.day .warn { color: var(--danger); font-size: 12px; line-height: 1; }
/* Same size and placement as the conflict marker, in a calmer colour. */
.day .air { color: var(--buffer); font-size: 12px; line-height: 1; }
.day .sent { color: var(--booked); font-size: 12px; line-height: 1; }
#mOffered .offered { display: grid; gap: 4px; font-size: 13px; }
#mOffered .offered > div { display: flex; justify-content: space-between; gap: 12px; }
#mOffered .offered span { color: var(--muted, inherit); opacity: .8; }
#mOffered .offered .note { display: block; opacity: .8; }

label.check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text); white-space: nowrap; padding-bottom: 8px;
}
label.check input { margin: 0; }

/* ---- counters ---- */
.counters { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 10px; margin: 20px 0 6px; }
.counter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.counter .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.counter .v { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; margin-top: 3px; }
.counter .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.meter { height: 5px; border-radius: 3px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; }

/* ---- panels ---- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-top: 18px;
}
.panel h3 { margin: 0 0 12px; font-size: 14px; font-weight: 650; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 14px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.err { background: var(--danger-bg); color: var(--danger); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 10px; }
.pill { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.on { background: var(--free-bg); color: var(--free); border-color: color-mix(in srgb, var(--free) 40%, transparent); }
.pill.off { background: var(--surface-2); }

/* ---- modal ---- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 0; max-width: 480px; width: calc(100% - 32px); box-shadow: 0 18px 50px rgba(0,0,0,.28);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .head { padding: 16px 18px 0; font-weight: 650; font-size: 15px; }
dialog .body { padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
dialog .foot { padding: 12px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; }
.evlist { max-height: 170px; overflow: auto; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.evlist div { display: flex; gap: 8px; }
.evlist b { font-weight: 550; color: var(--text); font-variant-numeric: tabular-nums; flex: none; }

@media (max-width: 720px) {
  .wrap { padding: 12px 12px 40px; }
  .day { min-height: 64px; padding: 5px 6px; }
  .day .meta, .day .note, .day .loc { display: none; }
  .chip { font-size: 8px; padding: 1px 4px; }
  .hint { display: none; }

  /* Compact the brush row so the grid still lands above the fold. */
  .palette { gap: 6px; margin-bottom: 10px; }
  .brush { padding: 5px 10px 5px 8px; font-size: 12.5px; gap: 6px; }
  .brush kbd { display: none; }

  header.bar { gap: 8px; padding: 8px 0 12px; }
    .nav-month h2 { min-width: 0; font-size: 15px; }
  .weekhead div { font-size: 10px; }
  .counters { grid-template-columns: repeat(2, 1fr); }
}

/* Calendar include/exclude checklist */
.callist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; margin-bottom: 14px; }
.callist label {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg);
}
.callist label:has(input:not(:checked)) { opacity: .5; }
.callist input { margin: 0; }
.callist .who { color: var(--muted); font-size: 11px; margin-left: auto; text-transform: uppercase; letter-spacing: .04em; }
.callist .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.danger:hover { background: var(--danger-bg); }
dialog .foot { justify-content: space-between; }
dialog .foot .spacer { flex: 1; }
.bookinfo {
  font-size: 12.5px; color: var(--muted);
  background: var(--surface-2); border-radius: 7px; padding: 8px 10px;
}
.bookinfo b { color: var(--text); font-weight: 600; }

/* Session-check warnings */
.alert {
  background: var(--danger-bg); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--text); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
}
.alert h4 { margin: 0 0 8px; font-size: 13.5px; color: var(--danger); }
.alert .item { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; flex-wrap: wrap; }
.alert .item + .item { border-top: 1px solid color-mix(in srgb, var(--danger) 15%, transparent); }
.alert .when { font-weight: 650; min-width: 92px; }
.alert .what { color: var(--muted); flex: 1; min-width: 180px; }
.alert .btn { padding: 4px 10px; font-size: 12.5px; }

/* ---------- an on/off switch ---------- */

/*
 * For a setting that acts the moment it is moved.
 *
 * A tick box reads as "part of a form" — something you set and then save — and the holds
 * one genuinely was, which is why ticking it appeared to do nothing at all. A switch
 * reads as a thing that is on or off right now, which is what this actually is.
 */
.switchrow { display: flex; align-items: center; gap: 12px; margin: 2px 0 10px; }

.switch {
  flex: none; width: 46px; height: 26px; padding: 0; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
  position: relative; transition: background .15s ease, border-color .15s ease;
}
.switch .knob {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .15s ease;
}
.switch[aria-checked="true"] { background: var(--open); border-color: var(--open); }
.switch[aria-checked="true"] .knob { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch[disabled] { opacity: .5; cursor: default; }

.switchsay { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.switchsay label { font-weight: 650; cursor: pointer; }
.switchsay .hint { margin-left: 0; }

/* The settings that only matter once it is on. */
.holdmore { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

/*
 * The message as it will arrive. Deliberately plain: an email is read in somebody
 * else's client, and dressing the preview in this app's typography would show
 * something the recipient will never see. Paragraph spacing, a readable measure, and
 * nothing else. Here rather than on the Emails page because every box an email is
 * typed into can now show it.
 */
.mailbody { font-size: 12.5px; line-height: 1.55; max-width: 40rem; }
.mailbody p { margin: 0 0 0.85em; }
.mailbody p:last-child { margin-bottom: 0; }
.mailbody ul, .mailbody ol { margin: 0 0 0.85em; padding-left: 1.4em; }
.mailbody li { margin: 0.2em 0; }
.mailbody strong { font-weight: 680; }
.mailbody a { text-decoration: underline; }
.mailbody h1, .mailbody h2, .mailbody h3 { margin: 0 0 0.5em; line-height: 1.3; }
.mailbody h1 { font-size: 17px; } .mailbody h2 { font-size: 15px; } .mailbody h3 { font-size: 13.5px; }

/* What the body accepts, said where it is typed — a vocabulary nobody is told about
   is a vocabulary nobody uses. */
.mdhint { font-size: 11px; color: var(--muted); margin: 5px 0 0; line-height: 1.6; }
.mdhint code { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 10.5px;
  background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

/*
 * The preview popover. Centred rather than anchored, because the boxes it is opened
 * from sit inside a modal dialog and the popover has to clear it; the top layer does
 * that, and the backdrop says what it is on top of.
 */
#mdPreview { position: fixed; inset: 0; margin: auto; width: min(44rem, calc(100vw - 32px));
  max-height: min(80vh, 44rem); overflow: auto; padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  box-shadow: 0 18px 48px rgba(0,0,0,.28); }
#mdPreview::backdrop { background: rgba(0,0,0,.25); }
#mdPreview .head { padding: 12px 16px 8px; font-weight: 650; font-size: 14px; display: flex;
  gap: 10px; align-items: baseline; border-bottom: 1px solid var(--border); }
#mdPreview .head .tools { font-weight: 400; flex: 1; }
#mdPreview .mailbody { padding: 14px 16px; }
#mdPreview .mdhint { padding: 0 16px 12px; }
