/* TopTeach Admin — Telegram Mini App.
   Цвета берутся из темы Telegram (--tg-theme-*), вне Telegram — из запасных значений ниже. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #7d8590);
  --accent: var(--tg-theme-button-color, #3478f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f6fde);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --border: color-mix(in srgb, var(--text) 9%, transparent);
  --soft: color-mix(in srgb, var(--text) 5%, transparent);
  --ok: #2e9e5b;
  --warn: #d98a00;
  --radius: 14px;
  --gap: 12px;
  --nav-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #0f1115; --surface: #191c22; --text: #eceef2; --hint: #8b93a1;
    --accent: #4c8dff; --link: #6ea2ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; display: flex; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; padding: 14px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.page { max-width: 1080px; margin: 0 auto; display: grid; gap: var(--gap); }
.page-head { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.page-head h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -0.01em; }
.back { border: 0; background: var(--soft); width: 34px; height: 34px; border-radius: 10px; cursor: pointer; font-size: 18px; }

.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav-item {
  border: 0; background: none; cursor: pointer; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; position: relative;
}

.nav-item.active { color: var(--accent); font-weight: 600; }
.nav-item .dot {
  position: absolute; top: 7px; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700;
  display: grid; place-items: center;
}

@media (min-width: 860px) {
  .bottom-nav { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 2px; width: 232px; flex-shrink: 0;
    position: sticky; top: 0; height: 100vh; padding: 18px 12px; background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .brand { font-weight: 700; font-size: 17px; padding: 4px 10px 16px; }
  .brand small { display: block; color: var(--hint); font-weight: 400; font-size: 12px; }
  .side-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
    border: 0; background: none; cursor: pointer; text-align: left; color: var(--text);
  }
  .side-item:hover { background: var(--soft); }
  .side-item.active { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); font-weight: 600; }
  .side-item .count { margin-left: auto; font-size: 12px; background: var(--danger); color: #fff; border-radius: 9px; padding: 0 7px; }
  .main { padding: 24px 28px 40px; }
}

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border); }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .muted { font-weight: 400; }
.grid { display: grid; gap: var(--gap); }
.stats { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 860px) { .two { grid-template-columns: 1fr 1fr; } }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--hint); font-size: 12.5px; }
.stat .value { font-size: clamp(17px, 4.6vw, 22px); font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; white-space: nowrap; }
.stat .sub { color: var(--hint); font-size: 12px; }

.muted { color: var(--hint); }
.small { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.notice {
  border-radius: 12px; padding: 10px 12px; font-size: 13.5px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
}
.notice.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); }

/* ---------- Lists ---------- */
.list { display: grid; }
.item {
  display: flex; gap: 12px; align-items: center; padding: 11px 2px; border: 0; background: none; width: 100%;
  text-align: left; border-bottom: 1px solid var(--border); cursor: pointer; color: inherit;
}
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { color: var(--hint); font-size: 12.5px; }
.chev { color: var(--hint); font-size: 18px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: var(--soft); display: grid; place-items: center; font-weight: 700; color: var(--hint);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Badges, buttons, inputs ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; border-radius: 999px;
  padding: 2px 9px; background: var(--soft); color: var(--hint); white-space: nowrap;
}
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.info { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.btn {
  border: 0; border-radius: 11px; padding: 10px 14px; font-weight: 600; cursor: pointer;
  background: var(--soft); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 140px; }

.input, .textarea, .select {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 11px; padding: 10px 12px; outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { min-height: 120px; resize: vertical; }

.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; border-radius: 999px; padding: 7px 13px; background: var(--surface); cursor: pointer;
  white-space: nowrap; font-weight: 500; border: 1px solid var(--border);
}
.tab.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.tab .n { opacity: .75; margin-left: 4px; }

/* ---------- Media ---------- */
.media { border-radius: 12px; overflow: hidden; background: var(--soft); }
.media img { width: 100%; max-height: 420px; object-fit: contain; }
.media video { width: 100%; max-height: 420px; display: block; background: #000; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.thumb { aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--soft); display: grid; place-items: center; font-size: 12px; color: var(--hint); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Chart ---------- */
.bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: end; gap: 4px; height: 120px; }
.bar { background: color-mix(in srgb, var(--accent) 75%, transparent); border-radius: 4px 4px 2px 2px; min-height: 2px; position: relative; }
.bar:hover::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface); font-size: 11px; padding: 2px 6px; border-radius: 6px; white-space: nowrap;
}
.bars-axis { display: flex; justify-content: space-between; color: var(--hint); font-size: 11px; margin-top: 6px; }

.funnel { display: grid; gap: 8px; }
.funnel .step { display: grid; gap: 4px; }
.funnel .track { height: 10px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.funnel .fill { height: 100%; background: var(--accent); border-radius: 6px; }

/* ---------- Feedback ---------- */
.empty { text-align: center; color: var(--hint); padding: 28px 10px; }
.empty .big { font-size: 30px; margin-bottom: 6px; }
.loader { display: grid; place-items: center; padding: 40px; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--soft), color-mix(in srgb, var(--text) 9%, transparent), var(--soft)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.18); animation: pop .18s ease-out;
}
.toast.bad { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (min-width: 860px) { .toast { bottom: 24px; } }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--surface); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; animation: up .2s ease-out;
}
.sheet h3 { margin: 0; font-size: 17px; }
@media (min-width: 640px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }

.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; text-align: center; }
.gate .box { max-width: 360px; display: grid; gap: 10px; }
.gate .logo { font-size: 44px; }

.q { padding: 10px 0; border-bottom: 1px solid var(--border); }
.q:last-child { border-bottom: 0; }
.q ol { margin: 6px 0 0; padding-left: 20px; }
.q li.right { color: var(--ok); font-weight: 600; }

/* В Telegram есть своя кнопка «Назад» */
.tg .back { display: none; }

/* ---------- Иконки (Lucide) ---------- */
.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }
.btn .icon { margin-right: -1px; }
.with-icon { display: inline-flex; align-items: center; gap: 7px; }
.with-icon .icon { color: var(--hint); }
.chev { color: var(--hint); }
.tile-icon {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
}
.empty .big { display: flex; justify-content: center; color: var(--hint); opacity: .8; }
.gate .logo { display: flex; justify-content: center; color: var(--accent); }
.side-item .icon { color: var(--hint); }
.side-item.active .icon { color: var(--accent); }
.nav-item .ico { display: grid; place-items: center; height: 24px; }
.q li .icon { color: var(--ok); vertical-align: -2px; }
