:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2433; --muted: #667085; --line: #e3e6eb;
  --brand: #1f3a5f; --brand-ink: #fff; --accent: #2f6fde;
  --wait: #b25e09; --wait-bg: #fff4e5; --ok: #157347; --ok-bg: #e7f6ee; --bad: #b42318; --bad-bg: #fdecea;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Georgian", "Sylfaen", Roboto, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.4; background: var(--bg); color: var(--ink); min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.mono { font-variant-numeric: tabular-nums; }

/* header */
.topbar { background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; gap: 16px; padding: 0 20px; min-height: 56px; flex-wrap: wrap; }
.topbar .title { font-weight: 700; font-size: 1.05rem; margin-right: 8px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: #cfd8e6; text-decoration: none; padding: 8px 12px; border-radius: 8px; }
.topbar nav a.on, .topbar nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; color: #cfd8e6; text-align: right; }
.topbar .who b { color: #fff; font-weight: 600; }
.langsw { display: inline-flex; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; overflow: hidden; }
.langsw button { background: transparent; border: 0; color: #cfd8e6; padding: 5px 10px; cursor: pointer; }
.langsw button.on { background: #fff; color: var(--brand); font-weight: 600; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }

/* buttons + inputs */
.btn { text-decoration: none; display: inline-block; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c4c9d2; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(.95); }
.btn.success { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { padding: 14px 22px; font-size: 1.05rem; font-weight: 600; border-radius: 10px; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { color: var(--ink); font-size: 15px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 6px 0; color: var(--ink); }
.checks label { display: inline-flex; gap: 6px; align-items: center; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #1f3a5f 0%, #2d5182 100%); }
.login { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 1.35rem; margin: 0; }
.login .hint { background: #eef4ff; border: 1px solid #cfe0ff; color: #1d3f7a; padding: 10px 12px; border-radius: 8px; font-size: .88rem; }
.login .err { color: var(--bad); font-size: .9rem; min-height: 1.2em; }
.login .top { display: flex; justify-content: space-between; align-items: center; }
.login .langsw { border-color: var(--line); } .login .langsw button { color: var(--muted); } .login .langsw button.on { background: var(--brand); color: #fff; }

/* tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* teacher */
.class-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.class-chip { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 14px; cursor: pointer; text-align: left; min-width: 96px; }
.class-chip b { display: block; font-size: 1.05rem; }
.class-chip.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,111,222,.2); }
.class-chip .counts { font-size: .78rem; color: var(--muted); }
.stu-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.stu { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; cursor: pointer; user-select: none; }
.stu input { width: 20px; height: 20px; accent-color: var(--accent); }
.stu.sel { border-color: var(--accent); background: #f2f6fe; }
.stu.waiting { background: var(--wait-bg); border-color: #f3d3a8; cursor: default; }
.stu.left { background: var(--ok-bg); border-color: #b7e2c9; cursor: default; }
.stu .nm { font-weight: 600; } .stu .meta { font-size: .8rem; color: var(--muted); }
.stu .grow { min-width: 0; }
.stu .btn { flex-shrink: 0; }
.actionbar { position: sticky; bottom: 0; background: rgba(244,245,247,.96); backdrop-filter: blur(4px); padding: 12px 0; display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; border-top: 1px solid var(--line); margin-top: 16px; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge.released { background: var(--wait-bg); color: var(--wait); }
.badge.left { background: var(--ok-bg); color: var(--ok); }
.badge.cancelled { background: #f0f1f3; color: var(--muted); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

/* guard */
.guard-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.guard-head .clock { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ok); }
.live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.live.off { color: var(--bad); }
.guard-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .guard-cols { grid-template-columns: 1fr; } }
.class-group { margin-bottom: 14px; }
.class-group h3 { font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 8px; }
.wcard { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid #f3d3a8; border-left: 5px solid var(--wait); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.wcard.fresh { animation: flash 2.5s ease-out; }
@keyframes flash { 0% { background: #ffe2b8; } 100% { background: #fff; } }
.wcard .nm { font-size: 1.2rem; font-weight: 700; }
.wcard .meta { font-size: .82rem; color: var(--muted); }
.wcard .note { font-size: .88rem; color: var(--wait); margin-top: 2px; }
.lrow { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lrow:last-child { border-bottom: 0; }
.lrow .t { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ok); min-width: 70px; }
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; background: #fff; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f8f9fb; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
tr:hover td { background: #fafbfc; }
td.wrap { max-width: 360px; word-break: break-word; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.stat .n { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.wait .n { color: var(--wait); } .stat.ok .n { color: var(--ok); }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal .err { color: var(--bad); font-size: .9rem; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; }
#toast div.err { background: var(--bad); }

/* ---------- portals ---------- */
.topbar .portal-name { font-weight: 500; opacity: .8; margin-left: 10px; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.35); }
.portal-badge { display: inline-block; align-self: flex-start; padding: 4px 10px; border-radius: 999px; font-weight: 600; font-size: .85rem; background: #eef1f5; color: var(--brand); }
.portal-link { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--ink); border: 1px solid var(--line); border-left: 5px solid var(--brand); border-radius: 10px; padding: 14px 16px; }
.portal-link:hover { background: #f8f9fb; }
.portal-link span { color: var(--muted); font-size: .9rem; }
.portal-link.teacher { border-left-color: #17795e; } .portal-link.security { border-left-color: #b25e09; }

/* Teachers: green */
body.portal-teacher { --brand: #17614c; --accent: #1f7a5f; }
body.portal-teacher .login-wrap { background: linear-gradient(160deg, #17614c 0%, #2a8a6c 100%); }

/* Security: dark, high-contrast kiosk for tablets / wall screens */
body.portal-security { color-scheme: dark; --bg: #0f141c; --panel: #171e29; --ink: #eef2f7; --muted: #9aa6b8; --line: #2a3443; --brand: #0b0f15;
  --wait: #ffb547; --wait-bg: #2b2112; --ok: #3ccf8e; --ok-bg: #12291f; font-size: 17px; }
body.portal-security .login-wrap { background: radial-gradient(circle at 30% 20%, #26324a 0%, #0b0f15 70%); }
body.portal-security .login { background: #171e29; }
body.portal-security .login .hint { background: #1d2a40; border-color: #2c3d5c; color: #cfe0ff; }
body.portal-security input, body.portal-security select { background: #0f141c; border-color: var(--line); }
body.portal-security .btn { background: #222b38; border-color: #334155; color: var(--ink); }
body.portal-security .btn.success { background: #1f9d64; border-color: #1f9d64; color: #fff; }
body.portal-security .btn.primary { background: #2f6fde; border-color: #2f6fde; color: #fff; }
body.portal-security .wcard { background: #1b2330; border-color: #4a3a1e; border-left-color: var(--wait); }
body.portal-security .wcard .nm { font-size: 1.45rem; }
body.portal-security .wcard .btn.big { padding: 18px 30px; font-size: 1.2rem; min-width: 150px; }
body.portal-security .guard-head .clock { font-size: 2.2rem; }
body.portal-security .empty { background: transparent; }
body.portal-security .langsw { border-color: #334155; }
body.portal-security .login .langsw button.on { background: #2f6fde; }
body.portal-security .portal-badge { background: #2b2112; color: var(--wait); }
@keyframes flash-dark { 0% { background: #5a3d0c; } 100% { background: #1b2330; } }
body.portal-security .wcard.fresh { animation: flash-dark 3s ease-out; }

/* supervisor overview */
.chip-group { margin-bottom: 4px; } .chip-group .class-list { margin: 4px 0 10px; }
.bar { display: flex; height: 10px; border-radius: 999px; background: #eef1f5; overflow: hidden; }
.bar .b-left { background: var(--ok); } .bar .b-wait { background: #f0b25c; }
.panel.alert { border-color: #f3d3a8; background: var(--wait-bg); }
.panel.alert .lrow { border-bottom-color: #f3d3a8; }
