/* Civi-Times — a civic meeting calendar for Simcoe County. */

:root {
  color-scheme: light dark;
  --bg: #f7f6f3;
  --surface: #fffffe;
  --surface-2: #f0eee9;
  --ink: #1b1a17;
  --ink-2: #55524c;
  --ink-3: #8b8781;
  --line: #e0ddd6;
  --accent: #1c5d4a;
  --accent-ink: #ffffff;
  --warn: #8a4b12;
  --warn-bg: #fbf1e6;
  --stop: #8f2c2c;
  --stop-bg: #fbeceb;
  --speak: #1c4f7a;
  --speak-bg: #eaf2f9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 18, 14, .06), 0 4px 16px rgba(20, 18, 14, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141a;
    --surface: #1c1c24;
    --surface-2: #23232d;
    --ink: #eceaf2;
    --ink-2: #adaabb;
    --ink-3: #7c7a89;
    --line: #2e2e3a;
    --accent: #58c9a5;
    --accent-ink: #10231d;
    --warn: #e0a86a;
    --warn-bg: #2c2318;
    --stop: #f08b86;
    --stop-bg: #2e1a1a;
    --speak: #8ab8e0;
    --speak-bg: #17222e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

/*
 * The `hidden` attribute must always win.
 *
 * The browser's own `[hidden] { display: none }` is a user-agent rule, so ANY author
 * rule setting `display` on the same element defeats it — no extra specificity needed.
 * Several elements here are flex or grid containers that the script shows and hides via
 * `el.hidden`, and without this the attribute silently becomes a no-op: menus render
 * open and cannot be closed, and search cannot hide the rows it filters out.
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px 72px; }

/* ---- masthead ---- */
.masthead { border-bottom: 2px solid var(--ink); margin-bottom: 22px; padding: 30px 0 16px; }
.masthead h1 {
  margin: 0;
  font: 700 clamp(30px, 6vw, 46px)/1.05 ui-serif, Georgia, "Times New Roman", serif;
  letter-spacing: -.02em;
}
.masthead .tagline { margin: 8px 0 0; color: var(--ink-2); font-size: 15px; }
.masthead .stats { margin: 14px 0 0; color: var(--ink-3); font-size: 13px; }

/* ---- filters ---- */
.filters {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
  margin-bottom: 20px;
}
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.field { position: relative; }
.field > button {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font: inherit; font-size: 14px; cursor: pointer;
}
.field > button:hover { border-color: var(--ink-3); }
.field > button[aria-expanded="true"] { border-color: var(--accent); }
.field .count {
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 600;
  min-width: 18px; text-align: center;
}
.field .count[hidden] { display: none; }
.chev { color: var(--ink-3); font-size: 11px; }

.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  min-width: 282px; max-width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
  /* The search box and bulk actions stay put while only the list scrolls. */
  display: flex; flex-direction: column; max-height: min(420px, 70vh);
}

.menu-search { padding: 2px 2px 6px; flex: none; }
.menu-search input {
  width: 100%; box-sizing: border-box;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 10px; font: inherit; font-size: 14px;
}
.menu-search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.menu-search input::placeholder { color: var(--ink-3); }
/* Safari draws its own clear button that clashes with the field styling. */
.menu-search input::-webkit-search-cancel-button { appearance: none; }

.menu-options { overflow-y: auto; flex: 1 1 auto; }

.menu-group {
  padding: 9px 9px 5px; margin-top: 4px;
  border-top: 1px solid var(--line);
  color: var(--ink-3); font-size: 11.5px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
}
/* No rule above the first section — it would sit directly under the toolbar. */
.menu-options > .menu-group:first-child { border-top: none; margin-top: 0; padding-top: 4px; }

