:root {
  --bg: #081411;
  --bg-elev: #0f221e;
  --bg-soft: #16312b;
  --ink: #eef5f1;
  --muted: #8aa399;
  --line: rgba(238, 245, 241, 0.1);
  --gold: #d4a94a;
  --gold-soft: rgba(212, 169, 74, 0.16);
  --ok: #2f9e6e;
  --ok-soft: rgba(47, 158, 110, 0.16);
  --warn: #c9853a;
  --warn-soft: rgba(201, 133, 58, 0.16);
  --danger: #d66b5c;
  --danger-soft: rgba(214, 107, 92, 0.14);
  --blue: #4d8fd6;
  --blue-soft: rgba(77, 143, 214, 0.16);
  --radius: 16px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --sidebar: 260px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(212, 169, 74, 0.12), transparent 55%),
    radial-gradient(700px 360px at 100% 0%, rgba(47, 158, 110, 0.1), transparent 50%),
    linear-gradient(165deg, #071210, #0c1c18 45%, #102822);
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: rgba(8, 20, 17, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 18px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--gold), #a87920);
  color: #13110b;
  font-weight: 800;
  font-size: 1.1rem;
}
.brand-text strong {
  display: block;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.brand-text span {
  color: var(--muted);
  font-size: 0.82rem;
}

.nav-links { display: grid; gap: 6px; }
.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid transparent;
  transition: 0.15s ease;
}
.nav-links a:hover {
  background: rgba(255, 255, 255, 0.04);
  text-decoration: none;
}
.nav-links a.active {
  background: var(--gold-soft);
  border-color: rgba(212, 169, 74, 0.28);
  color: var(--gold);
  font-weight: 650;
}
.nav-ico {
  width: 22px;
  text-align: center;
  opacity: 0.9;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}
.sidebar-foot .who {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 2px;
  word-break: break-all;
}
.sidebar-foot .role {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 12px;
}
.btn-logout {
  display: inline-flex;
  width: 100%;
  justify-content: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
}
.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
  text-decoration: none;
}

.main {
  padding: 28px 32px 40px;
  min-width: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0 0 6px;
  font-size: 1.7rem;
  letter-spacing: -0.02em;
}
.page-head p {
  margin: 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stat {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat .label {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 8px;
}
.stat .value {
  font-size: 1.45rem;
  font-weight: 750;
  color: var(--gold);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.panel {
  background: rgba(15, 34, 30, 0.72);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.panel-body { padding: 0; }
.panel-body.pad { padding: 18px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .grow { flex: 1; min-width: 220px; }

input, select, button, .btn {
  font: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  color: var(--ink);
  padding: 11px 14px;
}
input:focus, select:focus {
  outline: none;
  border-color: rgba(212, 169, 74, 0.55);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
button, .btn {
  background: linear-gradient(145deg, #dfb457, #b8892a);
  color: #17140c;
  border: none;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
}
.btn-sm { padding: 8px 12px; font-size: 0.86rem; border-radius: 10px; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
th, td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  background: rgba(0,0,0,0.18);
}
tr:hover td { background: rgba(255,255,255,0.02); }
.cell-title { font-weight: 650; }
.cell-sub { color: var(--muted); font-size: 0.85rem; margin-top: 3px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(255,255,255,0.08);
  color: var(--ink);
}
.badge.ok { background: var(--ok-soft); color: #7ddec0; }
.badge.warn { background: var(--warn-soft); color: #f0c08a; }
.badge.admin { background: var(--gold-soft); color: var(--gold); }
.badge.teacher { background: var(--blue-soft); color: #9ec4f0; }
.badge.student { background: rgba(255,255,255,0.08); color: #c7d5ce; }

.role-form {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}
.role-form select { padding: 7px 10px; font-size: 0.82rem; }
.role-form button { padding: 7px 10px; font-size: 0.82rem; }

.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
}

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert.error {
  background: var(--danger-soft);
  border-color: rgba(214, 107, 92, 0.35);
  color: #f0b2a8;
}
.alert.ok {
  background: var(--ok-soft);
  border-color: rgba(47, 158, 110, 0.35);
  color: #9fe0c4;
}

/* Login */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(15, 34, 30, 0.88);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card .brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}
.login-card .lead {
  color: var(--muted);
  margin: 0 0 22px;
  line-height: 1.5;
}
.form { display: grid; gap: 12px; }
.form label {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}
.form input, .form select { width: 100%; }
.form button { width: 100%; justify-content: center; margin-top: 4px; padding: 13px; }
.form-panel { max-width: 640px; }
.edit-stack {
  display: grid;
  gap: 18px;
  max-width: 640px;
}
.form-grid {
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid label { min-width: 0; }
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}
.form-actions button { width: auto; margin: 0; min-width: 160px; }
.form-panel .hint { margin-top: 16px; }
.page-actions, .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.row-actions { justify-content: flex-end; }
.hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.92rem;
}
.back-link:hover { color: var(--gold); }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar-foot { margin-top: 8px; }
  .main { padding: 18px 16px 28px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .nav-links { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions button { width: 100%; }
}
