:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --text: #16232a;
  --muted: #5b6b72;
  --border: #d7e0e3;
  --accent: #0f4c5c;
  --accent-contrast: #ffffff;
  --danger: #b3261e;
  --flag-bg: #fff4e5;
  --flag-border: #f2b866;
  --row-flag-bg: #fff8ec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a1e;
    --surface: #16262b;
    --text: #e7eef0;
    --muted: #9fb0b6;
    --border: #2a3d43;
    --accent: #4fb3c9;
    --accent-contrast: #06232a;
    --danger: #ff8a80;
    --flag-bg: #2b2412;
    --flag-border: #a97a2b;
    --row-flag-bg: #241f14;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  padding: 1.25rem 1rem 0.5rem;
  text-align: center;
}

.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
}

.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 1rem 3rem;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0.75rem 0;
  font-weight: 600;
  text-transform: capitalize;
}

.month-nav button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
}

.flags-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (max-width: 600px) {
  .flags-grid {
    grid-template-columns: 1fr;
  }
}

.flags {
  background: var(--flag-bg);
  border: 1px solid var(--flag-border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
}

.flags h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.flags ul {
  margin: 0;
  padding-left: 1.1rem;
}

.aggregates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  flex: 1;
  min-width: 140px;
}

.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.stat-instructors {
  flex: 2;
  min-width: 220px;
}

.instructor-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
}

.toolbar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

button {
  font: inherit;
}

button.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-weight: 600;
}

.toolbar button:not(.primary) {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.notes-cell {
  white-space: normal;
  min-width: 140px;
}

td:first-child {
  text-align: center;
  font-size: 1.05rem;
}

tr.row-flagged {
  background: var(--row-flag-bg);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
  text-decoration: underline;
}

.actions-cell {
  display: flex;
  gap: 0.6rem;
}

.dialog-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dialog-body h2 {
  margin: 0;
}

.preview-banner {
  background: var(--flag-bg);
  border: 1px solid var(--flag-border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  margin: 0;
}

.mail-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.85rem;
}

.mail-preview p {
  margin: 0 0 0.4rem;
}

.mail-preview pre {
  white-space: pre-wrap;
  font-family: inherit;
  margin: 0;
}

dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: min(420px, 92vw);
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

#bookingForm {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#bookingForm h2 {
  margin: 0 0 0.25rem;
}

#bookingForm label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#bookingForm input,
#bookingForm select,
#bookingForm textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}

.field-row {
  display: flex;
  gap: 0.75rem;
}

.field-row label {
  flex: 1;
}

.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.spacer {
  flex: 1;
}

.dialog-actions button {
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.dialog-actions button.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.toast-error {
  background: var(--danger);
}

@media (max-width: 600px) {
  .aggregates {
    flex-direction: column;
  }
}
