:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --cell: #ffffff;
  --cell-outside: #f0f1f4;
  --border: #dfe1e6;
  --text: #1c1d21;
  --muted: #5d6370;
  --faint: #9aa0ab;
  --accent: #5865f2;
  --accent-strong: #4752c4;
  --accent-text: #ffffff;
  --danger: #da373c;
  --shadow: 0 10px 30px rgba(15, 18, 30, 0.12);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1f22;
    --surface: #2b2d31;
    --surface-2: #232428;
    --cell: #313338;
    --cell-outside: #26272b;
    --border: #3a3c42;
    --text: #f2f3f5;
    --muted: #b5bac1;
    --faint: #6d717a;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1e1f22;
  --surface: #2b2d31;
  --surface-2: #232428;
  --cell: #313338;
  --cell-outside: #26272b;
  --border: #3a3c42;
  --text: #f2f3f5;
  --muted: #b5bac1;
  --faint: #6d717a;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-weight: 500; }

/* ---------- buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--border); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-icon { width: 36px; height: 36px; padding: 0; font-size: 22px; line-height: 1; background: transparent; }
.btn-icon:hover { background: var(--surface-2); }
.btn-discord { background: #5865f2; color: #fff; padding: 12px 22px; font-size: 16px; }
.btn-discord:hover { background: #4752c4; }
.wide { width: 100%; }

/* ---------- loading & login */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  display: grid;
  gap: 14px;
  justify-items: center;
}
.login-card h1 { font-size: 26px; }
.login-card p { margin: 0; }
.fine { font-size: 12px; color: var(--faint); }

/* The OOA logo (transparent, so it sits on both the light and dark themes). */
.brand-mark {
  width: 96px; height: 96px; flex: none;
  background: url("/static/logo.png") center / contain no-repeat;
}
.brand-mark.small { width: 44px; height: 44px; }

/* ---------- app shell */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user img { border-radius: 50%; background: var(--surface-2); }
#username { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }

/* Filters on the left, the month in the middle, "Upcoming" on the right. Below 1500px there isn't room
   for three columns, so Upcoming moves under the month instead. */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  max-width: 1800px;
  margin: 0 auto;
}
@media (min-width: 1500px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr) 300px; }
}

.sidebar, .rail { display: grid; gap: 22px; align-content: start; }
.sidebar { grid-row: 1 / span 2; }
.rail { grid-column: 2; }
#new-event { height: 40px; }  /* fixed, so the right-hand column can line up below it */
@media (min-width: 1500px) {
  .sidebar { grid-row: auto; }
  .rail { grid-column: 3; position: sticky; top: 84px; max-height: calc(100vh - 104px); overflow: auto; }
  /* Start level with the "Calendars" heading: the New event button (40px) plus the sidebar's 22px gap. */
  .layout.can-add .rail { margin-top: 62px; }
}
.sidebar h2, .rail h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }

