/* Кабинет аналитики. Светлая и тёмная тема — через токены на :root. */

:root {
  --bg: #f4f7fc;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --surface-hover: #f1f5fb;
  --border: #e4e9f2;
  --border-strong: #d3dbe8;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #8391a7;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8f0fe;
  --green: #16a34a;
  --green-soft: #e7f6ec;
  --orange: #f59e0b;
  --orange-soft: #fef3dc;
  --red: #dc2626;
  --red-soft: #fdeaea;
  --violet: #7c3aed;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 12px 48px rgba(15, 23, 42, .16);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #131b2e; --surface-2: #172036; --surface-hover: #1c2640;
    --border: #243049; --border-strong: #2f3d5a; --text: #e8edf6; --text-2: #aab6ca; --text-3: #75839b;
    --primary: #5b8cff; --primary-hover: #7aa2ff; --primary-soft: #1b2a4d;
    --green: #34c26b; --green-soft: #133224; --orange: #fbb13c; --orange-soft: #3a2c10; --red: #f06262; --red-soft: #3b1a1d;
    --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 12px 48px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #131b2e; --surface-2: #172036; --surface-hover: #1c2640;
  --border: #243049; --border-strong: #2f3d5a; --text: #e8edf6; --text-2: #aab6ca; --text-3: #75839b;
  --primary: #5b8cff; --primary-hover: #7aa2ff; --primary-soft: #1b2a4d;
  --green: #34c26b; --green-soft: #133224; --orange: #fbb13c; --orange-soft: #3a2c10; --red: #f06262; --red-soft: #3b1a1d;
  --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 12px 48px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Каркас ── */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 15px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed); box-shadow: 0 4px 12px rgba(37, 99, 235, .35); }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--text-3); }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; border: 0; background: none; cursor: pointer; text-align: left; width: 100%;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.nav-item .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 13px; }
.user-chip b { display: block; font-size: 13px; }
.user-chip span { font-size: 12px; color: var(--text-3); }

.main { min-width: 0; padding: 24px 32px 48px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.topbar .subtitle { color: var(--text-3); margin-top: 2px; }
.fresh { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); flex: none; }
.dot.warn { background: var(--orange); box-shadow: 0 0 0 4px var(--orange-soft); }
.dot.bad { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }

/* ── Панель фильтров ── */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: 13px; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(37, 99, 235, .3); }
.field { display: inline-flex; align-items: center; gap: 6px; }
.field label { font-size: 12px; color: var(--text-3); }
.input, .select {
  height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  min-width: 0; transition: border-color .15s;
}
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.select { padding-right: 32px; appearance: none; cursor: pointer; max-width: 360px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238391a7' stroke-width='2'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); }
.search .input { padding-left: 34px; width: 240px; }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-hover); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: none; }
.icon-btn { width: 36px; padding: 0; justify-content: center; }

