:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2430;
  --muted: #667085;
  --accent: #2f6fde;
  --accent-soft: #e5eefc;
  --good: #1a8a5a;
  --good-soft: #e3f4ec;
  --bad: #c2412d;
  --bad-soft: #fbe9e6;
  --warn: #b7791f;
  --booked: #d9dde3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #222733;
    --border: #2e3442;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --accent: #6b9cf0;
    --accent-soft: #1f2d48;
    --good: #4cc38a;
    --good-soft: #17352a;
    --bad: #f07a66;
    --bad-soft: #3d201b;
    --warn: #e0b04f;
    --booked: #2c323f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

header.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header.top .inner {
  max-width: 1280px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 24px; height: 56px;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); display: flex; gap: 8px; align-items: center; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
nav .spacer { flex: 1; }

.userbox { display: flex; align-items: center; gap: 4px; }
.userbox a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.userbox a.active, .userbox a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
button.link { border: none; background: none; color: var(--muted); padding: 6px 8px; }
button.link:hover { color: var(--text); background: var(--surface-2); }
body:not([data-role="admin"]) .admin-only { display: none !important; }
.login-wrap { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; padding: 28px; text-align: center; }
.login-card form { text-align: left; display: grid; gap: 14px; margin-top: 20px; }
.logo.big { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: #fff; font-size: 28px;
  display: grid; place-items: center; margin: 0 auto 14px; }
.error { color: var(--bad); min-height: 1.2em; font-size: 13px; }

main { max-width: 1280px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.two { grid-template-columns: 2fr 1fr; }
.half { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two, .half { grid-template-columns: 1fr; } }
.section { margin-top: 16px; }
.chart-box { position: relative; height: 280px; }

button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: progress; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.r, th.r { text-align: right; }
td.num { white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.up { color: var(--good); }
.down { color: var(--bad); }

/* Календарь */
.cal-head, .cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-head div { font-size: 12px; color: var(--muted); text-align: center; padding-bottom: 4px; }
.cell {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 7px; min-height: 74px;
  background: var(--surface); cursor: pointer; position: relative; font-size: 12px;
  display: flex; flex-direction: column; gap: 1px; overflow: hidden;
}
.cell:hover { border-color: var(--accent); }
.cell.selected { outline: 2px solid var(--accent); }
.cell.empty { visibility: hidden; }
.cell .d { display: flex; justify-content: space-between; color: var(--muted); }
.cell .d b { color: var(--text); }
.cell .cur { font-variant-numeric: tabular-nums; }
.cell .rec { font-weight: 650; font-variant-numeric: tabular-nums; }
.cell .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
.cell.booked { background: var(--booked); }
.cell.blocked { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, var(--surface) 6px, var(--surface) 12px); }
.cell .tag { font-size: 10px; }
.cell.weekend .d b { color: var(--accent); }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-left: 2px; }
.dot.hol { background: var(--bad); }
.dot.ev { background: var(--warn); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }

.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; font-variant-numeric: tabular-nums; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input { width: 120px; }

#toast {
  position: fixed; right: 16px; bottom: 16px; max-width: 360px;
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px;
  opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 50;
}
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--bad); color: #fff; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
