:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f27;
  --muted: #5c6472;
  --border: #dfe3ea;
  --accent: #7b3ff2;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(20, 24, 33, .06), 0 4px 16px rgba(20, 24, 33, .06);
  --radius: 12px;
  --radius-sm: 8px;

  /* Type accent colours */
  --t-talk: #2f6fed;
  --t-workshop: #0e9f6e;
  --t-familyworkshop: #d97706;
  --t-performance: #db2777;
  --t-music: #8b5cf6;
  --t-djset: #e11d48;
  --t-meetup: #0891b2;
  --t-film: #6b7280;
}

html[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #181c24;
  --surface-2: #1f2530;
  --text: #e8ebf1;
  --muted: #9aa4b5;
  --border: #2a313d;
  --accent: #a377ff;
  --accent-text: #12151b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);

  --t-talk: #6ea0ff;
  --t-workshop: #35d69b;
  --t-familyworkshop: #f6ad55;
  --t-performance: #f472b6;
  --t-music: #b79bff;
  --t-djset: #fb7185;
  --t-meetup: #38bdf8;
  --t-film: #9ca3af;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0f1218;
    --surface: #181c24;
    --surface-2: #1f2530;
    --text: #e8ebf1;
    --muted: #9aa4b5;
    --border: #2a313d;
    --accent: #a377ff;
    --accent-text: #12151b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
    --t-talk: #6ea0ff;
    --t-workshop: #35d69b;
    --t-familyworkshop: #f6ad55;
    --t-performance: #f472b6;
    --t-music: #b79bff;
    --t-djset: #fb7185;
    --t-meetup: #38bdf8;
    --t-film: #9ca3af;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -.01em;
}
.bolt { color: var(--accent); }
.tagline {
  margin: 2px 0 0;
  font-size: .85rem;
  color: var(--muted);
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}

/* ---------- Filters ---------- */
.filters {
  position: sticky;
  top: 84px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 104px);
  overflow-y: auto;
}
.filters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.filters-head h2 { margin: 0; font-size: 1rem; }
.filters-head-actions { display: flex; align-items: center; gap: 10px; }
/* The in-panel Done button only exists in the mobile drawer. */
.filters-close { display: none; padding: 6px 16px; }
.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: .85rem;
  padding: 4px;
}
.text-btn:hover { text-decoration: underline; }

/* ---------- Saved filters (chip bar on the results page) ---------- */
.saved-bar { margin-bottom: 16px; }
.saved-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
/* Each saved filter is one rounded pill: name (apply) + rename + delete. */
.saved-item {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.saved-apply {
  background: none;
  border: none;
  color: var(--text);
  font-size: .9rem;
  padding: 8px 14px;
  cursor: pointer;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.saved-apply:hover { color: var(--accent); }
.save-filter { padding: 4px 0; }

/* Manage saved filters inside the filter pane (rename / delete). */
.saved-manage {
  list-style: none;
  margin: 0;
  padding: 4px 0 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.saved-manage-item { display: flex; align-items: center; gap: 4px; }
.saved-manage-item .saved-apply {
  flex: 1;
  min-width: 0;
  max-width: none;
  text-align: left;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}
.saved-manage-item .saved-apply:hover { background: var(--surface-2); }
.saved-rename,
.saved-del {
  flex: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  padding: 6px;
  border-radius: 6px;
}
.saved-rename:hover { color: var(--accent); background: var(--surface-2); }
.saved-del:hover { color: var(--t-djset); background: var(--surface-2); }

.field { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 6px;
}
#search {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
}
#search:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  cursor: pointer;
  font-size: .92rem;
}
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

.facet { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 4px; }
.facet summary {
  cursor: pointer;
  padding: 8px 0;
  font-weight: 600;
  font-size: .92rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.facet summary::-webkit-details-marker { display: none; }
.facet summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform .15s;
  font-size: .8rem;
}
.facet[open] summary::before { transform: rotate(90deg); }
.facet-count { color: var(--muted); font-weight: 400; font-size: .82rem; }
.facet-body { padding: 4px 0 10px; }

.facet-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0 4px;
}
.facet-shortcuts button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent);
  font-size: .78rem;
  padding: 3px 10px;
  cursor: pointer;
}
.facet-shortcuts button:hover {
  background: var(--surface);
  border-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9rem;
}
.check:hover { background: var(--surface-2); }
.check input { width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.check .name { flex: 1; }
.check .num { color: var(--muted); font-size: .8rem; }
.check .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
}

