:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1e2638;
  --border: #2a3350;
  --text: #e8ecf4;
  --muted: #94a0bd;
  --accent: #5b8def;
  --accent-2: #39c6a1;
  --danger: #e2577a;
  --warn: #e7b84b;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --panel-2: #eef1f8;
    --border: #d9e0ef;
    --text: #1a2033;
    --muted: #5b6480;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.25rem; margin: 0; }
.week-nav { display: flex; align-items: center; gap: 0.75rem; }
.week-nav button {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; width: 2rem; height: 2rem; cursor: pointer; font-size: 1rem;
}
.week-nav button:hover { background: var(--accent); color: white; }

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}

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

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem;
  min-width: 0;
}
.panel h2 { font-size: 1rem; margin: 0 0 0.75rem; }

.booking-panel form { display: flex; flex-direction: column; gap: 0.6rem; }
.booking-panel label { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--muted); gap: 0.25rem; }
input, select, button {
  font: inherit; padding: 0.5rem 0.6rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
}
button { cursor: pointer; background: var(--accent); color: white; border: none; font-weight: 600; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); }

.recommendation, .hidden { }
.hidden { display: none !important; }
.recommendation { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.recommendation h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
#recommendedSlot { font-weight: 700; font-size: 1.05rem; }
.reason { color: var(--muted); font-size: 0.85rem; }
#altSlots { list-style: none; padding: 0; margin: 0.5rem 0 0; display: flex; flex-direction: column; gap: 0.35rem; }
#altSlots li { display: flex; justify-content: space-between; align-items: center; background: var(--panel-2); padding: 0.4rem 0.6rem; border-radius: 8px; font-size: 0.85rem; }
#altSlots button { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.calendar-controls { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.staff-filter { font-size: 0.85rem; color: var(--muted); display: flex; gap: 0.4rem; align-items: center; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 0.5rem;
  overflow-x: auto;
  margin-top: 0.75rem;
}
@media (max-width: 800px) {
  .calendar-grid { grid-template-columns: 1fr; }
}

.day-col { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem; min-height: 200px; }
.day-col h4 { margin: 0 0 0.4rem; font-size: 0.8rem; color: var(--muted); text-align: center; }
.staff-lane { margin-bottom: 0.5rem; }
.staff-lane .staff-name { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.2rem; }
.appt-block {
  border-radius: 6px; padding: 0.35rem 0.45rem; font-size: 0.72rem; margin-bottom: 0.3rem;
  cursor: pointer; color: white; line-height: 1.25;
}
.appt-block:hover { outline: 2px solid rgba(255,255,255,0.5); }
.appt-block .time { font-weight: 700; display: block; }
.empty-day { color: var(--muted); font-size: 0.75rem; text-align: center; padding: 0.75rem 0; }

.side-panel > div { margin-bottom: 1.25rem; }
.side-panel > div:last-child { margin-bottom: 0; }
.side-panel label { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--muted); gap: 0.25rem; margin-bottom: 0.5rem; }

.util-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 0.8rem; }
.util-row .name { width: 70px; flex-shrink: 0; }
.util-bar { flex: 1; background: var(--border); border-radius: 6px; height: 10px; overflow: hidden; }
.util-bar > div { height: 100%; background: var(--accent-2); }
.util-pct { width: 44px; text-align: right; flex-shrink: 0; color: var(--muted); }

.waitlist-item, .optimize-move {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.6rem; font-size: 0.8rem; margin-bottom: 0.4rem; display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
}
.waitlist-item button { padding: 0.25rem 0.5rem; font-size: 0.72rem; }
.badge { font-size: 0.65rem; padding: 0.1rem 0.4rem; border-radius: 999px; background: var(--border); color: var(--muted); }
.badge.offered { background: var(--warn); color: #3a2c00; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; max-width: 420px; width: 100%;
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }

.empty { color: var(--muted); font-size: 0.8rem; }
