/* === Reset === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

/* === Base === */
:root {
  --bg-from: #f5f6f8;
  --bg-to: #eceef1;
  --surface: rgba(255,255,255,0.7);
  --surface-hover: rgba(255,255,255,0.9);
  --surface-border: rgba(0,0,0,0.08);
  --surface-blur: blur(12px);
  --text: rgba(0,0,0,0.87);
  --text-muted: rgba(0,0,0,0.5);
  --separator: rgba(0,0,0,0.06);
  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-coral: #E87A73;
  --accent-coral-hover: #d96860;
  --nav-accent: #522aaf; /* logo purple */
  --nav-highlight: rgba(145,153,234,0.2); /* logo lavender #9199ea */
  --accent-sky: #2a7ab5;
  --accent-yellow: #FEF6C2;
  --radius: 12px;
  --radius-sm: 8px;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-from) 0%, var(--bg-to) 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

/* === Typography === */
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }
p { margin-bottom: 0.75rem; }
strong { font-weight: 600; }

/* === Links === */
a { color: var(--accent-sky); text-decoration: none; transition: color 0.2s; }
a:hover { color: #1a5a8a; }

/* === Nav === */
nav {
  position: relative;
  z-index: 10; /* keeps open menus above the page's glass cards */
  display: flex;
  align-items: center;
  gap: 40px;
  padding: 14px 32px;
  background: rgba(255,255,255,0.7);
  backdrop-filter: var(--surface-blur);
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
nav .brand {
  text-decoration: none;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
nav .nav-logo {
  height: 28px;
  width: auto;
}
nav .brand:hover { color: var(--text); }
nav .links { display: flex; align-items: center; gap: 24px; flex: 1; font-size: 14px; }
nav .links a { color: var(--text-muted); text-decoration: none; white-space: nowrap; }
nav .links a:hover { color: rgba(0,0,0,0.75); }
nav .links > a, nav button.nav-menu-button { border-bottom: 2px solid transparent; padding: 2px 0; }
nav .links > a.active, nav button.nav-menu-button.active {
  color: var(--text);
  border-bottom-color: var(--nav-accent);
}

/* Dropdown menus: More, and the signed-in person's account */
nav .nav-menu { position: relative; }
nav .nav-account { margin-left: auto; }
nav button.nav-menu-button, nav button.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border-radius: 0;
  padding: 2px 0;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
}
nav button.nav-menu-button:hover, nav button.nav-toggle:hover { background: none; color: rgba(0,0,0,0.75); }
nav button.nav-menu-button::after, nav button.nav-toggle::after {
  content: "";
  width: 5px;
  height: 5px;
  margin-top: -3px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
  transition: transform 0.15s;
}
nav button[aria-expanded="true"]::after { transform: rotate(-135deg); margin-top: 3px; }
nav .nav-menu-panel {
  position: absolute;
  top: calc(100% + 14px);
  left: -10px;
  min-width: 190px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.97);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
}
nav .nav-account .nav-menu-panel { left: auto; right: -10px; }
nav .nav-menu-button[aria-expanded="false"] + .nav-menu-panel { display: none; }
nav .nav-menu-panel a, nav .nav-menu-panel button.link-button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  text-align: left;
  font-size: 14px;
  color: var(--text);
}
nav .nav-menu-panel a:hover, nav .nav-menu-panel button.link-button:hover { background: rgba(0,0,0,0.05); color: var(--text); }
nav .nav-menu-panel a.active { background: var(--nav-highlight); }
nav .nav-menu-panel .logout-form { display: block; }
nav .nav-menu-who {
  display: flex;
  flex-direction: column;
  padding: 6px 10px 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--separator);
  font-size: 14px;
  line-height: 1.35;
}
nav .nav-menu-who .text-muted { font-size: 12px; overflow-wrap: anywhere; }
nav button.nav-toggle { display: none; }

/* === Container === */
.container { max-width: 1400px; margin: 0 auto; padding: 32px 24px 48px; }

/* === Page Header === */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-header h2 { margin: 0; }
.page-header select { width: auto; margin-bottom: 0; }

