:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --chip: #1e3a5f;
  --chip-active: #0369a1;
  --link: #7dd3fc;
  --today: rgba(56, 189, 248, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --header-height: 12rem;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem 0.75rem;
  z-index: 100;
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: flex-start;
  gap: 0.65rem 1rem;
  margin-bottom: 0.75rem;
}

.header-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  flex-shrink: 0;
}

.header-subtitle,
.header-note,
.header-contact {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}

.header-contact a {
  color: var(--link);
  white-space: nowrap;
}

.filter-panel-wrap {
  margin-bottom: 0.5rem;
}

.filter-toggle {
  display: none;
  width: 100%;
  margin-bottom: 0.35rem;
}

.filter-panel {
  margin-bottom: 0.5rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.filter-group-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 0.25rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--chip);
  color: var(--text);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chip:hover {
  border-color: var(--accent);
}

.chip.active {
  background: var(--chip-active);
  border-color: var(--accent);
}

.week-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.week-nav h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  min-width: 14rem;
  text-align: center;
}

.week-search {
  flex: 1 1 12rem;
  min-width: 10rem;
  max-width: 22rem;
  padding: 0.45rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.week-search::placeholder {
  color: var(--muted);
}

.week-search:focus {
  outline: none;
  border-color: var(--accent);
}

.week-search::-webkit-search-cancel-button {
  cursor: pointer;
}

button {
  font-family: inherit;
  background: var(--accent-dim);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
}

button:hover {
  background: var(--accent);
}

button.secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}

button.secondary:hover {
  border-color: var(--accent);
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.25rem;
  flex-wrap: wrap;
}

.result-count {
  font-size: 0.82rem;
  color: var(--muted);
}

main {
  padding: 0.75rem 1.25rem 2rem;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  text-align: left;
  padding: 0.65rem 0.75rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

tbody td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.is-today {
  background: var(--today);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

td.time {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

td.event-name {
  font-weight: 600;
}

td.recurring {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

td.description {
  color: var(--muted);
  max-width: 28rem;
}

td a {
  color: var(--link);
  word-break: break-all;
}

.loading,
.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem !important;
}

.schedule-cards {
  display: none;
  flex-direction: column;
  gap: 0.65rem;
}

.schedule-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.schedule-card.is-today {
  border-color: var(--accent);
  background: var(--today);
}

.card-main {
  padding: 0.85rem 1rem;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.card-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.3;
}

.card-time {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.card-meta {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.card-details {
  border-top: 1px solid var(--border);
  padding: 0 1rem 0.65rem;
}

.card-details summary {
  cursor: pointer;
  padding: 0.55rem 0;
  font-size: 0.82rem;
  color: var(--link);
  list-style: none;
}

.card-details summary::-webkit-details-marker {
  display: none;
}

.card-details p {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.card-details a {
  color: var(--link);
  word-break: break-all;
}

/* Desktop: fixed header, page scroll, column headers stick under header */
@media (min-width: 769px) {
  .header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }

  main {
    padding-top: calc(var(--header-height) + 0.75rem);
  }

  .filter-toggle {
    display: none !important;
  }

  .filter-panel {
    display: block !important;
  }

  .filter-panel[hidden] {
    display: block !important;
  }

  .desktop-only {
    display: block;
  }

  .schedule-cards {
    display: none !important;
  }

  .table-wrap {
    overflow: visible;
  }

  .table-wrap thead th {
    position: sticky;
    top: var(--header-height);
    z-index: 5;
    box-shadow: 0 1px 0 var(--border);
  }
}

/* Phone: sticky header, scrollable filter panel, cards */
@media (max-width: 768px) {
  .header {
    position: sticky;
    top: 0;
  }

  .header-title {
    font-size: 1.05rem;
  }

  .header-subtitle,
  .header-note,
  .header-contact {
    font-size: 0.78rem;
    padding-left: 0.65rem;
  }

  main {
    padding: 0.75rem 0.85rem 2rem;
  }

  .filter-toggle {
    display: block;
  }

  .filter-panel[hidden] {
    display: none !important;
  }

  .filter-panel:not([hidden]) {
    display: block;
    max-height: min(45vh, 280px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem;
    background: var(--surface2);
  }

  .desktop-only {
    display: none !important;
  }

  .schedule-cards {
    display: flex !important;
  }

  .week-nav h2 {
    width: 100%;
    order: -1;
    min-width: 0;
    font-size: 0.95rem;
  }

  .week-search {
    flex: 1 1 100%;
    max-width: none;
    margin-left: 0;
    min-height: 44px;
  }

  button,
  .chip {
    min-height: 44px;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
  }

  .chip {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
    font-size: 0.85rem;
  }
}