/* ---------- Sync / import favourites ---------- */
.import-body { padding-top: 4px; }
.import-help { font-size: .82rem; color: var(--muted); margin: 0 0 8px; }
.import-help strong { color: var(--text); }
.import-help code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .95em;
}
#token-input,
#import-text {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .78rem;
  line-height: 1.4;
}
#import-text { resize: vertical; }
#token-input:focus,
#import-text:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.import-actions {
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.import-actions .btn { flex: 1; }
.import-actions .text-btn { flex: none; white-space: nowrap; }
.import-paste {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.import-paste summary {
  cursor: pointer;
  font-size: .85rem;
  color: var(--accent);
  padding: 2px 0;
}
.sync-info {
  margin: 0 0 8px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--t-workshop);
}
.import-status { margin: 8px 0 0; font-size: .82rem; color: var(--t-workshop); }
.import-status.error { color: var(--t-djset); }
.import-status .undo-btn { font-size: .82rem; padding: 0 2px; }

/* ---------- Results ---------- */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.count { margin: 0; font-size: .95rem; color: var(--muted); }
.count strong { color: var(--text); }
.results-bar-actions { display: flex; gap: 8px; }
.btn {
  padding: 8px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  font-weight: 500;
}
.btn.ghost:hover { background: var(--surface-2); }
.btn.copied { background: var(--t-workshop); border-color: var(--t-workshop); color: #fff; }

.status {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: .9rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.status.error { border-color: var(--t-djset); background: color-mix(in srgb, var(--t-djset) 12%, var(--surface)); }

/* ---------- Schedule ---------- */
.day-group { margin-bottom: 28px; }
.day-head {
  position: sticky;
  top: 72px;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(6px);
  padding: 8px 2px;
  margin: 0 0 10px;
  font-size: 1.05rem;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.day-head .day-n { color: var(--muted); font-weight: 400; font-size: .85rem; }

.card {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--type-color, var(--border));
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card-time {
  text-align: right;
  padding-top: 2px;
}
.card-time .start { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.card-time .end { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.card-time .dur { color: var(--muted); font-size: .72rem; margin-top: 3px; }

.card-body { min-width: 0; }
.card-top { display: flex; align-items: flex-start; gap: 8px; }
.card-title {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.3;
  flex: 1;
}
.card-title a { color: var(--text); text-decoration: none; }
.card-title a:hover { color: var(--accent); text-decoration: underline; }

.fav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--border);
  padding: 0 2px;
  flex: none;
}
.fav-btn:hover { color: var(--t-familyworkshop); }
.fav-btn.on { color: var(--t-familyworkshop); }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 6px 0;
  font-size: .85rem;
  color: var(--muted);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  color: #fff;
  background: var(--type-color, var(--muted));
  text-transform: capitalize;
}
.speaker { color: var(--text); font-weight: 500; }
.venue-link { color: var(--muted); text-decoration: none; }
.venue-link:hover { color: var(--accent); text-decoration: underline; }

.card-desc {
  margin: 4px 0 0;
  font-size: .9rem;
  color: var(--text);
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.tag.warn { color: var(--t-familyworkshop); border-color: color-mix(in srgb, var(--t-familyworkshop) 40%, var(--border)); }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty h3 { margin: 0 0 6px; color: var(--text); }

/* ---------- Footer ---------- */
.site-footer {
  max-width: 1200px;
  margin: 20px auto;
  padding: 20px;
  color: var(--muted);
  font-size: .82rem;
  border-top: 1px solid var(--border);
}
.site-footer p { margin: 0; }

/* ---------- Mobile filters drawer ---------- */
.fab {
  display: none;
  position: fixed;
  right: 16px;
  /* Keep clear of the iOS home indicator / Safari bottom bar. */
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 60; /* above the drawer so it can close it */
  padding: 12px 20px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  box-shadow: var(--shadow);
  cursor: pointer;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .filters {
    position: fixed;
    inset: 0;
    z-index: 50;
    border-radius: 0;
    max-height: none;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .filters.open { transform: none; }
  .fab { display: block; }
  .day-head { top: 64px; }

  /* Always-visible close control at the top of the drawer, so it never depends
     on the floating button (which iOS chrome can hide). */
  .filters-close { display: inline-block; }
  .filters-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface);
    padding: 4px 0 10px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 480px) {
  .card { grid-template-columns: 1fr; gap: 4px; }
  .card-time { text-align: left; display: flex; gap: 8px; align-items: baseline; }
  .card-time .dur { display: none; }
}
