:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef0fd;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1e2130;
  --muted: #7c8093;
  --border: #e8e9f0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(30, 33, 48, .06), 0 6px 16px rgba(30, 33, 48, .05);

  --g2-bg: #fde3e3; --g2-fg: #b42318;
  --g3-bg: #fef0c7; --g3-fg: #93500a;
  --g4-bg: #e3f6d5; --g4-fg: #3f7016;
  --g5-bg: #d4f3e2; --g5-fg: #14804a;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: inherit; }
button, input, select, textarea { font-family: inherit; font-size: 15px; }

.container { max-width: 1000px; margin: 0 auto; padding: 0 16px; }

/* ─── Шапка ─── */
header.app-header {
  background: linear-gradient(135deg, var(--primary), #6d28d9);
  color: #fff;
  padding: 16px 0;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 12px rgba(79, 70, 229, .25);
}
.app-header .row { display: flex; align-items: center; justify-content: space-between; }
.app-header .brand { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.app-header .brand .sub { display: block; font-size: 12px; font-weight: 400; opacity: .85; }
.app-header .user-box { display: flex; align-items: center; gap: 10px; }
.app-header .user-name { font-size: 13px; opacity: .92; display: none; }
@media (min-width: 560px) { .app-header .user-name { display: inline; } }
.icon-btn {
  background: rgba(255,255,255,.16); border: none; color: #fff;
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: rgba(255,255,255,.28); }

main.app-main { padding: 18px 0 90px; }

/* ─── Табы (для админки) ─── */
.tabbar {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 14px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  flex-shrink: 0; border: none; background: var(--surface); color: var(--muted);
  padding: 9px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow);
}
.tabbar button.active { background: var(--primary); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Карточки ─── */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 18px 20px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2, .card h3 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.card .hint { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 0 10px; }

/* ─── Сетка карточек-плиток (список назначений/предметов) ─── */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface); border-radius: var(--radius-sm); padding: 16px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, box-shadow .12s;
  display: flex; flex-direction: column; gap: 4px;
}
.tile:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(30,33,48,.1); }
.tile .tile-title { font-weight: 700; font-size: 15px; }
.tile .tile-sub { font-size: 13px; color: var(--muted); }

/* ─── Переключатель ребёнка (пилюли) ─── */
.child-switch { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; }
.child-switch button {
  flex-shrink: 0; border: 2px solid var(--border); background: var(--surface);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--text);
}
.child-switch button.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); }

/* ─── Стат-карточки (средний балл / итоговые) ─── */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius-sm); padding: 14px 10px;
  text-align: center; box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-size: 26px; font-weight: 800; color: var(--primary-dark); margin-top: 4px; line-height: 1; }
.stat-card .stat-caption { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.stat-card .stat-final-line { font-size: 12px; color: var(--text); margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); display: flex; align-items: center; justify-content: center; gap: 5px; }
.stat-card .stat-final-line.empty { color: var(--muted); }

/* ─── Бейджи оценок ─── */
.grade-chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 8px; border-radius: 9px;
  font-weight: 800; font-size: 15px;
}
.grade-chip.g2 { background: var(--g2-bg); color: var(--g2-fg); }
.grade-chip.g3 { background: var(--g3-bg); color: var(--g3-fg); }
.grade-chip.g4 { background: var(--g4-bg); color: var(--g4-fg); }
.grade-chip.g5 { background: var(--g5-bg); color: var(--g5-fg); }
.grade-chip.sm { min-width: 24px; height: 24px; font-size: 13px; border-radius: 7px; }
.grade-chip-wrap { position: relative; display: inline-flex; }
.weight-badge {
  position: absolute; top: -6px; right: -6px; background: var(--primary); color: #fff;
  font-size: 9px; font-weight: 800; border-radius: 999px; padding: 1px 4px; line-height: 1.3;
  box-shadow: 0 0 0 2px var(--surface);
}

