:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1f2a33;
  --muted: #5d6a74;
  --border: #ddd7cc;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --brand-soft: #e3edf7;
  --open: #2f7d4f;
  --open-soft: #e2f2e8;
  --taken: #8a8f94;
  --taken-soft: #eceae6;
  --warn: #a4471f;
  --warn-soft: #fbe9df;
  --focus: #f0a33a;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171c;
    --surface: #1a2128;
    --surface-2: #222b33;
    --text: #e7ebee;
    --muted: #9aa7b1;
    --border: #2e3943;
    --brand: #7fb2e5;
    --brand-ink: #0d1a26;
    --brand-soft: #1d3247;
    --open: #6fcf97;
    --open-soft: #173a28;
    --taken: #7d868e;
    --taken-soft: #232a31;
    --warn: #f4a27c;
    --warn-soft: #3d2418;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12171c;
  --surface: #1a2128;
  --surface-2: #222b33;
  --text: #e7ebee;
  --muted: #9aa7b1;
  --border: #2e3943;
  --brand: #7fb2e5;
  --brand-ink: #0d1a26;
  --brand-soft: #1d3247;
  --open: #6fcf97;
  --open-soft: #173a28;
  --taken: #7d868e;
  --taken-soft: #232a31;
  --warn: #f4a27c;
  --warn-soft: #3d2418;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--brand); }
[hidden] { display: none !important; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

.site-header {
  background: var(--brand);
  color: var(--brand-ink);
  padding: 28px 0 24px;
  margin-bottom: 24px;
}
.site-header h1 { margin: 0; font-size: 1.9rem; line-height: 1.2; letter-spacing: -0.01em; }
.eyebrow { margin: 0 0 4px; font-size: 0.85rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; }
.header-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 0 0 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.intro p { margin: 0; white-space: pre-line; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* ---------- calendar ---------- */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.875rem; color: var(--muted); margin-bottom: 12px; }
.legend span::before {
  content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  margin-right: 6px; vertical-align: -1px; border: 1px solid var(--border);
}
.legend .l-open::before { background: var(--open-soft); border-color: var(--open); }
.legend .l-taken::before { background: var(--taken-soft); }

.month { margin-bottom: 20px; }
.month h3 { margin: 0 0 8px; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dow { text-align: center; font-size: 0.75rem; font-weight: 600; color: var(--muted); padding: 2px 0; }
.day {
  min-height: 52px; border-radius: 8px; padding: 4px; text-align: center;
  font-size: 0.95rem; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid transparent; font: inherit; color: inherit; background: none;
}
.day .tag { font-size: 0.66rem; line-height: 1.1; margin-top: 2px; }
.day.off { color: var(--muted); opacity: 0.45; }
.day.taken { background: var(--taken-soft); color: var(--taken); }
.day.open {
  background: var(--open-soft); border-color: var(--open); color: var(--text);
  cursor: pointer; font-weight: 600;
}
.day.open .tag { color: var(--open); font-weight: 600; }
.day.open:hover { filter: brightness(0.97); }
.day.open.selected { background: var(--open); color: var(--surface); }
.day.open.selected .tag { color: var(--surface); }

/* ---------- forms ---------- */
form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { form .row { grid-template-columns: 1fr; } }
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 12px; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 1px;
}
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 12px; }
.checks label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; }
.checks input { width: auto; margin: 0; }
.trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.turnstile { min-height: 65px; margin: 4px 0 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.secondary { background: transparent; color: var(--brand); }
.btn.danger { background: transparent; color: var(--warn); border-color: var(--warn); }
.btn.small { padding: 6px 12px; font-size: 0.875rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.selected-date { font-size: 1.1rem; font-weight: 600; color: var(--open); margin: -4px 0 16px; }
.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.alert.error { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--open-soft); color: var(--open); }
.success h2 { color: var(--open); }

.footer { padding: 8px 16px 40px; font-size: 0.875rem; color: var(--muted); }

/* ---------- manage pages ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs button {
  border: none; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 14px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.header-actions .btn { border-color: var(--brand-ink); color: var(--brand-ink); background: transparent; }
.role-pill { font-size: 0.8rem; opacity: 0.85; margin-right: 8px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.seg button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.day-list { list-style: none; margin: 0; padding: 0; }
.day-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; display: grid; grid-template-columns: 112px 1fr; gap: 12px;
}
.day-item.is-today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.day-item.is-past { opacity: 0.65; }
@media (max-width: 520px) { .day-item { grid-template-columns: 1fr; gap: 6px; } }
.day-when { font-weight: 700; }
.day-when .time { display: block; font-weight: 600; color: var(--open); }
.day-who .name { font-weight: 700; font-size: 1.05rem; }
.day-who p { margin: 2px 0; overflow-wrap: anywhere; }
.day-who .notes { white-space: pre-line; color: var(--muted); font-size: 0.9rem; margin-top: 6px; }
.day-who .empty { color: var(--warn); font-weight: 600; }
.day-who .actions { margin-top: 10px; }
.badge-today { font-size: 0.7rem; background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: 2px; }

.stats { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 16px; font-size: 0.9rem; color: var(--muted); }
.stats b { color: var(--text); font-size: 1.1rem; }

.share { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.share code { background: var(--surface-2); padding: 6px 10px; border-radius: 6px; overflow-wrap: anywhere; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }

.login-card { max-width: 420px; margin: 0 auto; }

@media print {
  .site-header { background: none; color: #000; padding: 0; margin-bottom: 12px; }
  .tabs, .seg, .header-actions, .no-print, .actions, .footer { display: none !important; }
  .day-item { break-inside: avoid; box-shadow: none; }
  body { background: #fff; color: #000; }
}
