/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #2563eb;
  --brand-dk:     #1d4ed8;
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --muted:        #64748b;
  --danger:       #dc2626;
  --success:      #16a34a;
  --today-bg:     #eff6ff;
  --today-border: #2563eb;
  --event-bg:     #dbeafe;
  --event-bg-dk:  #bfdbfe;
  --event-text:   #1e40af;
  --radius:       8px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  background: var(--brand);
  color: #fff;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
}
.header-inner {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* Logo + title grouped together on the left */
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.header-logo {
  height: 40px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
}
header h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.admin-link {
  color: #fff;
  text-decoration: none;
  font-size: 0.875rem;
  background: rgba(255,255,255,0.2);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius);
  transition: background 0.15s;
}
.admin-link:hover { background: rgba(255,255,255,0.35); }

/* ── Main layout ─────────────────────────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

/* ── Controls ────────────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.nav-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.nav-row h2 { font-size: 1.35rem; min-width: 200px; text-align: center; }
.nav-row button {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  width: 36px; height: 36px;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.nav-row button:hover { background: var(--brand-dk); }

.zip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.zip-row label { font-size: 0.875rem; color: var(--muted); white-space: nowrap; }
.zip-row input {
  width: 100px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
button {
  cursor: pointer;
  padding: 0.45rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--brand);
  color: #fff;
  transition: background 0.15s;
}
button:hover { background: var(--brand-dk); }
button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--border); }
button.danger { background: var(--danger); }
button.danger:hover { background: #b91c1c; }

/* ── ZIP info banner ──────────────────────────────────────────────────────────── */
.zip-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--event-text);
  margin-bottom: 0.75rem;
}

