/* ============================================================
   Школьная LMS — блочный дизайн
   ============================================================ */

:root {
  --bg:          #f5f7fb;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e6eaf2;
  --border-soft: #eef1f7;

  --text:        #0f172a;
  --text-2:      #475569;
  --muted:       #94a3b8;

  --primary:     #6366f1;
  --primary-600: #4f46e5;
  --primary-700: #4338ca;
  --primary-50:  #eef2ff;

  --success:     #10b981;
  --success-50:  #ecfdf5;
  --warning:     #f59e0b;
  --warning-50:  #fffbeb;
  --danger:      #ef4444;
  --danger-50:   #fef2f2;
  --info:        #3b82f6;
  --info-50:     #eff6ff;

  --g2: #ef4444;
  --g3: #f59e0b;
  --g4: #3b82f6;
  --g5: #10b981;

  --radius:      12px;
  --radius-lg:   16px;
  --radius-sm:   8px;

  --shadow-sm:   0 1px 2px rgba(15,23,42,.04);
  --shadow:      0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md:   0 4px 12px rgba(15,23,42,.06), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg:   0 12px 32px rgba(15,23,42,.10);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
img { max-width: 100%; display: block; }

body {
  font-family: 'Inter', -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary-600); text-decoration: none; transition: color .15s; }
a:hover { color: var(--primary-700); }

h1 { font-size: 26px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 700; margin: 32px 0 14px; letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }

/* ============================================================
   LAYOUT
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 20px;
  color: var(--text);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 10px;
}
.brand:hover { color: var(--text); }
.brand-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  display: grid; place-items: center;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(99,102,241,.25);
  flex-shrink: 0;
}
.brand-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-section {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 14px 10px 6px;
}
.nav-section:first-child { padding-top: 4px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: var(--primary-50);
  color: var(--primary-700);
  font-weight: 600;
}
.nav-icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.user-card {
  margin-top: 16px;
  padding: 10px;
  background: var(--surface-2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.user-info { min-width: 0; flex: 1; }
.user-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: 11px; color: var(--muted); }
.logout-btn {
  color: var(--muted);
  padding: 6px;
  border-radius: 6px;
  display: grid; place-items: center;
  transition: background .15s, color .15s;
}
.logout-btn:hover { background: #fee2e2; color: var(--danger); }

/* ---------- MAIN ---------- */
.main { min-width: 0; }
.content { padding: 28px 32px 60px; max-width: 1400px; }

/* ============================================================
   AUTH (login page)
   ============================================================ */
.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(1000px 500px at 50% 0%, rgba(99,102,241,.10), transparent 60%),
    radial-gradient(800px 400px at 100% 100%, rgba(139,92,246,.10), transparent 60%),
    var(--bg);
}
.auth-layout .flash { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); max-width: 420px; }

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 36px 32px 28px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-card h1 {
  text-align: center;
  margin-bottom: 26px;
  font-size: 22px;
}
.login-card h1::before {
  content: "🎓";
  display: block;
  font-size: 40px;
  margin-bottom: 8px;
}
.login-card label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
.login-card input {
  width: 100%;
  padding: 11px 14px;
  margin-top: 6px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  transition: border .15s, background .15s, box-shadow .15s;
}
.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(99,102,241,.12);
}
.login-card button {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  font-size: 15px;
  font-weight: 600;
}
.login-card .muted { text-align: center; margin-top: 20px; line-height: 1.7; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.stat {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat::after {
  content: "";
  position: absolute;
  inset: auto -30px -30px auto;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(99,102,241,.10), transparent);
  pointer-events: none;
}
.stat span {
  display: block;
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.03em;
  text-transform: none;
  line-height: 1;
}

/* ============================================================
   FORMS / FILTERS
   ============================================================ */
.filter, form.inline, .add-form form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
  align-items: center;
}
.filter input, .filter select,
.add-form input, .add-form select, .add-form textarea,
form.inline input, form.inline select {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border .15s, box-shadow .15s;
}
.filter input:focus, .filter select:focus,
.add-form input:focus, .add-form select:focus, .add-form textarea:focus,
form.inline input:focus, form.inline select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99,102,241,.12);
}
.add-form textarea {
  min-height: 70px;
  width: 100%;
  resize: vertical;
}

details.add-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
details.add-form summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
  list-style: none;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.add-form summary::-webkit-details-marker { display: none; }
details.add-form summary::before {
  content: "＋";
  display: grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--primary-50);
  color: var(--primary-600);
  font-size: 14px;
  font-weight: 700;
  transition: transform .2s;
}
details.add-form[open] summary::before {
  content: "−";
  background: var(--danger-50);
  color: var(--danger);
}
details.add-form[open] { padding-bottom: 20px; }
details.add-form form { margin-top: 14px; }

/* ============================================================
   BUTTONS
   ============================================================ */
button {
  padding: 9px 16px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 1px 2px rgba(99,102,241,.20);
}
button:hover {
  background: var(--primary-600);
  box-shadow: 0 4px 12px rgba(99,102,241,.25);
}
button:active { transform: translateY(1px); }

