/* ===========================================================================
   Bilim Platform — дизайн-система (Apple HIG, светлая, mobile-first)
   Приоритет №1: мобильный экран 390px. Тач-таргеты ≥44px. safe-area-inset.
   =========================================================================== */

/* ---------- 1. Переменные ---------- */
:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --surface-3: #e9e9ee;
  --ink: #1c1c1e;
  --ink-2: #3a3a3c;
  --muted: #8e8e93;
  --line: #e5e5ea;
  --line-strong: #d1d1d6;

  --accent: #5856d6;         /* indigo */
  --accent-ink: #ffffff;
  --accent-soft: #ecebff;
  --accent-press: #4644b8;

  --danger: #ff3b30;
  --warn: #ffcc00;
  --ok: #34c759;
  --ok-strong: #248a3d;

  /* оценки за прогресс */
  --g2: #ff3b30;             /* регресс */
  --g2-ink: #ffffff;
  --g3: #ffcc00;             /* на уровне */
  --g3-ink: #4d3b00;
  --g4: #34c759;             /* рост (салатовый) */
  --g4-ink: #0b3d17;
  --g5: #248a3d;             /* сильный прогресс */
  --g5-ink: #ffffff;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-1: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --shadow-2: 0 8px 30px rgba(0,0,0,.12);
  --shadow-press: 0 1px 4px rgba(0,0,0,.10);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --tap: 44px;
  --ease: 0.2s ease;

  --sidebar-w: 248px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}
h1,h2,h3,h4,p,figure,ul,ol { margin: 0; }
ul,ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
img,svg { max-width: 100%; display: block; }
button { font-family: inherit; }
input,select,textarea { font-family: inherit; font-size: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 3. Типографика ---------- */
h1 { font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 18px; line-height: 1.25; font-weight: 650; }
h4 { font-size: 15px; font-weight: 650; }
small { font-size: 13px; }
.title-lg { font-size: 34px; font-weight: 800; letter-spacing: -.03em; }
.muted { color: var(--muted); }
.subtle { color: var(--ink-2); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- 4. Каркас приложения ---------- */
.app-main {
  padding: calc(var(--space-4) + var(--safe-top)) var(--space-4)
           calc(var(--tabbar-h) + var(--safe-bottom) + var(--space-4));
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
body.no-nav .app-main { padding-bottom: calc(var(--space-6) + var(--safe-bottom)); }

/* ---------- 5. Карточки ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.card.pad-lg { padding: var(--space-5); }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card-title { font-size: 13px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--space-2); }

/* ---------- 6. Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-4);
  border: none; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink);
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: transform var(--ease), background var(--ease), box-shadow var(--ease), opacity var(--ease);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: scale(.97); box-shadow: var(--shadow-press); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { background: var(--accent-press); }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--line-strong); }
.btn-ghost:active { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: 14px; }
.btn-lg { min-height: 52px; font-size: 17px; padding: 0 var(--space-5); }

/* ---------- 7. Чипы / бейджи ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--ink-2);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: #e4f7ea; color: var(--ok-strong); }
.chip.warn { background: #fff6d6; color: #7a5c00; }
.chip.danger { background: #ffe5e3; color: var(--danger); }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
}
.badge.neutral { background: var(--surface-3); color: var(--ink-2); }

/* ---------- 8. Оценки за прогресс ---------- */
.grade {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px; padding: 0 8px;
  border-radius: 10px; font-weight: 800; font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.grade-2 { background: var(--g2); color: var(--g2-ink); }
.grade-3 { background: var(--g3); color: var(--g3-ink); }
.grade-4 { background: var(--g4); color: var(--g4-ink); }
.grade-5 { background: var(--g5); color: var(--g5-ink); }
.grade-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.grade-cell { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }

/* ---------- 9. Списки ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-1); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  transition: background var(--ease);
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--surface-2); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { font-size: 13px; color: var(--muted); }
.list-item .li-trail { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.list-item.link::after { content: "›"; color: var(--line-strong); font-size: 22px; margin-left: 4px; }

/* ---------- 10. Bottom-sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  opacity: 0; pointer-events: none; transition: opacity var(--ease); z-index: 60;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-2);
  padding: var(--space-4) var(--space-4) calc(var(--space-5) + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  max-height: 88vh; overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong);
  margin: 0 auto var(--space-3); }
@media (min-width: 640px) {
  .sheet { left: 50%; right: auto; bottom: 50%; transform: translate(-50%, 60%) scale(.98);
    width: 460px; max-width: calc(100vw - 32px); border-radius: var(--radius-lg); opacity: 0; }
  .sheet.open { transform: translate(-50%, 50%) scale(1); opacity: 1; }
}

/* ---------- 11. Таблица со скроллом и липкой первой колонкой ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch;
  border-radius: var(--radius); box-shadow: var(--shadow-1); background: var(--surface); }
.table-scroll table { border-collapse: collapse; width: 100%; min-width: max-content; }
.table-scroll th, .table-scroll td {
  padding: var(--space-3); text-align: center; font-size: 14px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table-scroll thead th { position: sticky; top: 0; background: var(--surface-2);
  font-weight: 650; color: var(--ink-2); z-index: 2; }
.table-scroll th.sticky-col, .table-scroll td.sticky-col {
  position: sticky; left: 0; background: var(--surface); text-align: left;
  z-index: 3; box-shadow: 1px 0 0 var(--line);
}
.table-scroll thead th.sticky-col { z-index: 4; background: var(--surface-2); }

/* ---------- 12. Progress-ring ---------- */
.progress-ring { --p: 0; --size: 64px; --tw: 7px;
  width: var(--size); height: var(--size); border-radius: 50%;
  display: grid; place-items: center; position: relative;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-3) 0);
}
.progress-ring::before { content: ""; position: absolute; inset: var(--tw);
  border-radius: 50%; background: var(--surface); }
.progress-ring .pr-val { position: relative; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- 13. Скелетоны ---------- */
.skeleton { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 200% 100%; animation: sk 1.2s infinite linear; border-radius: var(--radius-sm); }
.skeleton.line { height: 14px; margin-bottom: 8px; }
.skeleton.line.short { width: 55%; }
.skeleton.block { height: 96px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- 14. Формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 10px var(--space-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.textarea { min-height: 96px; padding: var(--space-3); resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; margin-bottom: var(--space-3); }
.alert-danger { background: #ffe5e3; color: var(--danger); }
.alert-ok { background: #e4f7ea; color: var(--ok-strong); }

/* ---------- 15. Утилиты ---------- */
.row { display: flex; align-items: center; gap: var(--space-3); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.stack.tight { gap: var(--space-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); }
.spacer { flex: 1; }
.hide { display: none !important; }
.mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); } .mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); }
.pad-0 { padding: 0; }
.stat { font-size: 30px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--line); margin: var(--space-3) 0; border: 0; }

/* ---------- 16. Навигация: нижний tab-bar (мобайл) ---------- */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab-bar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tabbar-h); padding: 6px 2px;
  color: var(--muted); font-size: 11px; font-weight: 600;
  transition: color var(--ease), transform var(--ease);
}
.tab-bar .tab .ic { font-size: 22px; line-height: 1; filter: grayscale(.35); transition: filter var(--ease), transform var(--ease); }
.tab-bar .tab .lb { letter-spacing: -.01em; }
.tab-bar .tab.active { color: var(--accent); }
.tab-bar .tab.active .ic { filter: none; transform: translateY(-1px) scale(1.06); }
.tab-bar .tab:active { transform: scale(.94); }

/* ---------- 17. Навигация: сайдбар (десктоп) ---------- */
.sidebar { display: none; }
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-4) var(--space-5); }
.brand-mark { font-size: 26px; }
.brand-text { display: flex; flex-direction: column; font-weight: 800; font-size: 18px; line-height: 1.05; }
.brand-text small { font-weight: 600; font-size: 11px; color: var(--muted); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 var(--space-2); flex: 1; }
.side-link {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap); padding: 10px var(--space-3);
  border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 600;
  transition: background var(--ease), color var(--ease);
}
.side-link .ic { font-size: 20px; width: 24px; text-align: center; }
.side-link:hover { background: var(--surface-2); }
.side-link.active { background: var(--accent-soft); color: var(--accent); }
.side-link.logout { color: var(--danger); }
.sidebar-foot { padding: var(--space-3) var(--space-2) var(--space-4); border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); margin-bottom: var(--space-2); }
.user-chip .ava { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }
.user-chip .u-meta { display: flex; flex-direction: column; min-width: 0; }
.user-chip .u-meta b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 18. Экран логина ---------- */
.login-wrap { max-width: 420px; margin: 0 auto; padding-top: var(--space-5); }
.login-hero { text-align: center; margin-bottom: var(--space-5); }
.login-logo { font-size: 56px; line-height: 1; margin-bottom: var(--space-2);
  filter: drop-shadow(0 6px 14px rgba(88,86,214,.25)); }