/* ── Карточки ── */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.card-head .hint { color: var(--text-3); font-size: 12px; }
.card-body { padding: 16px 20px 20px; }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi-value small { font-size: 14px; font-weight: 500; color: var(--text-3); margin-left: 2px; }
.kpi-foot { font-size: 12px; color: var(--text-3); min-height: 18px; }
.kpi-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.kpi-icon svg { width: 16px; height: 16px; }
.tone-blue { background: var(--primary-soft); color: var(--primary); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-orange { background: var(--orange-soft); color: var(--orange); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-violet { background: color-mix(in srgb, var(--violet) 14%, transparent); color: var(--violet); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.gray { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* ── Таблицы ── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
.data th { position: sticky; top: 0; z-index: 1; text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data th.sortable { cursor: pointer; user-select: none; }
.data th.sortable:hover { color: var(--text); }
.data th[aria-sort] { color: var(--primary); }
.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data tbody tr { transition: background .1s; }
.data tbody tr.clickable { cursor: pointer; }
.data tbody tr:hover { background: var(--surface-hover); }
.data tbody tr:last-child td { border-bottom: 0; }
.data .r { text-align: right; }
.data .c { text-align: center; }
.person { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.person b { font-weight: 600; display: block; }
.person .sub { font-size: 12px; color: var(--text-3); }
.gc-link { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--text-3); }
.gc-link:hover { color: var(--primary); }
.gc-link svg { width: 12px; height: 12px; }

/* ── Прохождение: матрица ── */
.module-head { display: flex; align-items: center; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.module-head h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.module-head h2 svg { width: 22px; height: 22px; color: var(--primary); }
.bars { margin-left: auto; display: grid; gap: 6px; min-width: 280px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 44px; align-items: center; gap: 10px; font-size: 12px; color: var(--text-2); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.bar i.green { background: var(--green); }
.bar-row b { text-align: right; color: var(--text); }
.matrix th.lesson { text-transform: none; letter-spacing: 0; font-size: 12px; min-width: 112px; max-width: 150px; white-space: normal; text-align: center; vertical-align: bottom; line-height: 1.3; }
.matrix th.lesson .ln { color: var(--text); font-weight: 600; display: block; }
.matrix th.lesson .lt { font-weight: 400; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.matrix td.cell { text-align: center; padding: 8px; }
.matrix .sticky { position: sticky; left: 0; background: var(--surface); z-index: 2; box-shadow: 1px 0 0 var(--border); }
.matrix thead .sticky { background: var(--surface-2); z-index: 3; }
.matrix tbody tr:hover .sticky { background: var(--surface-hover); }
.matrix tr.group-row td { background: var(--surface-2); font-weight: 600; }
.matrix tr.group-row .share { font-size: 13px; }
.st { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; }
.st svg { width: 15px; height: 15px; }
.st.accepted { background: var(--green); color: #fff; }
.st.new { background: var(--orange); color: #fff; }
.st.declined { background: var(--red); color: #fff; }
.st.none { border: 2px solid var(--border-strong); width: 24px; height: 24px; }
.st.other { background: var(--primary); color: #fff; }
a.st:hover { transform: scale(1.12); transition: transform .1s; }
.pct { display: block; font-size: 11px; color: var(--text-3); margin-top: 3px; }
.gauge { display: inline-flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--text-2); min-width: 64px; }
.gauge svg { width: 54px; height: 30px; margin-top: 2px; }
.gauge .g-val { font-size: 11px; font-weight: 600; margin-top: -14px; color: var(--text); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .st { width: 18px; height: 18px; }
.legend .st svg { width: 11px; height: 11px; }
.legend .st.none { width: 16px; height: 16px; }

/* ── График ── */
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .tip-target:hover rect { opacity: .85; }
.chart-tip { position: fixed; pointer-events: none; z-index: 50; background: var(--text); color: var(--surface); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow-lg); white-space: nowrap; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ── Списки внимания ── */
.alerts { display: flex; flex-direction: column; }
.alert { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.alert:last-child { border-bottom: 0; }
.alert .kpi-icon { margin-top: 1px; }
.alert b { display: block; font-weight: 600; }
.alert p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }

/* ── Выдвижная карточка ── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 40; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--bg); z-index: 41;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .2s ease-out; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 18px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { overflow-y: auto; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 26px 1fr auto; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); align-items: start; }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat span { font-size: 12px; color: var(--text-3); }
.stat b { display: block; font-size: 20px; margin-top: 2px; }

/* ── Состояния ── */
.skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 40px; height: 40px; margin-bottom: 10px; color: var(--border-strong); }
.empty b { display: block; color: var(--text-2); font-size: 15px; margin-bottom: 4px; }
.error-box { padding: 16px 20px; border-radius: var(--radius); background: var(--red-soft); color: var(--red); margin-bottom: 16px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); color: var(--text-2); font-size: 13px; }
.note { font-size: 12px; color: var(--text-3); padding: 12px 20px; border-top: 1px solid var(--border); }
.wait { font-weight: 600; }
.wait.ok { color: var(--green); }
.wait.mid { color: var(--orange); }
.wait.bad { color: var(--red); }

/* ── Вход ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 80% -10%, color-mix(in srgb, var(--primary) 16%, transparent), transparent), var(--bg); }
.login-card { width: min(400px, 100%); padding: 32px; }
.login-card h1 { margin: 16px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; color: var(--text-3); }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.login-card .input { height: 42px; width: 100%; }
.login-card .btn { height: 44px; justify-content: center; font-size: 15px; }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ── Мобильные ── */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .person { min-width: 150px; }
  .person .avatar { display: none; }
  .matrix th.lesson { min-width: 88px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; z-index: 30; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto;
    border-right: 0; border-bottom: 1px solid var(--border); gap: 2px; }
  .brand { padding: 0 8px 0 0; }
  .brand small, .brand span { display: none; }
  .nav-item { width: auto; padding: 8px 10px; white-space: nowrap; }
  .nav-item span { display: none; }
  .nav-item[aria-current="page"] span { display: inline; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; flex-direction: row; }
  .user-chip { display: none; }
  .main { padding: 16px 16px 40px; }
  .topbar h1 { font-size: 20px; }
  .search .input { width: 100%; }
  .search { flex: 1 1 100%; }
  .bars { margin-left: 0; min-width: 0; width: 100%; }
  .kpi-value { font-size: 24px; }
}

/* ── Формы раздела «ИИ-куратор» ── */
.form { display: grid; gap: 18px; }
.field-block { display: grid; gap: 6px; }
.field-block > label { font-weight: 600; font-size: 14px; }
.field-block .hint { color: var(--text-3); font-size: 12px; margin-top: -2px; }
.area { height: auto; padding: 10px 12px; line-height: 1.5; font: inherit; resize: vertical; width: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.crit-row { display: grid; grid-template-columns: minmax(0, 1fr) 84px 36px; gap: 8px; margin-bottom: 10px; }
.crit-row .area { grid-column: 1 / -1; margin-top: -4px; }
.crit-max { text-align: center; }
.empty-inline { color: var(--text-2); }
.empty-inline code { background: var(--surface-2); border-radius: 6px; padding: 2px 6px; }
details.fb { margin-top: 4px; }
details.fb summary { cursor: pointer; color: var(--primary); font-size: 12px; }
details.fb p { margin: 6px 0 0; color: var(--text-2); font-size: 13px; max-width: 520px; white-space: pre-wrap; }

/* ── Профиль и команда ── */
button.user-chip { border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; width: 100%; border-radius: 10px; }
button.user-chip:hover, button.user-chip[aria-current="page"] { background: var(--surface-hover); }
.narrow { max-width: 640px; }
.callout { padding: 12px 14px; border-radius: 10px; background: var(--primary-soft); color: var(--text); line-height: 1.5; }
.callout.secret { display: grid; gap: 8px; margin-bottom: 16px; }
.callout.secret > div:first-child { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.callout code { font-size: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; user-select: all; }
.perm-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.perms { gap: 8px; }
.check.off { color: var(--text-3); }
.edit-row > td { background: var(--surface-2); }
.access-box { padding: 8px 4px; max-width: 640px; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; min-width: 160px; }
.drawer-seg { margin-bottom: 14px; }
