:root {
  --blue: #1e3a8a;
  --blue-600: #2563eb;
  --blue-50: #eff6ff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --green: #16a34a;
  --red: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--gray-50); color: var(--gray-800); font-size: 14px;
}
a { color: var(--blue-600); }
button { font-family: inherit; cursor: pointer; }

/* ---------- login ---------- */
#login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.login-card {
  background: #fff; padding: 32px 28px; border-radius: 14px; width: 340px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.login-card h1 { margin: 0 0 4px; color: var(--blue); font-size: 22px; }
.login-card p.sub { margin: 0 0 20px; color: var(--gray-600); font-size: 13px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; margin: 12px 0 4px; color: var(--gray-600); }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 14px;
}
.btn {
  background: var(--blue); color: #fff; border: none; padding: 10px 16px; border-radius: 8px;
  font-size: 14px; font-weight: 600; transition: background .15s;
}
.btn:hover { background: #1d4ed8; }
.btn.block { width: 100%; margin-top: 18px; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.ghost { background: #fff; color: var(--blue); border: 1px solid var(--gray-300); }
.btn.ghost:hover { background: var(--gray-100); }
.msg { margin-top: 12px; font-size: 13px; min-height: 18px; }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }

/* ---------- app shell ---------- */
#app { display: none; }
.topbar {
  background: var(--blue); color: #fff; padding: 0 20px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar .user { font-size: 13px; display: flex; align-items: center; gap: 12px; }
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: 200px; background: #fff; border-right: 1px solid var(--gray-200);
  padding: 14px 10px; flex-shrink: 0;
}
.sidebar button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 10px 12px; border-radius: 8px; font-size: 14px; color: var(--gray-600); margin-bottom: 2px;
}
.sidebar button:hover { background: var(--gray-100); }
.sidebar button.active { background: var(--blue-50); color: var(--blue); font-weight: 600; }
.main { flex: 1; padding: 22px 26px; overflow: auto; }
.page { display: none; }
.page.active { display: block; }
.page h2 { margin: 0 0 4px; font-size: 20px; }
.page .desc { color: var(--gray-600); margin: 0 0 18px; font-size: 13px; }

/* ---------- cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-card .n { font-size: 28px; font-weight: 700; color: var(--blue); }
.stat-card .l { color: var(--gray-600); font-size: 13px; margin-top: 2px; }

/* ---------- table ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 13px;
}
table.data { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--gray-100); font-size: 13px; }
table.data th { background: var(--gray-100); color: var(--gray-600); font-weight: 600; }
table.data tr:hover td { background: var(--gray-50); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; background: var(--blue-50); color: var(--blue); font-size: 12px; }

/* ---------- modal ---------- */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); align-items: center; justify-content: center; z-index: 50; }
.modal-bg.show { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 460px; max-width: 94vw; max-height: 90vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-600); margin-bottom: 4px; }
.field input, .field select { width: 100%; padding: 9px 11px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- report print ---------- */
.iframe-wrap { width: 100%; height: 70vh; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.empty { color: var(--gray-600); font-style: italic; padding: 20px 0; }
@media (max-width: 720px) {
  .sidebar { width: 100%; display: flex; overflow-x: auto; }
  .sidebar button { white-space: nowrap; }
  .layout { flex-direction: column; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- role-based page visibility ---------- */
body[data-role="teacher"] .page:not([data-role="teacher"]) { display: none !important; }
body[data-role="admin"] .page[data-role="teacher"] { display: none !important; }

/* ---------- cards (teacher assignments) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-t { font-weight: 700; font-size: 15px; color: var(--blue); }
.card-s { font-size: 13px; margin: 4px 0 2px; }
.card-m { font-size: 12px; color: var(--gray-600); margin-bottom: 12px; }
.card .btn { width: 100%; }

/* ---------- settings form ---------- */
.settings-form { max-width: 440px; display: flex; flex-direction: column; gap: 12px; }
.settings-form .field { margin-bottom: 0; }

/* ---------- tags / status ---------- */
.tag.ok { background: #dcfce7; color: #166534; }

/* ---------- score inputs (teacher entry) ---------- */
input.score { width: 84px; padding: 6px 8px; text-align: center; }

