/* Cal360 dashboard */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #15181e;
  --text-2: #4b5563;
  --muted: #6b7280;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8efff;
  --accent-text: #ffffff;
  --good: #15803d;
  --good-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --neutral-soft: #eef0f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
  --sidebar: 236px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1e222a; --text: #e8eaee; --text-2: #b4bac4; --muted: #8b929e;
    --line: #2a2f38; --line-strong: #3a404b; --accent: #6b9bff; --accent-hover: #8ab0ff; --accent-soft: #1b2740; --accent-text: #0b1220;
    --good: #4ade80; --good-soft: #13281b; --warn: #fbbf24; --warn-soft: #2d2410; --bad: #f87171; --bad-soft: #2e1616; --neutral-soft: #242832;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a20; --surface-2: #1e222a; --text: #e8eaee; --text-2: #b4bac4; --muted: #8b929e;
  --line: #2a2f38; --line-strong: #3a404b; --accent: #6b9bff; --accent-hover: #8ab0ff; --accent-soft: #1b2740; --accent-text: #0b1220;
  --good: #4ade80; --good-soft: #13281b; --warn: #fbbf24; --warn-soft: #2d2410; --bad: #f87171; --bad-soft: #2e1616; --neutral-soft: #242832;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .92rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; word-break: break-all; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 6px 10px 14px; color: var(--text); }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: .8rem; }
.nav-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; background: var(--warn-soft); color: var(--warn); font-size: .75rem; font-weight: 700; padding: 0 7px; border-radius: 999px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: flex; align-items: center; gap: 10px; }
.sidebar-foot form { margin-left: auto; }
.main { min-width: 0; padding: 24px 32px 64px; max-width: 1280px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); gap: 2px; }
  .brand { padding: 0 8px 0 0; }
  .brand span:last-child, .nav-label, .sidebar-foot .who { display: none; }
  .nav { display: contents; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .sidebar-foot { margin: 0 0 0 8px; border: 0; padding: 0; }
  .main { padding: 16px 16px 48px; }
}

/* Page header */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
@media (max-width: 1000px) { .cols-2, .cols-3, .cols-main { grid-template-columns: 1fr; } }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: .78rem; }
a.stat:hover { text-decoration: none; border-color: var(--line-strong); }

/* Buttons */
.btn, button { font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-weight: 500; text-decoration: none; line-height: 1.4; }
.btn:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-good { background: var(--good); border-color: var(--good); color: #fff; }
.btn-good:hover { background: var(--good); filter: brightness(1.08); }
.btn-danger { color: var(--bad); border-color: var(--line-strong); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
button:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: default; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }

/* Forms */
form.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field > label, .label-text { font-weight: 600; font-size: .86rem; }
.field .help { color: var(--muted); font-size: .8rem; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date], input[type=time], input[type=search], input[type=color], input:not([type]), select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text);
}
input[type=color] { padding: 2px; height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; }
.check input { margin-top: 3px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.chip-check { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-weight: 500; }
.chip-check:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-check input { margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 16px 0 4px; }

/* Filters: one row above content */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters input[type=search] { min-width: 220px; flex: 1; max-width: 360px; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { background: var(--surface-2); color: var(--text-2); border-radius: 999px; padding: 0 7px; font-size: .75rem; margin-left: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-link { color: var(--text); font-weight: 600; }

/* Badges (status always has a text label) */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600; background: var(--neutral-soft); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.confirmed, .badge.good { background: var(--good-soft); color: var(--good); }
.badge.pending, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.rejected, .badge.bad, .badge.no_show { background: var(--bad-soft); color: var(--bad); }
.badge.cancelled { background: var(--neutral-soft); color: var(--muted); }
.badge.plain::before { display: none; }
.tag { display: inline-block; padding: 0 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); font-size: .78rem; color: var(--text-2); margin: 0 4px 4px 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* Agenda list */
.agenda-day { margin: 18px 0 8px; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.agenda-day:first-child { margin-top: 0; }
.agenda { display: grid; gap: 8px; }
.agenda-item { display: grid; grid-template-columns: 92px 4px 1fr auto; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--text); box-shadow: var(--shadow); }
.agenda-item:hover { border-color: var(--line-strong); text-decoration: none; }
.agenda-item .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.agenda-item .time span { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.agenda-item .bar { align-self: stretch; border-radius: 4px; }
.agenda-item .who { font-weight: 600; }
.agenda-item .what { color: var(--muted); font-size: .85rem; }
@media (max-width: 640px) { .agenda-item { grid-template-columns: 70px 4px 1fr; } .agenda-item > :last-child { grid-column: 3; } }

/* Description lists */
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) { dl.kv { grid-template-columns: 1fr; gap: 2px; } dl.kv dd { margin-bottom: 8px; } }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.t-note::before { background: var(--accent); }
.timeline li.t-good::before { background: var(--good); }
.timeline li.t-bad::before { background: var(--bad); }
.timeline li.t-warn::before { background: var(--warn); }
.timeline .meta { color: var(--muted); font-size: .8rem; }
.timeline .note { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin-top: 4px; white-space: pre-wrap; }

/* Avatars */
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; font-weight: 700; font-size: .75rem; flex: none; }
.person { display: flex; align-items: center; gap: 10px; }

/* Flash & alerts */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; overflow-wrap: anywhere; }
.flash.ok { background: var(--good-soft); border-color: transparent; color: var(--good); }
.flash.error { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.alert { padding: 12px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin-bottom: 16px; }
.alert a { color: inherit; text-decoration: underline; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 16px; }

/* Dropdown actions */
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > .menu-body { position: absolute; right: 0; z-index: 10; margin-top: 6px; min-width: 280px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .14); }

/* Availability editor */
.week { display: grid; gap: 4px; }
.week-day { display: grid; grid-template-columns: 140px 1fr; gap: 12px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.week-day:last-child { border-bottom: 0; }
.windows { display: grid; gap: 6px; }
.win { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.win input[type=time] { width: 120px; }
.win input[type=date] { width: 160px; }
.win input.grow { flex: 1; min-width: 160px; width: auto; }
.icon-btn { padding: 4px 8px; border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn:hover { color: var(--bad); background: var(--bad-soft); }
@media (max-width: 640px) { .week-day { grid-template-columns: 1fr; } }

/* Repeater editors (questions, routing) */
.rep-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--surface-2); display: grid; gap: 10px; }
.rep-list { display: grid; gap: 10px; margin-bottom: 10px; }
.rep-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.cond { display: grid; grid-template-columns: 1fr 140px 1fr auto; gap: 6px; }
@media (max-width: 640px) { .cond { grid-template-columns: 1fr; } }

/* Analytics */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 48px; gap: 10px; align-items: center; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.columns { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--line); padding-top: 8px; }
.columns .col { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; position: relative; }
.columns .col.zero { background: transparent; }
.columns .col:hover { filter: brightness(1.15); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; margin-top: 4px; }
.heat { display: grid; grid-template-columns: 36px repeat(24, minmax(10px, 1fr)); gap: 2px; font-size: .7rem; color: var(--muted); }
.heat .cell { aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); }
.heat .hl { text-align: center; }
.legend-scale { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: .75rem; margin-top: 8px; }
.legend-scale span.sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

/* Auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.auth .brand { justify-content: center; padding-bottom: 20px; }
