/* servecal shared styles — mobile first. Pages add only page-specific rules.
   Breakpoint: 720px (phones below, tablets/desktop above). */

:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #16181d;
  --muted: #5f6673;
  --line: #e3e6eb;
  --brand: #23324a;
  --brand-ink: #ffffff;
  --brand-soft: #e8edf5;
  --ok: #16794f;
  --ok-soft: #e6f4ea;
  --warn: #b45309;
  --warn-soft: #fff4d6;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --open: #dc6803;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1216;
    --surface: #181c22;
    --surface-2: #1f242c;
    --ink: #e8eaee;
    --muted: #9aa3b2;
    --line: #2c323c;
    --brand: #8fb3ff;
    --brand-ink: #0f1216;
    --brand-soft: #1f2a3d;
    --ok: #4cc38a;
    --ok-soft: #133526;
    --warn: #f0b24a;
    --warn-soft: #3a2c10;
    --danger: #ff8a80;
    --danger-soft: #3d1a18;
    --open: #ff9f45;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--brand); }
[hidden] { display: none !important; }

/* --- Layout ------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 17px; margin: 0; line-height: 1.2; }
.topbar .sub { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.topbar nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.topbar nav a { text-decoration: none; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.wrap.wide { max-width: 1040px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card > h2, .card-title { font-size: 16px; margin: 0 0 4px; }
.card > .sub, p.sub { font-size: 14px; color: var(--muted); margin: 0 0 14px; }

.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }

@media (min-width: 720px) {
  .topbar { padding: 14px 24px; }
  .wrap { padding: 24px; }
  .card { padding: 20px; }
}

/* --- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-size: 15px; font-weight: 600; text-decoration: none;
  cursor: pointer; touch-action: manipulation;
  background: var(--surface-2); color: var(--ink); border-color: var(--line);
}
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); padding: 0 8px; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent);
  outline-offset: 2px;
}

/* --- Forms ---------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: 14px; font-weight: 600; }
.field .hint { font-size: 13px; color: var(--muted); font-weight: 400; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=date], input[type=time],
input:not([type]), select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
textarea { min-height: 88px; resize: vertical; }
.form-grid { display: grid; gap: 12px; }
@media (min-width: 720px) {
  .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
}

/* Pill toggles for multi-select (roles, Sundays of the month). */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 15px; cursor: pointer; user-select: none;
}
.chip input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip input:checked + span::before { content: "✓"; font-weight: 700; }

/* Stacked radio options with a description line. */
.options { display: grid; gap: 8px; }
.option {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; background: var(--surface);
}
.option input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brand); flex-shrink: 0; }
.option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.option b { display: block; font-size: 15px; }
.option small { color: var(--muted); font-size: 13px; }

/* --- Feedback --------------------------------------------------------------- */

.notice { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; margin-bottom: 16px; background: var(--warn-soft); }
.notice.ok { background: var(--ok-soft); }
.notice.bad { background: var(--danger-soft); }
.notice.info { background: var(--brand-soft); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }
.badge {
  display: inline-block; font-size: 12px; font-weight: 600; line-height: 1;
  padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  vertical-align: middle;
}
.badge.warn { background: var(--open); color: #fff; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.toast {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  z-index: 60; box-shadow: var(--shadow);
}

/* --- Lists (slots, assignments) ----------------------------------------------- */

.list { display: flex; flex-direction: column; }
.item { display: flex; flex-direction: column; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: none; padding-top: 0; }
.item .title { font-weight: 600; }
.item .meta { font-size: 14px; color: var(--muted); }
.item .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.item .actions .btn { flex: 1 1 auto; }
@media (min-width: 720px) {
  .item { flex-direction: row; align-items: center; justify-content: space-between; }
  .item .actions .btn { flex: 0 0 auto; }
}
.empty { color: var(--muted); font-size: 14px; }

/* --- Responsive tables: rows become cards under 720px --------------------------- */

.rtable { width: 100%; border-collapse: collapse; font-size: 15px; }
.rtable th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
.rtable td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
@media (max-width: 719px) {
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tr { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 10px; background: var(--surface); }
  .rtable td { border: none; padding: 4px 0; display: flex; gap: 12px; }
  .rtable td[data-label]::before { content: attr(data-label); flex: 0 0 88px; color: var(--muted); font-size: 13px; padding-top: 2px; }
  .rtable td.primary { font-weight: 600; font-size: 16px; }
  .rtable td.primary::before { display: none; }
  .rtable td.actions { padding-top: 8px; flex-wrap: wrap; }
  .rtable td:empty { display: none; }
}

/* --- Tabs ----------------------------------------------------------------------- */

.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 16px; padding: 0 16px 2px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  font: inherit; font-size: 15px; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.tabs button.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.tabs .count { margin-left: 6px; }
@media (min-width: 720px) { .tabs { margin: 0 0 20px; padding: 0; } }

/* --- Sheet / dialog: bottom sheet on phones, centered dialog above ----------------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; }
  .sheet { width: 440px; border-radius: var(--radius); }
}

/* --- Legend / status dots --------------------------------------------------------- */

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* --- FullCalendar ------------------------------------------------------------------- */

.fc {
  --fc-border-color: var(--line);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: var(--surface-2);
  --fc-today-bg-color: var(--brand-soft);
  --fc-list-event-hover-bg-color: var(--surface-2);
  --fc-button-bg-color: var(--brand);
  --fc-button-border-color: var(--brand);
  --fc-button-text-color: var(--brand-ink);
  --fc-button-hover-bg-color: var(--brand);
  --fc-button-hover-border-color: var(--brand);
  --fc-button-active-bg-color: var(--brand);
  --fc-button-active-border-color: var(--brand);
  font-size: 14px;
}
.fc .fc-toolbar { gap: 8px; }
.fc .fc-toolbar-title { font-size: 18px; }
.fc .fc-button { min-height: 40px; min-width: 44px; }
.fc .fc-daygrid-day-number, .fc .fc-col-header-cell-cushion { color: var(--ink); text-decoration: none; }
.fc-event.status-open, .fc-list-event.status-open .fc-list-event-dot { background: var(--open); border-color: var(--open); }
.fc-event.status-assigned, .fc-list-event.status-assigned .fc-list-event-dot { background: var(--ok); border-color: var(--ok); }
.fc-list-event.status-open, .fc-list-event.status-assigned { background: transparent; }
@media (min-width: 720px) { .fc .fc-toolbar-title { font-size: 22px; } }
