:root {
  --ink: #17312b;
  --muted: #687c76;
  --cream: #f5f4ee;
  --paper: #fffefa;
  --green: #17745c;
  --green-dark: #123c36;
  --green-soft: #dff1e9;
  --red: #c3443f;
  --red-soft: #fde8e4;
  --amber: #b77915;
  --amber-soft: #fff1cf;
  --blue: #256f92;
  --blue-soft: #e0f0f7;
  --line: #dfe6e1;
  --shadow: 0 18px 55px rgba(30, 67, 57, .10);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 241, 207, .55), transparent 38%),
    linear-gradient(315deg, rgba(224, 240, 247, .7), transparent 34%),
    var(--cream);
  font-family: "Tahoma", "Arial", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .6; cursor: wait; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 56px; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 24px 0 18px; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 20px; }
.compact-brand { margin-bottom: 42px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: white; background: var(--green); box-shadow: 0 8px 18px rgba(23,116,92,.25); }
.nav-actions, .card-actions { display: flex; gap: 8px; align-items: center; }
.nav-link, .icon-button {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--muted);
}
.nav-link:hover, .nav-link.active { background: var(--paper); border-color: var(--line); color: var(--green-dark); }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; padding: 0; border-color: var(--line); background: rgba(255,255,255,.65); }

.hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: end; margin: 26px 0; }
.eyebrow { color: var(--green); font-size: 13px; font-weight: 800; margin: 0 0 8px; }
h1 { font-size: clamp(30px, 5vw, 52px); line-height: 1.15; margin: 0; letter-spacing: 0; }
h2 { margin: 0; font-size: 22px; }
.subtitle { color: var(--muted); font-size: 16px; margin: 12px 0 0; line-height: 1.7; }

.panel { background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: 0 10px 35px rgba(30,67,57,.06); margin-bottom: 16px; }
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 16px; }
.toolbar.second { margin-top: 28px; }
.toolbar p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.filters { display: flex; gap: 10px; align-items: end; }
.filters.wide { flex-wrap: wrap; justify-content: flex-end; }
.filters input, .filters select { min-width: 190px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 13px;
  outline: none;
  transition: .2s;
}
textarea { resize: vertical; line-height: 1.7; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,116,92,.1); }
.field-label { display: block; color: var(--muted); font-size: 12px; font-weight: 700; margin: 0 0 7px; }