/* === Glass Card (article) === */
article {
  background: var(--surface);
  backdrop-filter: var(--surface-blur);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

article > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
article > header h2 { margin: 0; }
article > header h3 { margin: 0; }

article > footer {
  border-top: 1px solid var(--separator);
  margin-top: 16px;
  padding-top: 12px;
}

/* === Stats Row === */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.stat-card .number { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-card .label { font-size: 11px; color: var(--text); opacity: 0.6; margin-top: 2px; }
/* Status: enrolled vs capacity. Neutral for everything else. */
.stat-neutral { background: rgba(0,0,0,0.05); }
.stat-under   { background: #fde68a; }
.stat-at      { background: #86efac; }
.stat-over    { background: #fca5a5; }

/* === Location Grid === */
.location-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
.location-grid article { margin: 0; }
.location-grid h3 { margin: 0; }
.location-grid table { font-size: 13px; }
.location-grid td, .location-grid th { padding: 4px 8px; }

/* === Tables === */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
td { padding: 8px; border-top: 1px solid var(--separator); }
.table-wrap { overflow-x: auto; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-full   { background: rgba(22,163,74,0.1); color: #15803d; }
.badge-ok     { background: rgba(202,138,4,0.1); color: #a16207; }
.badge-low    { background: rgba(234,88,12,0.1); color: #c2410c; }
.badge-empty  { background: rgba(220,38,38,0.1); color: #dc2626; }
.badge-over   { background: #dc2626; color: #fff; }
.badge-notice { background: rgba(37,99,235,0.1); color: #2563eb; }
.badge-info   { background: rgba(6,182,212,0.1); color: #0891b2; }
.badge-ageout { background: rgba(124,58,237,0.1); color: #7c3aed; }
.badge-archived { background: rgba(120,120,140,0.1); color: #6b7280; }

/* === CSV import preview === */
.import-table td { vertical-align: top; }
.import-table input[type="checkbox"] { width: auto; margin: 0; }
.import-row-num { white-space: nowrap; width: 1%; }
.import-result .badge + * { margin-top: 6px; }
.import-result select { margin-bottom: 0; width: auto; max-width: 100%; }
.import-errors { border-left: 3px solid #dc2626; }

/* === Alerts === */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border-left: 3px solid;
}
.alert-info   { background: rgba(37,99,235,0.06); border-color: #3b82f6; color: #1d4ed8; }
.alert-warn   { background: rgba(202,138,4,0.08); border-color: #ca8a04; color: #92400e; }
.alert-danger { background: rgba(220,38,38,0.06); border-color: #dc2626; color: #b91c1c; }

/* === Forecast Projection Cells === */
.proj-full { color: #15803d; }
.proj-ok   { color: #a16207; }
.proj-low  { color: #dc2626; }

/* === Buttons === */
button, [role="button"] {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s;
  background: var(--accent-primary);
  color: white;
  font-family: inherit;
  line-height: 1.5;
}
button:hover, [role="button"]:hover {
  background: var(--accent-primary-hover);
  color: white;
}

button.outline, [role="button"].outline {
  background: transparent;
  border: 1px solid rgba(0,0,0,0.2);
  color: var(--text);
}
button.outline:hover, [role="button"].outline:hover {
  border-color: rgba(0,0,0,0.35);
  background: rgba(0,0,0,0.04);
}
button.outline:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

button.secondary, [role="button"].secondary {
  background: transparent;
  border: 1px solid rgba(0,0,0,0.15);
  color: var(--text-muted);
}
button.secondary:hover, [role="button"].secondary:hover {
  color: var(--text);
  border-color: rgba(0,0,0,0.3);
}

button.contrast {
  background: rgba(0,0,0,0.06);
  color: var(--text);
  border: 1px solid rgba(0,0,0,0.12);
}
button.contrast:hover {
  background: rgba(0,0,0,0.1);
}

button.btn-danger, [role="button"].btn-danger {
  background: #dc2626;
  border: none;
  color: white;
}
button.btn-danger:hover, [role="button"].btn-danger:hover {
  background: #b91c1c;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* === Forms === */
label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

input, select, textarea {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0,0,0,0.15);
  background: rgba(255,255,255,0.6);
  color: var(--text);
  color-scheme: light;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-sky);
}
input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}
select option { background: var(--bg-to); color: var(--text); }

/* === Details / Summary === */
details { margin-top: 12px; }
summary {
  cursor: pointer;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary[role="button"] { width: fit-content; }

/* === Filter Bar === */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar > input {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}
.filter-bar select {
  width: auto;
  min-width: 140px;
  margin-bottom: 0;
}
.archived-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  white-space: nowrap;
  margin-bottom: 0;
  cursor: pointer;
}
.archived-toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

/* === Profile Fields === */
.profile-fields {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.profile-fields dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.profile-fields dd { margin: 0; font-weight: 500; }

/* === Availability Checker === */

/* === Confirm Dialog === */
.confirm-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-to);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 24px;
  color: var(--text);
  max-width: 360px;
  width: calc(100% - 32px);
}
.confirm-dialog::backdrop {
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
.confirm-dialog p { margin-bottom: 20px; }
.confirm-dialog .actions { margin: 0; }

/* === Login === */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 60px);
  padding-top: 0;
  padding-bottom: 0;
}
.login-container article {
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.login-container input { text-align: center; }
.login-container button { width: 100%; }

/* A button that reads as a link: Log out is a POST form, so other sites can't trigger it */
.logout-form { display: flex; justify-content: center; align-items: flex-start; }
button.link-button, button.link-button:hover {
  background: none;
  border: none;
  padding: 0;
  width: auto;
  font: inherit;
  color: var(--text-muted);
}
button.link-button:hover { color: rgba(0,0,0,0.75); }

/* === Account & Users === */
.form-narrow { max-width: 480px; }
.location-fields { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.location-fields legend { padding: 0; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.location-fields p { margin: 8px 0 0; font-size: 13px; }
.location-checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.location-checks label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; font-weight: 400; color: var(--text); cursor: pointer; }
.location-checks input[type="checkbox"] { width: 1rem; height: 1rem; margin: 0; }
.temp-password-card { max-width: 560px; }
.temp-password-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 12px 0 16px;
}
/* Shown once, then read aloud or retyped: large, monospaced, one click selects it all */
.temp-password {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-yellow);
  border: 1px solid rgba(202,138,4,0.25);
  user-select: all;
}

/* === Breadcrumb === */
.breadcrumb {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 13px;
}

/* === Misc === */
.text-muted { color: var(--text-muted); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
a.secondary { color: var(--text-muted); }
.header-stat { font-size: 13px; font-weight: 600; }

/* === Next spot (forecast + dashboard) === */
.spot-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.spot-form label { margin: 0; }
.spot-form input, .spot-form select { margin-bottom: 0; height: 40px; }
/* Safari ignores a native dropdown's height, so draw it (and its arrow) ourselves */
.spot-form select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23777' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}
.spot-answer { margin: 20px 0 16px; padding: 16px 18px; border-radius: var(--radius-sm); background: var(--nav-highlight); }
.spot-answer .when { font-size: 22px; font-weight: 700; color: var(--nav-accent); line-height: 1.25; }
.spot-answer .detail { font-size: 14px; margin-top: 4px; }
.spot-answer.none { background: rgba(202,138,4,0.08); }
.spot-answer.none .when { color: #92400e; }
.spot-table td:nth-child(2) { font-weight: 600; white-space: nowrap; }
.spot-table .first { display: block; font-weight: 400; font-size: 12px; color: var(--text-muted); }
.spot-table tr.best td { background: rgba(145,153,234,0.08); }
.spot-table .why { color: var(--text-muted); }

/* === Projection table === */
.proj td { font-variant-numeric: tabular-nums; white-space: nowrap; }
.proj-wl { color: var(--accent-sky); font-weight: 600; }
.proj-over { background: rgba(202,138,4,0.1); }
.proj-note { display: block; font-size: 11px; color: #92400e; }

/* === Licence age limits (location page) === */
.license-stats { display: flex; gap: 16px; align-items: baseline; }
.age-table td:nth-child(2) { font-weight: 600; font-variant-numeric: tabular-nums; }
.age-table td.zero { color: var(--text-muted); font-weight: 400; }
.limit-note { font-size: 12px; color: #a16207; margin-left: 6px; }

/* === Responsive === */
/* Below this width the nav links no longer fit on one line, so they fold behind a Menu button */
@media (max-width: 960px) {
  nav { flex-wrap: wrap; gap: 0; padding: 12px 16px; }
  nav button.nav-toggle { display: inline-flex; margin-left: auto; padding: 6px 0; }
  nav .links {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin-top: 10px;
    padding-top: 6px;
    border-top: 1px solid var(--separator);
  }
  nav .nav-toggle[aria-expanded="true"] + .links { display: flex; }
  nav .links a, nav .nav-menu-panel button.link-button {
    padding: 9px 8px;
    border: 0;
    border-radius: 6px;
    font-size: 15px;
    color: var(--text);
  }
  nav .links > a.active, nav .nav-menu-panel a.active { background: var(--nav-highlight); }
  nav .nav-account { margin-left: 0; }
  /* Menus show their links in place instead of as dropdowns */
  nav button.nav-menu-button { display: none; }
  nav .nav-menu-panel, nav .nav-menu-button[aria-expanded="false"] + .nav-menu-panel {
    display: flex;
    position: static;
    min-width: 0;
    padding: 6px 0 0;
    margin-top: 6px;
    background: none;
    border: 0;
    border-top: 1px solid var(--separator);
    border-radius: 0;
    box-shadow: none;
  }
  nav .nav-menu-who { padding: 8px 8px 10px; margin-bottom: 0; border-bottom: 0; }
}


@media (max-width: 640px) {
  .temp-password { font-size: 18px; letter-spacing: 0.04em; }
  .container { padding: 20px 16px 32px; }
  .page-header h2 { font-size: 18px; }
  .spot-form { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .location-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-bar input, .filter-bar select { width: 100%; min-width: 0; }
  .profile-fields { gap: 1rem; }
}