/* ── Calendar grid ───────────────────────────────────────────────────────────── */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.day-header {
  background: var(--surface);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.day-cell {
  background: var(--surface);
  min-height: 100px;
  padding: 0.4rem;
  vertical-align: top;
}
.day-cell.empty { background: #f1f5f9; }
.day-cell.today { background: var(--today-bg); border: 2px solid var(--today-border); }
.day-number {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.25rem;
  display: block;
}
.day-cell.today .day-number { color: var(--brand); }
.event-pill {
  display: block;
  background: var(--event-bg);
  color: var(--event-text);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
}
.event-pill:hover { background: #bfdbfe; }
.event-pill.has-distance::after {
  content: attr(data-distance);
  float: right;
  font-weight: 400;
  opacity: 0.75;
}

/* Multi-day pill variants */
.event-pill.pill-start {
  background: var(--event-bg-dk);
  border-radius: 4px 0 0 4px;
  border-right: 2px solid var(--event-bg-dk);
  filter: brightness(0.93);
}
.event-pill.pill-mid {
  background: var(--event-bg-dk);
  border-radius: 0;
  border-right: 2px solid var(--event-bg-dk);
  filter: brightness(0.93);
  opacity: 0.85;
}
.event-pill.pill-end {
  background: var(--event-bg-dk);
  border-radius: 0 4px 4px 0;
  filter: brightness(0.93);
  opacity: 0.85;
}
.event-pill.pill-only { /* single-day, no change from base */ }

/* ── Nearby list ─────────────────────────────────────────────────────────────── */
.nearby-list {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.nearby-list h3 { margin-bottom: 0.75rem; font-size: 1rem; }
.nearby-item {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.nearby-item:last-child { border-bottom: none; }
.nearby-item:hover .nearby-title { color: var(--brand); }
.nearby-dist {
  min-width: 64px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--brand);
  white-space: nowrap;
}
.nearby-title { font-weight: 600; font-size: 0.9rem; }
.nearby-meta { font-size: 0.8rem; color: var(--muted); }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-close {
  position: absolute; top: 0.75rem; right: 0.75rem;
  background: none; border: none;
  font-size: 1.4rem; color: var(--muted);
  cursor: pointer; padding: 0.1rem 0.4rem;
}
.modal-close:hover { color: var(--text); background: var(--border); border-radius: 4px; }
.modal-box h3 { font-size: 1.15rem; margin-bottom: 0.75rem; padding-right: 1.5rem; }
.modal-meta { font-size: 0.875rem; color: var(--muted); margin-bottom: 0.3rem; }
#modalDesc { margin-top: 0.75rem; font-size: 0.9rem; line-height: 1.6; white-space: pre-wrap; }

/* ── Event detail — OG image ─────────────────────────────────────────────────── */
.modal-image-wrap {
  margin: -1.25rem -1.5rem 1rem -1.5rem; /* bleed to modal edges */
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  background: var(--border);
  max-height: 240px;
}
.modal-image {
  width: 100%;
  height: 240px;
  object-fit: cover;
  display: block;
}

/* ── Event detail — website / Facebook links ─────────────────────────────────── */
.modal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}
.modal-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s;
}
.modal-link:hover { opacity: 0.85; }
.modal-link-website {
  background: var(--brand);
  color: #fff;
}
.modal-link-facebook {
  background: #1877f2;
  color: #fff;
}

/* ── Admin ───────────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 360px;
  margin: 0 auto;
}
.form-card h2 { margin-bottom: 1.25rem; }

form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}
form input, form textarea {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
}
form input:focus, form textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.toolbar-right { display: flex; gap: 0.5rem; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.875rem;
}
th {
  background: #f1f5f9;
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }
.action-btns { display: flex; gap: 0.4rem; }
.action-btns button { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* ── Messages ────────────────────────────────────────────────────────────────── */
.error-msg {
  background: #fef2f2; border: 1px solid #fecaca;
  color: var(--danger); border-radius: var(--radius);
  padding: 0.5rem 0.75rem; margin-bottom: 0.75rem; font-size: 0.875rem;
}
.success-msg {
  background: #f0fdf4; border: 1px solid #bbf7d0;
  color: var(--success); border-radius: var(--radius);
  padding: 0.5rem 0.75rem; margin-bottom: 0.75rem; font-size: 0.875rem;
}
.empty-msg { color: var(--muted); text-align: center; padding: 2rem; font-size: 0.9rem; }

/* ── Tabs ────────────────────────────────────────────────────────────────────── */
.tab-row {
  display: flex;
  gap: 0.25rem;
}
.tab-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.45rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.panel-toolbar { margin-bottom: 0.75rem; }

/* ── Role badges ──────────────────────────────────────────────────────────────── */
.role-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}
.role-superadmin { background: #fef3c7; color: #92400e; }
.role-admin      { background: var(--event-bg); color: var(--event-text); }

/* ── Misc form helpers ────────────────────────────────────────────────────────── */
.field-hint { font-size: 0.8rem; color: var(--muted); margin-top: -0.5rem; margin-bottom: 1rem; }
.logged-in-as { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* ── Hours editor (admin event form) ─────────────────────────────────────────── */
.hours-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
  max-height: 320px;
  display: flex;
  flex-direction: column;
}
.hours-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f1f5f9;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  flex-shrink: 0;
}
.hours-header-actions { display: flex; gap: 0.4rem; }
button.small { padding: 0.25rem 0.65rem; font-size: 0.78rem; }

#hoursRows {
  overflow-y: auto;
  flex: 1;
}
.hours-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border));
  font-size: 0.83rem;
}
.hours-row:last-child { border-bottom: none; }
.hours-day-label {
  min-width: 110px;
  color: var(--muted);
  font-weight: 500;
  flex-shrink: 0;
}
.hours-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
}
.hours-inputs input[type="time"] {
  flex: 1;
  padding: 0.3rem 0.5rem;
  font-size: 0.83rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.hours-sep { color: var(--muted); font-size: 0.8rem; }

/* Summary text under date range in events table */
.hours-summary { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

/* Wide modal for the event form */
.modal-box-wide { max-width: 580px; }

/* ── Public modal hours list ──────────────────────────────────────────────────── */
.modal-hours { margin-bottom: 0.5rem; }
.modal-hours-label { display: block; font-size: 0.875rem; color: var(--muted); margin-bottom: 0.35rem; }
.modal-hours-row {
  display: flex;
  gap: 0.75rem;
  font-size: 0.85rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--border);
}
.modal-hours-row:last-child { border-bottom: none; }
.modal-hours-date { min-width: 160px; color: var(--muted); }

/* ── Event pill — title + time lines ─────────────────────────────────────────── */
.pill-title { display: block; }
.pill-time  { display: block; font-size: 0.65rem; opacity: 0.8; font-weight: 400; }

/* ── Monthly recurrence pattern options ───────────────────────────────────────── */
.monthly-options {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 1rem;
}
.monthly-type-row {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}
.radio-label input[type="radio"] { margin: 0; cursor: pointer; }
.weekday-options { margin-top: 0.5rem; }
.weekday-preview { color: var(--brand); font-style: italic; margin-top: 0.35rem; }

/* ── Recurring event badges ───────────────────────────────────────────────────── */
.recur-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: #fae8ff;
  color: #7e22ce;
}
/* Inline badge inside the public modal */
.recur-badge-inline {
  font-size: 0.82rem;
  font-weight: 600;
  color: #7e22ce;
}

/* ── Duration input (recurring form) ──────────────────────────────────────────── */
.duration-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.duration-wrap input[type="number"] {
  width: 70px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.duration-unit { font-size: 0.82rem; color: var(--muted); }

/* ── Recurring event pills (public calendar) ──────────────────────────────────── */
.event-pill.pill-recurring { background: #f3e8ff; color: #7e22ce; }
.event-pill.pill-recurring:hover { background: #e9d5ff; }

/* muted small text in admin table */
.muted-sm { font-size: 0.78rem; color: var(--muted); }

/* ── Color picker grid (settings panel) ─────────────────────────────────────── */
.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.color-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
}
.color-item-wide {
  grid-column: 1 / -1;
}
.color-input-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.color-input-row input[type="color"] {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}
.color-input-row input[type="text"] {
  font-family: monospace;
  font-size: 0.82rem;
  width: 80px;
  padding: 0.3rem 0.5rem;
}
.color-section-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0.75rem 0 0.4rem;
  grid-column: 1 / -1;
}
.color-reset-btn {
  font-size: 0.78rem;
  padding: 0.3rem 0.75rem;
}

/* ── Settings image preview ──────────────────────────────────────────────────── */
.settings-preview {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem;
}
.settings-preview img {
  max-height: 60px;
  max-width: 100%;
  object-fit: contain;
}

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

@media (max-width: 640px) {
  .nav-row h2 { min-width: 160px; font-size: 1.1rem; }
  .day-cell { min-height: 64px; }
  .form-row { grid-template-columns: 1fr; }
  table { font-size: 0.78rem; }
  th, td { padding: 0.4rem 0.5rem; }
}
