:root {
  --bg: #eef3ee; --surface: #fff; --fg: #15231a; --muted: #5a6b60; --line: #d5dfd6;
  --accent: #17693c; --accent-fg: #fff; --accent-soft: #e0eee4;
  --free: #e6f4ea; --free-fg: #17693c; --busy: #fbe4e1; --busy-fg: #a32a1e;
  --paid: #dcefe2; --paid-fg: #0f5a31; --pending: #fdf0d3; --pending-fg: #84510a;
  --block: #e3e6e4; --block-fg: #47524b; --past: #f2f5f2; --past-fg: #8b978f;
  --danger: #b3261e;
  --font: "Segoe UI", Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1712; --surface: #17211a; --fg: #e6efe8; --muted: #9db0a3; --line: #2c3a31;
    --accent: #58c088; --accent-fg: #08140d; --accent-soft: #1d3326;
    --free: #16301f; --free-fg: #7dd3a4; --busy: #3a1e1b; --busy-fg: #f2a99f;
    --paid: #1b3a27; --paid-fg: #8fdcb2; --pending: #38290f; --pending-fg: #e9bd70;
    --block: #262d29; --block-fg: #aab5ae; --past: #151c17; --past-fg: #66736b;
    --danger: #f2877d; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.45 var(--font); padding-bottom: env(safe-area-inset-bottom, 0); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 960px; margin: 0 auto; padding: 10px 16px 0; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-weight: 700; font-size: 1.05rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 2px; overflow-x: auto; margin-top: 6px; scrollbar-width: none; }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--accent); border-color: var(--accent); }
main { max-width: 960px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.btn { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.link { background: none; border: 0; color: var(--muted); padding: 4px 6px; font-weight: 500; }
.btn:disabled { opacity: .55; cursor: default; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }

.datebar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.datebar .day { font-weight: 700; font-size: 1.1rem; flex: 1 1 160px; min-width: 0; }
.datebar input { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .8125rem; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; border: 1px solid var(--line); }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.slot { text-align: left; border: 1px solid transparent; border-radius: 8px; padding: 10px 11px; min-height: 66px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.slot .h { font-weight: 700; font-variant-numeric: tabular-nums; }
.slot .w { font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot:hover { border-color: var(--accent); }
.s-free { background: var(--free); color: var(--free-fg); }
.s-booked { background: var(--busy); color: var(--busy-fg); }
.s-paid { background: var(--paid); color: var(--paid-fg); }
.s-pending { background: var(--pending); color: var(--pending-fg); }
.s-block { background: var(--block); color: var(--block-fg); }
.s-past { background: var(--past); color: var(--past-fg); }
.s-noshow { background: var(--block); color: var(--danger); }

.chip { display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.chip.bad { background: var(--busy); color: var(--busy-fg); }
.chip.warn { background: var(--pending); color: var(--pending-fg); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8125rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.kpi b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi span { color: var(--muted); font-size: .8125rem; }

.form { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .875rem; min-width: 0; }
label.f small { font-weight: 400; color: var(--muted); }
label.f input, label.f select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; font-weight: 400; font-size: 16px; }
label.c { display: flex; gap: 8px; align-items: center; font-weight: 500; }
h2.sec { font-size: 1rem; }
.err { color: var(--danger); font-size: .875rem; }

.login { max-width: 360px; margin: 10vh auto 0; padding: 0 16px; }
.login h1 { font-size: 1.4rem; margin-bottom: 14px; }

.modal { position: fixed; inset: 0; z-index: 20; background: rgba(8, 18, 12, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; border-radius: 14px 14px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 560px) { .modal { align-items: center; } .sheet { border-radius: 12px; } }
.sheet h3 { font-size: 1.1rem; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.receipt { max-width: 100%; border-radius: 6px; border: 1px solid var(--line); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 30; background: var(--fg); color: var(--bg); padding: 9px 14px; border-radius: 8px; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--danger); color: #fff; }
.empty { color: var(--muted); padding: 14px; text-align: center; }