/* ─── Журнал-таблица (учитель/админ) ─── */
.journal-table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table.journal-grid { border-collapse: separate; border-spacing: 0; width: auto; min-width: 100%; }
table.journal-grid th, table.journal-grid td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); text-align: center; padding: 6px 4px; white-space: nowrap; }
table.journal-grid thead th { background: #fafafe; color: var(--muted); font-weight: 700; font-size: 11px; }
table.journal-grid th.month-header { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--primary-dark); background: var(--primary-light); }
table.journal-grid th.student-col, table.journal-grid td.student-col {
  position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left;
  padding: 8px 12px; min-width: 160px; font-weight: 600; font-size: 13.5px; cursor: pointer;
  border-right: 2px solid var(--border);
}
table.journal-grid thead th.student-col { z-index: 3; background: #fafafe; }
table.journal-grid td.student-col:hover { color: var(--primary); }
table.journal-grid td.grade-cell { cursor: pointer; min-width: 40px; }
table.journal-grid td.grade-cell:hover { background: var(--primary-light); }
table.journal-grid td.avg-col, table.journal-grid th.avg-col { font-weight: 800; color: var(--primary-dark); background: #fafbff; min-width: 54px; }
table.journal-grid th.add-col { min-width: 46px; }
.add-date-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--primary);
  color: #fff; font-size: 18px; font-weight: 700; cursor: pointer; line-height: 1;
}

/* ─── Редактор ячейки (список оценок за день + добавление) ─── */
.cell-grade-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bg); margin-bottom: 8px; }
.cell-grade-item .cgi-meta { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted); }
.cell-grade-item .cgi-actions { display: flex; gap: 6px; }
.weight-toggle { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin: 10px 0; }
.weight-toggle input { width: auto; }
.value-picker { display: flex; gap: 8px; margin-bottom: 10px; }
.value-picker button {
  flex: 1; padding: 10px 0; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-weight: 800; font-size: 16px; cursor: pointer; color: var(--text);
}
.value-picker button.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); }

/* ─── Лента оценок ─── */
.grade-feed { display: flex; flex-direction: column; gap: 8px; }
.grade-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: var(--radius-sm); background: var(--bg);
}
.grade-row .grade-meta { flex: 1; min-width: 0; }
.grade-row .grade-date { font-weight: 600; font-size: 13.5px; }
.grade-row .grade-comment { font-size: 12.5px; color: var(--muted); margin-top: 1px; overflow-wrap: break-word; }
.grade-row .grade-teacher { font-size: 11.5px; color: var(--muted); }
.grade-row .grade-actions { display: flex; gap: 6px; flex-shrink: 0; }
.grade-row.foreign { opacity: .85; }

/* ─── Формы ─── */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }
.checkbox-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; color: var(--text); }
.checkbox-list input[type=checkbox] { width: auto; }

/* ─── Кнопки ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius-sm); padding: 11px 18px;
  font-weight: 700; font-size: 14px; cursor: pointer; background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn.secondary:hover { background: #e2e5fb; }
.btn.danger { background: #fde3e3; color: #b42318; }
.btn.danger:hover { background: #fbd2d2; }
.btn.ghost { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn.ghost:hover { color: var(--text); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Таблицы (для плотных админ-списков) ─── */
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 10px 8px; text-align: left; font-size: 13.5px; border-bottom: 1px solid var(--border); }
table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
.table-wrap { overflow-x: auto; }

.filters-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters-row input, .filters-row select { padding: 9px 11px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); }
.filters-row .spacer { flex: 1; }

.muted { color: var(--muted); font-size: 13px; }
.badge-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--primary-light); color: var(--primary-dark); }
.badge-pill.gray { background: var(--bg); color: var(--muted); }
.badge-pill.red { background: var(--g2-bg); color: var(--g2-fg); }

/* ─── Модалки ─── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(20, 20, 35, .45);
  align-items: flex-end; justify-content: center; z-index: 200; backdrop-filter: blur(1px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 20px 20px 0 0; width: 100%; max-width: 480px;
  max-height: 92vh; overflow-y: auto; padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); max-height: 88vh; }
  .modal.wide { max-width: 960px; }
}
.modal-handle { width: 40px; height: 4px; background: var(--border); border-radius: 4px; margin: 0 auto 14px; }
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ─── Логин ─── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border-radius: 22px; padding: 34px 28px; width: 100%; max-width: 380px; box-shadow: var(--shadow); text-align: center; }
.login-card .logo-dot { width: 56px; height: 56px; border-radius: 18px; background: linear-gradient(135deg, var(--primary), #6d28d9); margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.login-card h1 { font-size: 19px; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); font-size: 13.5px; margin-bottom: 24px; }
.login-error { background: var(--g2-bg); color: var(--g2-fg); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin-bottom: 14px; display: none; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .emoji { font-size: 36px; margin-bottom: 10px; }

.loading-dots { text-align: center; padding: 30px; color: var(--muted); }
