:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --panel: #f7f7f8;
  --card: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e3e3e6;
  --accent: #d98324;
  --accent-soft: #fdf2e2;
  --green: #0a7d33;
  --green-soft: #e6f4ea;
  --red: #b23a3a;
  --red-soft: #fbe9e9;
  --amber: #96690c;
  --amber-soft: #fdf3dc;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --panel: #1b1b1e;
    --card: #1e1e22;
    --fg: #ededf0;
    --muted: #9a9aa2;
    --line: #2d2d33;
    --accent: #e8a44e;
    --accent-soft: #33260f;
    --green: #56c47c;
    --green-soft: #14301d;
    --red: #e07b7b;
    --red-soft: #331717;
    --amber: #d9ac52;
    --amber-soft: #302712;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* ---------------------------------------------------------------- шапка */

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 16px;
  padding: 14px 0;
  white-space: nowrap;
}
.brand span { color: var(--accent); }

nav { display: flex; gap: 2px; flex-wrap: wrap; }

nav button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 14px 12px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
nav button:hover { color: var(--fg); }
nav button[aria-current="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  margin-left: 6px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}
.badge:empty, .badge[hidden] { display: none; }

main { padding: 20px 16px 60px; max-width: 1400px; margin: 0 auto; }

h2 { font-size: 18px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 18px; }

/* --------------------------------------------------------------- фильтры */

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 12px; color: var(--muted); }

input, select, textarea, button {
  font: inherit;
  color: var(--fg);
}

input, select, textarea {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  min-height: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
textarea { min-height: 70px; resize: vertical; }

.btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  min-height: 36px;
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--card); color: var(--fg); border-color: var(--line); font-weight: 500; }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* -------------------------------------------------------------- таблицы */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 180px; }

.link { color: var(--accent); cursor: pointer; text-decoration: none; border-bottom: 1px dotted currentColor; }

/* ----------------------------------------------------------------- чипы */

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.new       { background: var(--panel);      color: var(--muted); }
.chip.confirmed { background: var(--accent-soft); color: var(--amber); }
.chip.completed { background: var(--green-soft); color: var(--green); }
.chip.no_show   { background: var(--red-soft);   color: var(--red); }
.chip.cancelled { background: var(--panel);      color: var(--muted); text-decoration: line-through; }
.chip.draft     { background: var(--amber-soft); color: var(--amber); }
.chip.paid      { background: var(--green-soft); color: var(--green); }
.chip.unpaid    { background: var(--panel);      color: var(--muted); }
.chip.prepaid   { background: var(--amber-soft); color: var(--amber); }
.chip.refunded  { background: var(--red-soft);   color: var(--red); }

/* --------------------------------------------------------------- плитки */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }

.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.tile .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.tile .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .note { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ------------------------------------------------------------ расписание */

.timeline { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }

.master-col {
  flex: 1 0 230px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.master-col > h4 {
  margin: 0;
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.master-col > h4 small { display: block; color: var(--muted); font-weight: 400; }
.slots { padding: 8px; display: flex; flex-direction: column; gap: 6px; min-height: 60px; }

.visit {
  border-left: 3px solid var(--accent);
  background: var(--panel);
  border-radius: 6px;
  padding: 7px 9px;
  cursor: pointer;
  font-size: 13px;
}
.visit:hover { background: var(--accent-soft); }
.visit.completed { border-left-color: var(--green); }
.visit.no_show   { border-left-color: var(--red); opacity: .65; }
.visit.cancelled { border-left-color: var(--muted); opacity: .45; text-decoration: line-through; }
.visit .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.visit .c { color: var(--muted); }

.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---------------------------------------------------------------- модаль */

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--fg);
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
dialog .head h3 { margin: 0; font-size: 16px; }
dialog .body { padding: 18px; overflow-y: auto; }
dialog .foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap;
}
.close { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

.slot-list { display: flex; flex-wrap: wrap; gap: 6px; }
.slot-list button {
  background: var(--card); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 11px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.slot-list button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.err {
  background: var(--red-soft); color: var(--red);
  padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; font-weight: 500;
}
.ok {
  background: var(--green-soft); color: var(--green);
  padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; font-weight: 500;
}

dl.kv { margin: 0; }
dl.kv div { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--line); }
dl.kv div:last-child { border-bottom: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; font-weight: 500; }

.note-item { padding: 9px 0; border-bottom: 1px solid var(--line); }
.note-item:last-child { border-bottom: 0; }
.note-item .meta { font-size: 12px; color: var(--muted); }
.note-item.pinned { background: var(--accent-soft); border-radius: 8px; padding: 9px 11px; margin-bottom: 8px; border-bottom: 0; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 11px 20px; border-radius: 10px; font-weight: 600;
  z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  header { gap: 8px; }
  .brand { padding: 12px 0; }
  main { padding: 16px 12px 48px; }
}

/* Кнопки-ссылки выгрузки. <a> — строчный элемент, без этого
   отступы и высота у него не такие, как у соседних <button>. */
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
/* Заголовок отчёта и кнопка выгрузки рядом на одной строке */
#main h3 { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; font-size: 15px; }

/* ─────────────────────────────────────────────── экран писем */
.mail-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; margin-bottom: 26px; }
.mail-list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.mail-group { font-size: 12px; color: var(--muted); padding: 10px 10px 4px; }
.mail-list button {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--fg); cursor: pointer; font-size: 14px;
}
.mail-list button:hover { background: var(--panel); }
.mail-list button[aria-pressed="true"] { background: var(--accent-soft); color: var(--amber); font-weight: 600; }
.mail-editor { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.mail-editor textarea { width: 100%; font: 14px/1.6 ui-monospace, Consolas, monospace; resize: vertical; }
.mail-actions { display: flex; gap: 10px; margin-top: 14px; }
.mail-preview { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.mail-preview-head { background: var(--panel); padding: 8px 14px; font-size: 12px; color: var(--muted); }
.mail-preview-subject { padding: 12px 14px 0; font-weight: 700; }
.mail-preview-body { padding: 10px 14px 16px; line-height: 1.6; }
@media (max-width: 860px) { .mail-layout { grid-template-columns: 1fr; } }
/* Флажок с подписью в одну строку */
label.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; }
label.check input { width: 16px; height: 16px; }

/* Дети в карточке клиента */
.kids { list-style: none; margin: 0 0 12px; padding: 0; }
.kids li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kids li:last-child { border-bottom: 0; }
.kid-name { font-weight: 600; }
.kid-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.kid-form input, .kid-form select { flex: 1 1 130px; min-width: 0; }
.link-danger {
  margin-left: auto; background: none; border: 0; color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0 6px;
}
.link-danger:hover { color: var(--red); }

/* Настройка второго фактора */
.steps { margin: 0 0 14px; padding-left: 20px; line-height: 1.7; }
.secret {
  font: 16px/1.5 ui-monospace, Consolas, monospace; letter-spacing: .1em;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 8px 0; user-select: all; word-break: break-all;
}
.qr { margin-bottom: 14px; }
.qr .btn { display: inline-flex; margin-bottom: 8px; }
.codes { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.codes code {
  font: 15px/1.4 ui-monospace, Consolas, monospace; letter-spacing: .05em;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; text-align: center; user-select: all;
}

/* Подсказка, когда за выбранный период ничего нет */
.notice {
  background: var(--accent-soft); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 18px;
  color: var(--fg); line-height: 1.5;
}