.login-brand { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.login-brand span { display: block; font-size: 14px; font-weight: 600; color: var(--accent); margin-top: 2px; }
.login-sub { margin-top: var(--space-2); }
.login-card { padding: var(--space-5); }
.demo-card { padding: var(--space-4); }
.demo-title { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  font-weight: 700; font-size: 14px; margin-bottom: var(--space-3); }
.demo-grid { display: flex; flex-direction: column; gap: var(--space-2); }
.demo-btn { justify-content: flex-start; gap: var(--space-3); text-align: left; height: auto; padding: 10px var(--space-3); }
.demo-ic { font-size: 22px; }
.demo-lb { display: flex; flex-direction: column; line-height: 1.2; }
.demo-lb small { font-weight: 500; }
.demo-hint { font-size: 12px; margin-top: var(--space-3); }
.login-foot { text-align: center; margin-top: var(--space-5); font-size: 12px; }

/* ---------- 19. Десктоп ≥900px: сайдбар вместо tab-bar ---------- */
@media (min-width: 900px) {
  .tab-bar { display: none; }
  body.has-nav .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar-w);
    background: var(--surface); border-right: 1px solid var(--line);
    padding-top: var(--safe-top); z-index: 30;
  }
  body.has-nav .app-main {
    margin-left: var(--sidebar-w);
    max-width: 860px;
    padding: var(--space-6) var(--space-6) var(--space-6);
    margin-right: auto;
  }
}

/* ---------- 20. Прочее ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