.calendar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.calendar-list label {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; user-select: none;
}
.calendar-list label:hover { background: var(--surface-2); }
.calendar-list input { position: absolute; opacity: 0; pointer-events: none; }
.swatch {
  width: 16px; height: 16px; border-radius: 5px; flex: none;
  border: 2px solid var(--c); background: var(--c);
}
.calendar-list input:not(:checked) + .swatch { background: transparent; }
.calendar-list input:focus-visible + .swatch { outline: 2px solid var(--accent); outline-offset: 2px; }
.calendar-list .name { flex: 1; }
.calendar-list .tag { font-size: 11px; color: var(--faint); }
.calendar-list .section { margin-top: 12px; }
.calendar-list .section:first-child { margin-top: 0; }
.section-toggle {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%;
  display: flex; align-items: center; gap: 6px; padding: 4px 8px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.section-toggle:hover { color: var(--text); }
.section-toggle:focus-visible { outline: 2px solid var(--accent); border-radius: 6px; }
.section-toggle .chev { width: 10px; font-size: 10px; }

.upcoming { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.upcoming li button {
  all: unset; box-sizing: border-box; cursor: pointer; display: grid; gap: 2px; width: 100%;
  padding: 8px 10px 8px 12px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--c);
}
.upcoming li button:hover { border-color: var(--c); }
.upcoming li button:focus-visible { outline: 2px solid var(--accent); }
.upcoming .u-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming .u-when { font-size: 12px; color: var(--muted); }
.u-title .cal {
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em; margin-right: 6px; vertical-align: 1px;
  color: color-mix(in srgb, var(--c) 70%, var(--text));
}
.u-title .cal:empty { display: none; }
.upcoming .empty { color: var(--faint); font-size: 13px; }

/* ---------- month grid */
.main { min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.nav { display: flex; align-items: center; gap: 2px; }
#month-title { font-size: 24px; font-weight: 700; }
#tz-note { margin-left: auto; }

.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.weekdays div {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 0 8px 6px;
}
.day {
  background: var(--cell);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 118px;
  padding: 6px;
  display: flex; flex-direction: column; gap: 3px;
  min-width: 0;
  cursor: pointer;
}
.day.outside { background: var(--cell-outside); }
.day.outside .num { color: var(--faint); }
.day.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day .num {
  font-weight: 700; font-size: 14px; width: 28px; height: 28px;
  display: grid; place-items: center; border-radius: 50%;
}
.day.today .num { background: var(--accent); color: var(--accent-text); }

.chip {
  all: unset; box-sizing: border-box; cursor: pointer;
  display: block; width: 100%;
  font-size: 12.5px; line-height: 1.3; padding: 3px 6px 3px 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--c) 22%, transparent);
  border-left: 3px solid var(--c);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { background: color-mix(in srgb, var(--c) 34%, transparent); }
.chip:focus-visible { outline: 2px solid var(--accent); }
.chip.allday { background: var(--c); color: #fff; border-left-color: transparent; font-weight: 600; }
.chip .t { font-weight: 600; margin-right: 4px; font-variant-numeric: tabular-nums; }
.chip .cal {
  font-size: 10px; font-weight: 700; letter-spacing: 0.04em; margin-right: 5px;
  color: color-mix(in srgb, var(--c) 70%, var(--text));
}
.chip .cal:empty { display: none; }
.chip.allday .cal { color: #fff; opacity: 0.85; }
.more { font-size: 12px; font-weight: 600; color: var(--muted); padding-left: 6px; }
.dots { display: none; gap: 3px; flex-wrap: wrap; padding: 0 2px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

.day-panel { margin-top: 18px; display: none; }
.day-panel h2 { font-size: 16px; margin-bottom: 10px; }
.day-events { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }

/* ---------- dialogs */
dialog.sheet {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(10, 12, 20, 0.55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sheet h2 { font-size: 20px; overflow-wrap: anywhere; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px;
  background: color-mix(in srgb, var(--c) 20%, transparent);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.when { font-weight: 600; margin: 8px 0 4px; }
.meta { margin: 4px 0; color: var(--muted); }
.description { white-space: pre-wrap; overflow-wrap: anywhere; margin: 12px 0; }
.invitees { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.person {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border-radius: 99px; padding: 3px 10px 3px 3px; font-size: 13px;
}
.person img { width: 20px; height: 20px; border-radius: 50%; }
.person button { all: unset; cursor: pointer; color: var(--muted); padding: 0 2px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

form { display: grid; gap: 12px; }
form label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
form label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  width: 100%;
  min-width: 0;
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.invite-field { position: relative; display: grid; gap: 6px; }
.invite-results {
  list-style: none; margin: 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 200px; overflow: auto;
}
.invite-results button {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.invite-results button:hover, .invite-results button:focus-visible { background: var(--surface-2); }
.invite-results img { width: 22px; height: 22px; border-radius: 50%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- small screens */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .sidebar { order: 2; grid-row: auto; }
  .rail { display: none; grid-column: auto; }
  .upcoming-section { display: none; }
  .calendar-list { display: flex; flex-wrap: wrap; gap: 4px; }
  .calendar-list label { background: var(--surface); border: 1px solid var(--border); padding: 5px 10px; }
  .calendar-list .tag { display: none; }
  .calendar-list .section { flex-basis: 100%; margin-top: 6px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  #username { display: none; }
  .weekdays, .grid { gap: 3px; }
  .weekdays div { padding: 0 0 4px; text-align: center; font-size: 11px; }
  .day { min-height: 56px; padding: 4px 2px; align-items: center; border-radius: 8px; }
  .day .num { font-size: 13px; width: 24px; height: 24px; }
  .day .chip, .day .more { display: none; }
  .dots { display: flex; justify-content: center; }
  .day-panel { display: block; }
  #month-title { font-size: 20px; }
  #tz-note { width: 100%; margin-left: 0; }
  .row { grid-template-columns: 1fr; }
}
