:root {
  --navy: #0b3d91; --navy-2: #082d6b; --gold: #f2b705;
  --bg: #f4f6fb; --card: #ffffff; --ink: #1b2333; --muted: #5f6b80; --line: #e2e7f0;
  --ok: #138a4b; --ok-bg: #e6f6ed; --warn: #a15c00; --warn-bg: #fff4dc; --bad: #c0362c; --bad-bg: #fdecea;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 2px 8px rgba(16,24,40,.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
a { color: var(--navy); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--navy); color: #fff;
}
.topbar img { width: 30px; height: 30px; border-radius: 7px; }
.topbar .brand { font-weight: 700; font-size: 1.05rem; }
.topbar .brand small { display: block; font-weight: 400; font-size: .75rem; opacity: .8; }
.topbar .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.online { background: rgba(255,255,255,.15); color: #9ff0c0; }
.pill.offline { background: rgba(255,255,255,.15); color: #ffd27a; }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }
.wrap.wide { max-width: 1180px; }

/* ---------- Cards & buttons ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 10px; border: 1px solid transparent; background: var(--navy); color: #fff; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.secondary:hover { background: #f1f4fa; }
.btn.danger { background: #fff; color: var(--bad); border-color: #f2c4bf; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--navy); font-weight: 600; cursor: pointer; padding: 6px 4px; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cdd5e3; border-radius: 10px; background: #fff;
}
textarea { min-height: 110px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(11,61,145,.2); border-color: var(--navy); }
.error { color: var(--bad); font-size: .9rem; margin-top: 10px; min-height: 1.2em; }

/* ---------- Login ---------- */
.login { max-width: 400px; margin: 7vh auto 0; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 14px; }
.login h1 { text-align: center; font-size: 1.4rem; }
.login p.lead { text-align: center; color: var(--muted); margin: 6px 0 18px; }

/* ---------- Student: status ---------- */
.hello { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin: 4px 0 14px; }
.hello h1 { font-size: 1.3rem; }
.status { border-left: 6px solid var(--muted); }
.status.ok { border-color: var(--ok); }
.status.warn { border-color: var(--gold); }
.status.none { border-color: #9aa6bd; }
.status .row { display: flex; gap: 14px; align-items: center; }
.status .big { flex: 0 0 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; }
.status.ok .big { background: var(--ok-bg); color: var(--ok); }
.status.warn .big { background: var(--warn-bg); color: var(--warn); }
.status.none .big { background: #eef1f6; color: var(--muted); }
.status h3 { font-size: 1.05rem; margin-bottom: 2px; }
.status .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.progress { height: 8px; border-radius: 99px; background: #e8ecf4; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; width: 0; background: var(--navy); transition: width .3s; }
.banner { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-weight: 600; font-size: .9rem; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- Sheet list ---------- */
.day { margin-bottom: 14px; }
.day-head { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: 0 0 8px 2px; }
.tag { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--gold); color: #3b2b00; text-transform: uppercase; letter-spacing: .04em; }
.sheet {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.sheet:hover { border-color: #b9c4d8; }
.sheet .subj { flex: 0 0 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .8rem; }
.sheet .info { flex: 1; min-width: 0; }
.sheet .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sheet .meta { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.sheet .st { flex: 0 0 auto; font-size: .75rem; font-weight: 700; padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
.st.saved { background: var(--ok-bg); color: var(--ok); }
.st.missing { background: var(--warn-bg); color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 22px 12px; border: 2px dashed var(--line); border-radius: 12px; }
details.older { margin-top: 18px; }
details.older summary { cursor: pointer; font-weight: 700; color: var(--muted); padding: 8px 2px; }

.device { margin-top: 26px; }
.device .grid { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-top: 12px; }
.meter { height: 6px; background: #e8ecf4; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter > div { height: 100%; background: var(--navy); }

/* ---------- PDF viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #525a68; display: flex; flex-direction: column; }
.viewer .vbar { display: flex; align-items: center; gap: 6px; padding: calc(8px + env(safe-area-inset-top)) 8px 8px; background: #1f2633; color: #fff; }
.viewer .vbar .vt { flex: 1; min-width: 0; font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer .vbar button { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 8px; min-width: 40px; height: 40px; font-size: 1rem; font-weight: 700; cursor: pointer; padding: 0 10px; }
.viewer .pages { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 10px 0 30px; }
.viewer .page { margin: 0 auto 10px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.viewer .page canvas { display: block; width: 100%; height: 100%; }
.viewer .pageno { position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); background: rgba(0,0,0,.6); color: #fff; padding: 4px 10px; border-radius: 99px; font-size: .8rem; }

/* ---------- Dialog & toast ---------- */
dialog { border: 0; border-radius: 16px; padding: 20px; width: min(420px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10,20,40,.45); }
dialog h3 { margin-bottom: 6px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: 92vw; }
#toast div { background: #1f2633; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: tin .2s ease-out; }
#toast div.bad { background: var(--bad); }
#toast div.ok { background: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Teacher portal ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); padding: 0 12px; position: sticky; top: 50px; z-index: 15; }
.tabs button { background: none; border: 0; padding: 14px 14px 12px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--navy); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar select { width: auto; min-width: 200px; }
.weekpick { display: inline-flex; align-items: center; gap: 4px; background: #fff; border: 1px solid #cdd5e3; border-radius: 10px; padding: 2px; }
.weekpick button { background: none; border: 0; width: 38px; height: 38px; border-radius: 8px; cursor: pointer; font-size: 1.1rem; }
.weekpick button:hover { background: #f1f4fa; }
.weekpick span { min-width: 170px; text-align: center; font-weight: 600; font-size: .9rem; }
.secgrid { border: 1px solid #cdd5e3; border-radius: 10px; padding: 6px 12px 10px; max-height: 260px; overflow: auto; background: #fff; }
.secgrid .grade { font-weight: 700; margin: 8px 0 4px; display: flex; justify-content: space-between; }
.secgrid label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; margin: 4px 14px 4px 0; }
.drop { border: 2px dashed #b9c4d8; border-radius: 12px; padding: 22px; text-align: center; background: #fafbfe; cursor: pointer; }
.drop.over { border-color: var(--navy); background: #eef3fc; }
.hint { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: #fff; border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.tile b { display: block; font-size: 1.6rem; }
.tile.ok b { color: var(--ok); } .tile.warn b { color: var(--warn); } .tile.bad b { color: var(--bad); }
.tablewrap { overflow: auto; background: #fff; border-radius: 12px; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f7f9fc; font-weight: 700; position: sticky; top: 0; white-space: nowrap; }
td.c, th.c { text-align: center; }
.matrix th.sh { writing-mode: vertical-rl; transform: rotate(180deg); max-height: 150px; font-weight: 600; font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.matrix td.name { position: sticky; left: 0; background: #fff; min-width: 180px; font-weight: 600; }
.yes { color: var(--ok); font-weight: 800; } .no { color: var(--bad); font-weight: 800; } .gone { color: var(--warn); font-weight: 800; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); } .badge.gray { background: #eef1f6; color: var(--muted); }
.section-card { margin-bottom: 16px; }
.section-card h3 { margin-bottom: 10px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin: 8px 2px; }

/* ---------- v2: language switch, sibling accounts, opened ---------- */
.langswitch { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; background: #fff; }
.login .langswitch { display: flex; width: max-content; margin: -4px 0 10px auto; }
.langswitch button { border: 0; background: none; padding: 6px 12px; font-size: .8rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.langswitch button.active { background: var(--navy); color: #fff; }
.accounts { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px 4px; scrollbar-width: none; }
.accounts::-webkit-scrollbar { display: none; }
.acct { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 99px; border: 1px solid var(--line); background: #fff; cursor: pointer; text-align: left; }
.acct.active { border-color: var(--navy); box-shadow: 0 0 0 2px rgba(11,61,145,.15); }
.acct.expired { opacity: .6; }
.acct .av { width: 30px; height: 30px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 800; }
.acct b { display: block; font-size: .85rem; line-height: 1.1; }
.acct small { display: block; font-size: .72rem; color: var(--muted); }
.acct.add { padding: 0 14px; min-height: 44px; color: var(--navy); font-weight: 700; font-size: .85rem; border-style: dashed; }
.st.opened { background: #e7efff; color: var(--navy); }
.opn { color: var(--navy); font-weight: 800; }
.bar { height: 8px; border-radius: 99px; background: #eef1f6; overflow: hidden; min-width: 90px; }
.bar > div { height: 100%; }
.dash-grade td { background: #f7f9fc; font-weight: 700; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #f6f9ff; }

/* ---------- automatic update banner ---------- */
.updbanner { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 90;
  display: flex; align-items: center; gap: 12px; background: #1f2633; color: #fff; padding: 10px 10px 10px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); width: max-content; max-width: calc(100vw - 32px); font-size: .9rem; }
.updbanner .btn { background: var(--gold); color: #3b2b00; }
.viewer:not([hidden]) ~ .updbanner { bottom: calc(60px + env(safe-area-inset-bottom)); }
.appver { margin-top: 10px; font-size: .75rem; color: var(--muted); }