.menu-empty { margin: 0; padding: 16px 9px; text-align: center; color: var(--ink-3); font-size: 13.5px; }
.menu label {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 14px;
}
.menu label:hover { background: var(--surface-2); }
.menu label input { accent-color: var(--accent); flex: none; }
.menu .tally { margin-left: auto; color: var(--ink-3); font-size: 12px; padding-left: 8px; }
.menu .opt-label { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.menu .opt-note { color: var(--ink-3); font-size: 11.5px; }
.menu .menu-head {
  display: flex; gap: 12px; padding: 2px 9px 8px;
  border-bottom: 1px solid var(--line); margin-bottom: 4px; flex: none;
}
.menu .menu-head button {
  background: none; border: none; color: var(--accent);
  font: inherit; font-size: 13px; cursor: pointer; padding: 0;
}

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.toggle input { accent-color: var(--accent); }

.spacer { flex: 1 1 auto; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid transparent; border-radius: 999px;
  padding: 8px 16px; font: inherit; font-size: 14px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: var(--ink-3); filter: none; }

.active-filters { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 8px 4px 11px; font-size: 13px; color: var(--ink-2);
}
.pill button { background: none; border: none; color: var(--ink-3); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }
.pill button:hover { color: var(--stop); }
.pill.clear-all { cursor: pointer; padding: 4px 11px; font: inherit; font-size: 13px; color: var(--ink-2); }
.pill.clear-all:hover { border-color: var(--ink-3); color: var(--ink); }

/* ---- view switch ---- */
.viewswitch { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.viewswitch button {
  background: none; border: none; border-radius: 999px;
  padding: 6px 15px; font: inherit; font-size: 14px; color: var(--ink-2); cursor: pointer;
}
.viewswitch button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* ---- month navigation ---- */
.monthnav { display: flex; align-items: center; gap: 6px; margin: 0 0 16px; }
.monthnav h2 {
  margin: 0 4px; min-width: 12ch;
  font: 700 20px/1.2 ui-serif, Georgia, "Times New Roman", serif;
}
.monthnav button {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; width: 34px; height: 34px; font: inherit; font-size: 19px;
  line-height: 1; cursor: pointer; flex: none;
}
.monthnav button:hover { border-color: var(--ink-3); }
.monthnav .today-btn { width: auto; padding: 0 13px; font-size: 13.5px; }
.monthnav .month-count { margin-left: auto; color: var(--ink-3); font-size: 13px; }

/* ---- calendar grid ---- */
.cal-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.cal-weekday {
  background: var(--surface-2); color: var(--ink-3);
  padding: 7px 6px; text-align: center;
  font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
}
.cal-weekday abbr { text-decoration: none; border: none; }

.cal-day {
  background: var(--surface); border: none; margin: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 4px;
  min-height: 108px; padding: 6px; text-align: left;
  font: inherit; color: inherit; cursor: pointer;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day[aria-disabled="true"] { cursor: default; }
.cal-day[aria-disabled="true"]:hover { background: var(--surface); }
.cal-day.is-outside { background: var(--bg); }
.cal-day.is-outside .cal-daynum { color: var(--ink-3); opacity: .7; }
.cal-day.is-selected { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }

.cal-daynum { font-size: 12.5px; font-weight: 600; color: var(--ink-2); flex: none; }
.cal-day.is-today .cal-daynum {
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
}

.cal-chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip {
  display: flex; gap: 4px; align-items: baseline; min-width: 0;
  background: var(--surface-2); border-left: 2px solid var(--accent);
  border-radius: 3px; padding: 2px 4px; font-size: 11.5px; line-height: 1.3;
}
.chip-time { color: var(--ink-3); font-variant-numeric: tabular-nums; flex: none; }
.chip-place { font-weight: 600; flex: none; max-width: 9ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.is-cancelled { border-left-color: var(--stop); opacity: .65; }
.chip.is-cancelled .chip-title { text-decoration: line-through; }
.chip-more { color: var(--ink-3); font-size: 11px; padding-left: 4px; }

/* Dots replace chips where a cell is too narrow for text — see the media query below. */
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; }
.cal-dots .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-dots .dot.is-cancelled { background: var(--stop); }

.cal-empty { text-align: center; color: var(--ink-2); padding: 22px 12px; margin: 0; }
.linkish {
  background: none; border: none; padding: 0; font: inherit;
  color: var(--accent); text-decoration: underline; cursor: pointer;
}

/* ---- day modal ----
   A <dialog> is display:none until [open], so the display rule is scoped to [open].
   Setting display on the bare class would defeat the closed state entirely. */
.modal {
  padding: 0; border: none; background: none;
  max-width: none; max-height: none; width: 100%; height: 100%;
  overflow: hidden;
}
.modal[open] { display: flex; align-items: center; justify-content: center; }
.modal::backdrop { background: rgba(10, 9, 8, .55); backdrop-filter: blur(2px); }

.modal-inner {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  width: min(560px, calc(100vw - 32px)); max-height: min(76vh, 720px);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line); flex: none;
}
.modal-head h2 {
  margin: 0; flex: 1 1 auto;
  font: 700 19px/1.25 ui-serif, Georgia, "Times New Roman", serif;
}
.modal-close {
  background: none; border: none; color: var(--ink-3); cursor: pointer;
  font-size: 26px; line-height: 1; padding: 0 4px; flex: none; border-radius: 6px;
}
.modal-close:hover { color: var(--ink); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.modal-body { padding: 16px 20px 20px; overflow-y: auto; flex: 1 1 auto; }
.modal-body .event { box-shadow: none; }
.modal-body .event:last-child { margin-bottom: 0; }
.modal-body .cal-empty { padding: 12px 0; }

/* The page behind a modal must not scroll under it. */
body.modal-open { overflow: hidden; }

/* ---- day groups ---- */
.day { margin-bottom: 26px; }
.day-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 0 0 10px; padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.day-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.day-head .rel { color: var(--ink-3); font-size: 13px; }

/* ---- event cards ---- */
.event {
  display: grid; grid-template-columns: 88px 1fr; gap: 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 9px;
  box-shadow: var(--shadow);
}
.event .time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; color: var(--ink); }
.event .time .tbd { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); }
.event h3 { margin: 0 0 3px; font-size: 16.5px; font-weight: 600; line-height: 1.3; }
.event h3 a { text-decoration: none; }
.event h3 a:hover { text-decoration: underline; text-underline-offset: 2px; }
.event .meta { color: var(--ink-2); font-size: 13.5px; display: flex; flex-wrap: wrap; gap: 4px 9px; }
.event .meta .jur { font-weight: 600; color: var(--ink); }
.event .docs { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.event .docs a {
  font-size: 12.5px; text-decoration: none; color: var(--accent);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
}
.event .docs a:hover { border-color: var(--accent); }
.event.is-cancelled { opacity: .72; }
.event.is-cancelled h3 { text-decoration: line-through; text-decoration-thickness: 1.5px; }

.tag { border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.tag.cancelled { background: var(--stop-bg); color: var(--stop); }
.tag.moved { background: var(--warn-bg); color: var(--warn); }
.tag.speak { background: var(--speak-bg); color: var(--speak); }
.tag.package { background: var(--surface-2); color: var(--ink-3); }

.empty { text-align: center; padding: 64px 20px; color: var(--ink-2); }
.empty p { margin: 0 0 14px; }
.loading { text-align: center; padding: 64px 20px; color: var(--ink-3); }

.sheet {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(10, 9, 8, .5); padding: 20px;
}
.sheet[hidden] { display: none; }
.sheet-inner {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  padding: 24px; max-width: 520px; width: 100%;
}
.sheet-inner h2 { margin: 0 0 8px; font-size: 19px; }
.sheet-inner p { margin: 0 0 14px; color: var(--ink-2); font-size: 14px; }
.sheet-inner code {
  display: block; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 11px; font-size: 12.5px; word-break: break-all; margin-bottom: 14px;
}
.sheet-actions { display: flex; gap: 9px; flex-wrap: wrap; }

footer { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 13px; }
footer a { color: var(--ink-2); }

/* ---- single event page ---- */
.event-page { padding: 0 20px 60px; }
.event-page .topbar { max-width: 680px; margin: 0 auto; padding: 22px 0; }
.event-page .home { color: var(--ink-2); text-decoration: none; font-size: 14px; }
.event-page .card {
  max-width: 680px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px; box-shadow: var(--shadow);
}
.event-page .eyebrow { margin: 0 0 6px; color: var(--ink-2); font-size: 13.5px; font-weight: 600; }
.event-page h1 { margin: 0 0 10px; font: 700 27px/1.2 ui-serif, Georgia, serif; }
.event-page .when { margin: 0 0 3px; font-size: 17px; font-weight: 600; }
.event-page .where { margin: 0 0 16px; color: var(--ink-2); }
.event-page .notice { border-radius: 8px; padding: 11px 13px; font-size: 14px; margin: 0 0 11px; }
.event-page .notice.cancelled { background: var(--stop-bg); color: var(--stop); font-weight: 600; }
.event-page .notice.moved { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.event-page .notice.speak { background: var(--speak-bg); color: var(--speak); }
.event-page .actions { display: flex; flex-wrap: wrap; gap: 9px; margin: 18px 0 0; }
.event-page .subscribe { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--line); font-size: 14px; }

@media (max-width: 760px) {
  /* Chips cannot be read in a cell this narrow, so show dots and let tapping a day
     open the full list underneath the grid. */
  .cal-day { min-height: 62px; padding: 5px 3px; align-items: center; gap: 3px; }
  .cal-chips { display: none; }
  .cal-dots { display: flex; justify-content: center; }
  .cal-daynum { font-size: 12px; }
  .monthnav h2 { font-size: 17px; min-width: 0; }
  .monthnav .month-count { display: none; }
}

@media (max-width: 620px) {
  .menu { position: fixed; left: 12px; right: 12px; top: auto; min-width: 0; max-width: none; }
  .modal[open] { align-items: flex-end; }
  .modal-inner {
    width: 100%; max-height: 82vh;
    border-radius: 16px 16px 0 0; border-bottom: none;
  }

  .event { grid-template-columns: 68px 1fr; gap: 12px; padding: 12px 13px; }
  .event .time { font-size: 14px; }
  .filters { padding: 10px 0; }
  .event-page .card { padding: 22px 18px; }
}
