:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e1e6e3;
  --text: #17201c;
  --muted: #64706a;
  --accent: #0b6e4f;
  --accent-hover: #095c42;
  --accent-soft: #e3f2ec;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff5d6;
  --info: #1d5fbf;
  --info-soft: #e6effc;
  --pill: #eef3f0;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --surface: #171d1a;
    --surface-2: #1c2420;
    --border: #2a3430;
    --text: #e6ece9;
    --muted: #93a19a;
    --accent: #3fbf8f;
    --accent-hover: #5ad0a3;
    --accent-soft: #16352a;
    --on-accent: #0f1412;
    --danger: #ff8a80;
    --danger-soft: #3a1c1a;
    --warn: #f0c060;
    --warn-soft: #3a3016;
    --info: #8db8ff;
    --info-soft: #1a2940;
    --pill: #232c28;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171d1a; --surface-2: #1c2420; --border: #2a3430; --text: #e6ece9; --muted: #93a19a;
  --accent: #3fbf8f; --accent-hover: #5ad0a3; --accent-soft: #16352a; --on-accent: #0f1412; --danger: #ff8a80; --danger-soft: #3a1c1a;
  --warn: #f0c060; --warn-soft: #3a3016; --info: #8db8ff; --info-soft: #1a2940; --pill: #232c28;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.layout > div { min-width: 0; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 18px; }
.brand img { width: 32px; height: 32px; }
.brand b { display: block; font-size: 15px; }
.brand span { font-size: 12px; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .badge { margin-left: auto; }
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: 10px 12px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); }
.sidebar .who b { color: var(--text); display: block; }

.main { padding: 24px 28px 64px; min-width: 0; max-width: 1280px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.topbar { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 20;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 10px 16px;
  }
  .topbar img { width: 28px; height: 28px; }
  .topbar b { font-size: 15px; }
  .topbar .who { margin-left: auto; font-size: 13px; color: var(--muted); }
  .main { padding: 16px 16px 96px; }
  .bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(var(--cols, 4), 1fr);
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 4px; font-size: 11px; color: var(--muted); text-decoration: none; position: relative;
  }
  .bottom-nav a .ico { font-size: 19px; line-height: 1; }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav .badge { position: absolute; top: 4px; left: calc(50% + 6px); }
}
@media (min-width: 861px) { .bottom-nav { display: none; } }

/* ---------- элементы ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 6px; font-size: 16px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700;
}
.status { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status.new { background: var(--info-soft); color: var(--info); }
.status.in_work { background: var(--warn-soft); color: var(--warn); }
.status.enrolled, .status.answered { background: var(--accent-soft); color: var(--accent); }
.status.rejected, .status.closed { background: var(--pill); color: var(--muted); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip .n { color: var(--muted); font-weight: 500; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type="search"] { max-width: 280px; }
.filters select { width: auto; }

/* ---------- списки ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 13px 18px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text);
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.list-item .num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .side { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
@media (max-width: 560px) {
  .list-item { grid-template-columns: minmax(0, 1fr) auto; padding: 12px 14px; }
  .list-item .num { display: none; }
}
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

dl.props { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 14px; margin: 0; }
dl.props dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
dl.props dd { margin: 0; word-break: break-word; }
@media (max-width: 560px) { dl.props { grid-template-columns: 1fr; gap: 2px; } dl.props dd { margin-bottom: 8px; } }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.tl-item { border-left: 3px solid var(--border); padding: 2px 0 2px 12px; }
.tl-item.ok { border-color: var(--accent); }
.tl-item.err { border-color: var(--danger); }
.tl-item .meta { font-size: 12px; color: var(--muted); }

.bubble { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.bubble.answer { background: var(--accent-soft); border-color: transparent; }
.bubble .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.bubble.err { border-color: var(--danger); }

.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 8px; }
.back:hover { color: var(--text); }

/* ---------- расписание ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 14px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.meta-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; padding: 14px 18px; margin-bottom: 16px; }
.meta-bar label.field { min-width: 170px; }
@media (max-width: 560px) { .meta-bar label.field, .meta-bar label.field.grow { min-width: 100%; } }
.meta-bar label.field.grow { flex: 1; min-width: 220px; }

.coach-block { margin-bottom: 14px; overflow: hidden; }
.coach-head { display: flex; gap: 12px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.coach-head .avatar {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700;
}
.coach-head .info { min-width: 0; }
.coach-head .info .sub { color: var(--muted); font-size: 13px; }
.coach-head .actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.inactive-tag { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--pill); padding: 1px 7px; border-radius: 6px; margin-left: 6px; }

.tablewrap { overflow-x: auto; }
table.week { width: 100%; border-collapse: collapse; min-width: 860px; font-size: 13px; }
table.week th, table.week td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; vertical-align: top; }
table.week th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--surface-2); }
table.week tr:last-child td { border-bottom: 0; }
table.week td.gname { min-width: 150px; }
table.week td.gname b { display: block; font-size: 14px; }
table.week td.gname .sub { color: var(--muted); font-size: 12px; }
table.week tr.inactive td { opacity: .55; }
table.week tr.clickable { cursor: pointer; }
table.week tr.clickable:hover td { background: var(--surface-2); }
.slot { display: block; background: var(--pill); border-radius: 6px; padding: 3px 7px; margin-bottom: 4px; white-space: nowrap; }
.slot small { color: var(--muted); display: block; font-size: 11px; }
.off { color: var(--muted); }
.coach-empty { padding: 14px 18px; color: var(--muted); font-size: 14px; }

.slots-editor { display: flex; flex-direction: column; gap: 8px; }
.slot-row { display: grid; grid-template-columns: 84px 128px 128px minmax(0, 1fr) auto; gap: 6px; align-items: center; }
@media (max-width: 560px) {
  .slot-row { grid-template-columns: 72px minmax(0, 1fr) minmax(0, 1fr) auto; }
  .slot-row .place { grid-column: 1 / -1; grid-row: 2; }
  .slot-row { padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
}

/* ---------- диалог ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(720px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(10, 16, 13, .45); }
.dlg-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { margin: 0; }
.dlg-head .icon-btn { margin-left: auto; }
.dlg-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.dlg-foot .left { margin-right: auto; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 8px 12px; font-size: 14px; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; }
.login-card .brand { padding: 0 0 20px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); color: #fff; }
@media (max-width: 860px) { .toast { bottom: 84px; } }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; text-decoration: none; color: var(--text); }
.stat .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
a.stat:hover { border-color: var(--accent); }

table.users { width: 100%; border-collapse: collapse; }
table.users th, table.users td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; }
table.users th { color: var(--muted); font-size: 12px; font-weight: 600; }

.login-card.wide { width: min(460px, 100%); }
.login-card p { margin: 0 0 16px; }
ul.rules { list-style: none; margin: -4px 0 0; padding: 0; display: grid; gap: 3px; font-size: 13px; color: var(--muted); }
ul.rules li::before { content: '○'; display: inline-block; width: 18px; }
ul.rules li.ok { color: var(--accent); }
ul.rules li.ok::before { content: '✓'; }