button.danger {
  background: var(--danger);
  box-shadow: 0 1px 2px rgba(239,68,68,.20);
}
button.danger:hover {
  background: #dc2626;
  box-shadow: 0 4px 12px rgba(239,68,68,.25);
}

/* ============================================================
   TABLES
   ============================================================ */
table {
  width: 100%;
  background: var(--surface);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 11px 16px;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--surface-2); }
td a { font-weight: 500; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 13.5px;
}
.muted { color: var(--text-2); }
.small { font-size: 12px; }

/* ============================================================
   GRADES
   ============================================================ */
.grade {
  font-weight: 700;
  text-align: center;
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 7px;
  font-size: 13px;
}
.g2 { color: var(--g2); background: #fee2e2; }
.g3 { color: var(--g3); background: #fef3c7; }
.g4 { color: var(--g4); background: #dbeafe; }
.g5 { color: var(--g5); background: #d1fae5; }

/* ============================================================
   JOURNAL
   ============================================================ */
table.journal {
  font-size: 13px;
  border-radius: var(--radius);
}
table.journal th, table.journal td {
  padding: 8px 6px;
  text-align: center;
}
table.journal th {
  padding: 12px 6px;
  font-size: 11px;
}
table.journal td.sticky, table.journal th.sticky {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  box-shadow: 3px 0 8px -4px rgba(15,23,42,.12);
  min-width: 180px;
}
table.journal th.sticky { background: var(--surface-2); }
table.journal tbody tr:hover td.sticky { background: var(--surface-2); }

.cell { min-width: 66px; padding: 4px 4px !important; }

/* ---------- AJAX-журнал: чипы оценок ---------- */
.grades-inline {
  display: inline-flex;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.grade-chip {
  border: 1px solid var(--border);
  background: #fff;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.4;
  transition: transform .1s, background .15s, box-shadow .15s;
  font-family: inherit;
}
.grade-chip:hover {
  background: var(--surface-2);
  transform: scale(1.08);
  box-shadow: var(--shadow);
}
.grade-chip:disabled { opacity: .4; cursor: wait; }
.grade-chip.g2 { color: var(--g2); background: #fee2e2; border-color: #fecaca; }
.grade-chip.g3 { color: var(--g3); background: #fef3c7; border-color: #fde68a; }
.grade-chip.g4 { color: var(--g4); background: #dbeafe; border-color: #bfdbfe; }
.grade-chip.g5 { color: var(--g5); background: #d1fae5; border-color: #a7f3d0; }

.add-grade-select {
  border: 1.5px dashed #cbd5e1;
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 12px;
  padding: 2px 4px;
  margin-left: 2px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.add-grade-select:hover { border-color: var(--primary); background: #fff; }
.add-grade-select:disabled { opacity: .4; cursor: wait; }

.avg {
  font-weight: 700;
  color: var(--primary-700);
  background: var(--primary-50) !important;
  border-radius: 8px;
  margin: 4px;
  padding: 6px 8px;
}

/* ============================================================
   ATTENDANCE
   ============================================================ */
.att-cell { white-space: nowrap; padding: 4px 2px !important; }
.att-form { display: inline-block; margin: 0 1px; }
.att-btn {
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
  background: #fff;
  border: 1.5px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.att-btn:hover { transform: scale(1.06); }
.att-btn.active.att-Н {
  background: #fee2e2; border-color: var(--danger); color: var(--danger);
}
.att-btn.active.att-У {
  background: #fef3c7; border-color: var(--warning); color: var(--warning);
}
.att-btn.active.att-Б {
  background: #dbeafe; border-color: var(--info); color: var(--info);
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.6;
}
.badge.ok { background: var(--success-50); color: #047857; }
.badge.warn { background: var(--warning-50); color: #b45309; }
.badge.att-Н { background: #fee2e2; color: #b91c1c; }
.badge.att-У { background: #fef3c7; color: #b45309; }
.badge.att-Б { background: #dbeafe; color: #1d4ed8; }
.legend { margin-bottom: 16px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   FLASH
   ============================================================ */
.flash {
  padding: 12px 18px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 4px solid;
  animation: slideDown .25s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.flash.success { background: var(--success-50); color: #065f46; border-color: var(--success); }
.flash.error   { background: var(--danger-50);  color: #991b1b; border-color: var(--danger); }

/* ============================================================
   TOAST (AJAX)
   ============================================================ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(24px);
  background: #0f172a;
  color: #fff;
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

/* ============================================================
   MISC
   ============================================================ */
.submission {
  max-width: 320px;
  color: var(--text-2);
  font-size: 13px;
}
code {
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--primary-700);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--border);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
  }
  .brand { padding-bottom: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav-section { display: none; }
  .nav-link { padding: 7px 12px; font-size: 13px; }
  .nav-link span:not(.nav-icon) { display: none; }
  .user-card { margin-top: 10px; }
  .content { padding: 20px 16px 40px; }
  h1 { font-size: 22px; }
  .stat span { font-size: 26px; }
}
