:root {
  --brand: #1f4e79; --brand-2: #2d6aa3; --brand-soft: #e8f0f8; --accent: #f2b632;
  --bg: #f4f6f9; --panel: #fff; --text: #1d2733; --muted: #667485; --line: #e1e6ec;
  --ok: #1e8e4e; --ok-soft: #e4f5ea; --warn: #b7791f; --warn-soft: #fdf3e1; --bad: #c0392b; --bad-soft: #fbe9e7;
  --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", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg); font-size: 15px; line-height: 1.45;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #fff; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: flex; gap: .6rem; align-items: center; padding: .25rem .5rem 1rem; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: .75rem; }
.sidebar .brand img, .sidebar .brand .logo-fallback { width: 38px; height: 38px; border-radius: 8px; object-fit: contain; background: #fff; flex: none; }
.logo-fallback { display: grid; place-items: center; color: var(--brand); font-weight: 700; }
.sidebar .brand .name { font-weight: 650; font-size: .95rem; line-height: 1.2; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; color: #dbe7f3; padding: .55rem .7rem; border-radius: 8px; font-size: .93rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: #fff; color: var(--brand); font-weight: 600; }
.sidebar nav .sep { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #9fbbd6; margin: 1rem .7rem .3rem; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .term-pill { background: var(--brand-soft); color: var(--brand); padding: .25rem .7rem; border-radius: 999px; font-size: .85rem; font-weight: 600; }
.topbar .user { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.btn.menu-btn { display: none; }
.content { padding: 1.5rem; max-width: 1280px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* panels & cards */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.panel.flush { padding: 0; overflow: hidden; }
.panel .panel-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.panel.flush .panel-head { padding: 1rem 1.25rem 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .2rem; }
.stat .sub { color: var(--muted); font-size: .85rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; font-weight: 650; position: sticky; top: 0; }
tbody tr:hover { background: #fafcff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 700; background: #fafbfc; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* forms */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; color: #344150; }
input, select, textarea { width: 100%; padding: .55rem .7rem; border: 1px solid #cfd6de; border-radius: 8px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand-2); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: .9rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .9rem; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters > * { width: auto; min-width: 160px; }
.filters .grow { flex: 1; min-width: 200px; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: auto; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid #cfd6de; background: #fff; color: var(--text); padding: .5rem .9rem; border-radius: 8px; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f5f7fa; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: #efc4be; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }
.btn.link { border: none; background: none; color: var(--brand-2); padding: 0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-group { display: flex; gap: .35rem; flex-wrap: wrap; }

/* badges */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 650; background: #eef1f5; color: #475467; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.amount-bad { color: var(--bad); font-weight: 650; }
.amount-ok { color: var(--ok); font-weight: 650; }

/* attendance toggles */
.att-toggle { display: inline-flex; border: 1px solid #cfd6de; border-radius: 8px; overflow: hidden; }
.att-toggle button { border: none; background: #fff; padding: .35rem .65rem; font: inherit; font-weight: 650; font-size: .82rem; cursor: pointer; color: var(--muted); border-right: 1px solid #e3e8ee; }
.att-toggle button:last-child { border-right: none; }
.att-toggle button.on[data-v="P"] { background: var(--ok); color: #fff; }
.att-toggle button.on[data-v="A"] { background: var(--bad); color: #fff; }
.att-toggle button.on[data-v="L"] { background: var(--warn); color: #fff; }
.att-toggle button.on[data-v="E"] { background: var(--brand-2); color: #fff; }
.score-input { width: 80px; text-align: right; padding: .35rem .5rem; }
.score-input.err { border-color: var(--bad); background: var(--bad-soft); }

/* modal & toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.modal-body { padding: 1.1rem 1.25rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .9rem 1.25rem; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 12px 12px; }
.x-btn { border: none; background: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); line-height: 1; }
#toast-root { position: fixed; bottom: 1.25rem; right: 1.25rem; display: grid; gap: .5rem; z-index: 60; }
.toast { background: #1d2733; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); font-size: .9rem; max-width: 360px; }
.toast.err { background: var(--bad); }
.secret-box { background: var(--warn-soft); border: 1px solid #f0d9a8; border-radius: 8px; padding: .9rem 1rem; margin: .5rem 0; }
.secret-box code { font-size: 1.1rem; font-weight: 700; letter-spacing: .04em; user-select: all; }
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.alert.warn { background: var(--warn-soft); color: #7a5414; }
.alert.info { background: var(--brand-soft); color: var(--brand); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }

/* login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(135deg, #1f4e79 0%, #2d6aa3 60%, #3d84c6 100%); }
.auth-card { background: #fff; border-radius: 14px; padding: 2rem; width: min(400px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card .logo { width: 56px; height: 56px; margin-bottom: .75rem; }
.auth-card h1 { margin-bottom: .25rem; }
.auth-card .btn { width: 100%; justify-content: center; padding: .7rem; margin-top: .5rem; }

/* children cards */
.kid-card { display: grid; gap: .75rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); text-decoration: none; }

/* print documents */
.print-bar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.doc { background: #fff; color: #000; width: 210mm; max-width: 100%; margin: 0 auto 1.5rem; padding: 12mm 14mm; box-shadow: var(--shadow); border: 1px solid var(--line); font-size: 12.5px; }
.doc + .doc { page-break-before: always; break-before: page; }
.doc-head { display: grid; grid-template-columns: 70px 1fr 70px; align-items: center; text-align: center; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 10px; }
.doc-head img { width: 64px; height: 64px; object-fit: contain; }
.doc-head .sname { font-size: 20px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.doc-head .motto { font-style: italic; font-size: 12px; }
.doc-head .addr { font-size: 11.5px; }
.doc-title { text-align: center; font-weight: 800; font-size: 14px; letter-spacing: .06em; margin: 6px 0 10px; text-transform: uppercase; }
.doc table { font-size: 12px; }
.doc th, .doc td { border: 1px solid #555; padding: 4px 6px; background: none; position: static; color: #000; }
.doc th { font-size: 11px; background: #eef1f5; }
.doc .info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 18px; margin-bottom: 10px; }
.doc .info-grid div span { font-weight: 700; }
.doc .boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.doc .box { border: 1px solid #555; padding: 6px 8px; min-height: 48px; }
.doc .box .bl { font-weight: 700; font-size: 11px; text-transform: uppercase; }
.doc .sign { display: flex; justify-content: space-between; margin-top: 28px; }
.doc .sign div { border-top: 1px solid #000; padding-top: 3px; width: 40%; text-align: center; font-size: 11px; }
.doc.receipt { width: 148mm; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 250px; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  .btn.menu-btn { display: inline-flex; }
  .grid2, .grid3, .row, .row3 { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
  .topbar .user .who, .topbar .user .long { display: none; }
  .topbar .term-pill { font-size: .75rem; }
}
@media print {
  @page { size: A4; margin: 0; }
  body, :root { background: #fff; }
  .sidebar, .topbar, .print-bar, .no-print, #toast-root { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .doc { box-shadow: none; border: none; margin: 0; width: auto; }
}

.topbar .user .short { display: none; }
@media (max-width: 900px) { .topbar .user .short { display: inline; } }

/* EduBridge additions */
.switcher { width: auto; min-width: 180px; padding: .3rem .5rem; font-size: .88rem; }
.sidebar { display: flex; flex-direction: column; }
.sidebar nav { flex: 1; }
.sidebar .powered { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: #9fbbd6; padding: 1rem .7rem 0; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }
.perm-matrix .group-row td { background: #f3f6fa; font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; }
.perm-matrix input[type=checkbox] { width: auto; transform: scale(1.15); }
.perm-list { columns: 2; column-gap: 2rem; }
.perm-list .grp { break-inside: avoid; margin-bottom: .9rem; }
.perm-list .grp h4 { margin: 0 0 .3rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.wizard { display: grid; grid-template-columns: 230px 1fr; gap: 1.5rem; align-items: start; }
.wizard-steps { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.wizard-steps li { padding: .7rem 1rem; border-bottom: 1px solid var(--line); display: flex; gap: .6rem; align-items: center; cursor: pointer; font-size: .92rem; }
.wizard-steps li:last-child { border-bottom: none; }
.wizard-steps li.current { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.wizard-steps .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #cfd6de; display: grid; place-items: center; font-size: .72rem; font-weight: 700; flex: none; }
.wizard-steps li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.progress { height: 8px; background: #e7ecf2; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }
.auth-card.wide { width: min(640px, 100%); }
.status-card { text-align: center; }
.status-card .big { font-size: 2.5rem; margin-bottom: .25rem; }
.list-clean { list-style: none; padding: 0; margin: 0; }
.list-clean li { padding: .5rem 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.list-clean li:last-child { border-bottom: none; }
@media (max-width: 900px) { .wizard { grid-template-columns: 1fr; } .perm-list { columns: 1; } }
@media (min-width: 901px) { .shell { background: linear-gradient(to right, var(--brand) 240px, var(--bg) 240px); } }
