:root {
  --bg: #f5f4f1;
  --panel: #ffffff;
  --fg: #1d1d1f;
  --muted: #6b6b70;
  --line: #e4e2dd;
  --soft: #efede8;
  --accent: #1f5f4a;
  --accent-fg: #ffffff;
  --danger: #b3261e;
  --ok: #1f7a3a;
  --warn: #9a6700;
  --info: #1d4f91;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161617;
    --panel: #1f1f21;
    --fg: #f2f2f4;
    --muted: #9a9aa0;
    --line: #333336;
    --soft: #29292c;
    --accent: #5fbf9a;
    --accent-fg: #0f1a15;
    --danger: #ff8a80;
    --ok: #7bd88f;
    --warn: #f0c060;
    --info: #8ab4f8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 14px; }
.boot, .muted { color: var(--muted); }
.boot { padding: 40px; text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ── Кнопки и поля ── */
button, .btn {
  font: inherit; border: 1px solid transparent; border-radius: 8px; padding: 7px 12px; cursor: pointer;
  background: var(--accent); color: var(--accent-fg); white-space: nowrap; text-decoration: none; display: inline-block;
}
button:disabled { opacity: .55; cursor: default; }
button.ghost, .btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
button.ghost:hover:not(:disabled) { background: var(--soft); }
button.danger { background: transparent; color: var(--danger); border-color: var(--line); }
button.small, .btn.small { padding: 4px 9px; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ── Вход ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 12px; }
.login h1 { margin-bottom: 4px; }

/* ── Каркас ── */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 14px; }
.side .brand { font-weight: 700; font-size: 17px; padding: 0 8px; }
.side .group { display: grid; gap: 2px; }
.side .group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 8px 4px; }
.side a { color: var(--fg); text-decoration: none; padding: 6px 8px; border-radius: 7px; }
.side a:hover { background: var(--soft); }
.side a.active { background: var(--soft); font-weight: 600; }
.side .spacer { flex: 1; }
main { padding: 22px 26px 60px; min-width: 0; }
.head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.head h1 { margin-right: auto; }
.head > select, .head > input { width: auto; }
.crumbs { color: var(--muted); margin: -8px 0 14px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; flex-direction: row; flex-wrap: wrap; gap: 2px 4px; align-items: center; }
  .side .brand { width: 100%; padding-bottom: 6px; }
  .side .group { display: contents; }
  .side a { padding: 4px 8px; }
  .side .group-title, .side .spacer { display: none; }
  main { padding: 16px; }
}

/* ── Таблицы ── */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--soft); }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
td.actions > * + * { margin-left: 6px; }
td .sub { color: var(--muted); font-size: 12.5px; }
td > b { white-space: nowrap; }
td.wrap { max-width: 320px; min-width: 140px; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--soft); display: block; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.more { margin-top: 12px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--soft); white-space: nowrap; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.info { color: var(--info); }
.pill.danger { color: var(--danger); }

/* ── Диалоги ── */
dialog.sheet { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--panel); color: var(--fg); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .4); }
dialog.sheet form { padding: 22px; display: grid; gap: 12px; }
.fields { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field > .label { font-weight: 600; font-size: 13px; }
.field > .label .col { font-weight: 400; color: var(--muted); margin-left: 6px; }
.field.check { grid-template-columns: auto 1fr; align-items: center; gap: 8px; }
.field .row { display: flex; gap: 8px; align-items: center; }
.field .row img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--soft); }
.actions { display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: -22px; background: var(--panel); padding: 10px 0 0; }
.error { color: var(--danger); margin: 0; min-height: 1em; white-space: pre-wrap; }

/* ── Карточки урока ── */
.cards { display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.card.invalid { border-color: var(--danger); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card-head .n { font-weight: 700; color: var(--muted); min-width: 22px; }
.card-head select { width: auto; }
.card-head .summary { flex: 1; min-width: 160px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card textarea { min-height: 140px; }
.sticky-bar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 10px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sticky-bar select { width: auto; }
.dirty { color: var(--warn); font-weight: 600; }

/* ── Уведомления ── */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); }
.toast.bad { background: var(--danger); color: #fff; }