.primary, .secondary, .danger, .text-button, .tab {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary { background: var(--green); color: white; box-shadow: 0 8px 18px rgba(23,116,92,.18); }
.primary:hover { background: var(--green-dark); }
.secondary { background: var(--blue-soft); color: var(--blue); }
.danger { background: var(--red-soft); color: var(--red); }
.text-button { background: transparent; color: var(--muted); }
.small { padding: 8px 11px; font-size: 12px; }
.mode-tabs { display: flex; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.mode-tabs.wrap { flex-wrap: wrap; border-top: 0; padding-top: 0; }
.tab { background: #eef2ee; color: var(--muted); }
.tab.active { background: var(--green); color: white; }

.attendance-panel { margin-top: 16px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.attendance-list { display: grid; gap: 10px; }
.attendance-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 100px 100px minmax(220px, .9fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  padding: 12px;
}
.student-main { display: flex; gap: 12px; min-width: 0; align-items: flex-start; }
.student-main strong, .student-main span, .student-main small { display: block; }
.student-main span, .student-main small, .student-meta { color: var(--muted); font-size: 12px; margin-top: 5px; }
.avatar { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; background: var(--green-soft); color: var(--green-dark); }
.check-line { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 13px; }
.check-line input { width: 18px; height: 18px; }
.single-form { display: grid; grid-template-columns: 1.3fr auto auto; gap: 14px; align-items: end; }
.single-form .full { grid-column: 1 / -1; }
.student-hints { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 13px; }
.student-hints span { background: #f1f4f2; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 24px 0; }
.stats.compact { margin: 0 0 16px; }
.stat { border-radius: 8px; padding: 20px; border: 1px solid var(--line); background: rgba(255,255,255,.80); }
.stat strong { display: block; font-size: 32px; line-height: 1; margin-bottom: 7px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.expected { color: var(--blue); }
.stat.collected { color: var(--green); }
.stat.remaining { color: var(--red); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 14px 16px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f0f4ef; color: var(--muted); font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
.empty-cell { text-align: center; color: var(--muted); padding: 44px 18px; }

.manage-list { display: grid; gap: 12px; }
.manage-card { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 16px; }
.manage-top { display: flex; align-items: center; gap: 13px; }
.student-info { min-width: 0; flex: 1; }
.student-name { font-weight: 800; margin: 0 0 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.chip { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: #f5f8f5; color: var(--green-dark); padding: 5px 8px; font-size: 12px; }
.muted-text { color: var(--muted); font-size: 12px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager-actions { display: flex; align-items: center; gap: 8px; }
.empty { text-align: center; border: 1px dashed #c6d3cd; border-radius: 8px; padding: 42px 18px; color: var(--muted); background: rgba(255,255,255,.42); }
.empty.compact { padding: 24px 12px; }

dialog { width: min(620px, calc(100% - 28px)); border: 0; padding: 0; border-radius: 12px; color: var(--ink); box-shadow: 0 28px 90px rgba(16,40,34,.28); }
dialog::backdrop { background: rgba(13,38,31,.48); backdrop-filter: blur(3px); }
.dialog-content { padding: 24px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.dialog-close { border: 0; background: #f0f2ef; border-radius: 8px; width: 36px; height: 36px; color: var(--muted); font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #f8faf8; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast { position: fixed; z-index: 99; left: 24px; bottom: 24px; background: var(--ink); color: white; padding: 13px 18px; border-radius: 8px; opacity: 0; transform: translateY(18px); pointer-events: none; transition: .25s; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red); }
.login-error { color: var(--red); font-size: 13px; min-height: 20px; margin: 8px 0; }

.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.login-art { padding: 64px; background: var(--green-dark); color: white; position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; }
.login-art::before { content: ""; position: absolute; inset: 24px; border: 1px solid rgba(255,255,255,.12); border-radius: 16px; pointer-events: none; }
.login-art .brand, .login-quote { position: relative; z-index: 1; }
.login-quote { max-width: 570px; }
.login-quote h1 { font-size: clamp(38px, 6vw, 70px); }
.login-quote p { color: #cde1d9; line-height: 1.9; font-size: 17px; }
.login-form-wrap { display: grid; place-items: center; padding: 32px; }
.login-box { width: min(420px, 100%); }
.login-box h2 { margin: 0 0 8px; font-size: 32px; }
.login-box > p { margin: 0 0 28px; color: var(--muted); }
.login-box .field { margin-bottom: 15px; display: block; }
.login-box .primary { width: 100%; margin-top: 8px; padding: 13px; }
.setup-note { background: #fff4d9; border: 1px solid #ead49c; color: #76591c; border-radius: 8px; padding: 14px; line-height: 1.7; font-size: 13px; margin-bottom: 18px; }

@media (max-width: 980px) {
  .attendance-row { grid-template-columns: 1fr 92px 92px; }
  .achievement-input { grid-column: 1 / -1; }
  .single-form { grid-template-columns: 1fr 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-art { min-height: 280px; padding: 32px; }
  .login-art .brand { margin-bottom: 70px; }
}

@media (max-width: 650px) {
  .shell { width: min(100% - 20px, 1180px); }
  .topbar, .toolbar, .section-head, .manage-top { align-items: stretch; flex-direction: column; }
  .nav-actions, .filters, .filters.wide { width: 100%; flex-wrap: wrap; }
  .nav-link { flex: 1; text-align: center; justify-content: center; }
  .hero, .stats, .stats.compact { grid-template-columns: 1fr; }
  .filters input, .filters select { min-width: 0; }
  .attendance-row { grid-template-columns: 1fr; }
  .pager { align-items: stretch; flex-direction: column; }
  .pager-actions { justify-content: space-between; }
  .single-form, .form-grid, .check-group { grid-template-columns: 1fr; }
  .single-form .full, .form-grid .full { grid-column: auto; }
  .login-art { display: none; }
  .login-form-wrap { min-height: 100vh; }
}

@media print {
  body { background: white; }
  .topbar, .hero, .mode-tabs, .toolbar .filters button, #studentsTab, #coursesTab, #teachersTab, #enrollmentsTab, .toast { display: none !important; }
  .shell { width: 100%; padding: 0; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  .table-wrap { overflow: visible; border: 0; }
  table { min-width: 0; }
}
