:root {
  --navy-900: #0b1a4a;
  --navy-800: #102466;
  --navy-700: #16308a;
  --navy-600: #1f3fae;
  --blue: #2557d6;
  --blue-50: #eef3ff;
  --gold: #e3b04b;
  --gold-600: #c9952f;
  --gold-50: #fff7e6;
  --bg: #f2f5fb;
  --card: #ffffff;
  --text: #17203a;
  --muted: #6b7591;
  --line: #e3e8f2;
  --red: #d63b3b;
  --green: #1f9d62;
  --pink: #d9468f;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(16, 36, 102, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Kantumruy Pro', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0;
  background: radial-gradient(circle at 20% 0%, #24409e 0%, var(--navy-800) 45%, var(--navy-900) 100%);
  color: #e8edff;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 16px 14px;
  overflow-y: auto;
}
.brand {
  border: 1.5px solid rgba(227, 176, 75, .55);
  border-radius: 16px;
  padding: 12px 10px 10px;
  text-align: center;
  background: rgba(255, 255, 255, .04);
}
.brand img { width: 74px; height: auto; border-radius: 10px; }
.brand .name { font-weight: 700; font-size: 22px; letter-spacing: .3px; line-height: 1.1; margin-top: 4px; }
.brand .name span { color: var(--gold); }
.brand .tag { font-size: 12px; color: #c8d2f5; margin-top: 2px; }

.class-picker { margin: 14px 0 8px; display: flex; gap: 8px; align-items: center; }
.class-picker select {
  flex: 1; min-width: 0;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .18);
  color: #fff; border-radius: 10px; padding: 8px 10px; font-weight: 600;
}
.class-picker select option { color: var(--text); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .3);
  background: transparent; color: #fff; cursor: pointer; font-size: 20px; line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, .1); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px; color: #e3e9ff; font-size: 16px;
}
.nav a svg { width: 22px; height: 22px; flex-shrink: 0; }
.nav a:hover { background: rgba(255, 255, 255, .08); }
.nav a.active { background: rgba(227, 176, 75, .16); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav a.active svg { color: var(--gold); }
.nav a .soon { margin-left: auto; font-size: 11px; background: rgba(227, 176, 75, .9); color: var(--navy-900); padding: 1px 7px; border-radius: 99px; font-weight: 600; }
.nav .sep { height: 1px; background: rgba(255, 255, 255, .12); margin: 8px 6px; }

.user-box {
  margin-top: auto; padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, .06);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--gold); color: var(--navy-900);
  display: grid; place-items: center; font-weight: 700; flex-shrink: 0; overflow: hidden;
}
.user-box .who { flex: 1; min-width: 0; }
.user-box .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .who small { color: #b9c4ea; }
.user-box button { background: none; border: 0; color: #fff; cursor: pointer; padding: 6px; border-radius: 8px; }
.user-box button:hover { background: rgba(255, 255, 255, .1); }

.main { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; margin: 0; font-weight: 700; color: var(--navy-800); }
.page-head .sub { color: var(--muted); font-size: 14px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card-pad { padding: 18px; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: #fff; padding: 9px 16px; border-radius: 10px;
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #c9d3ea; background: #f8faff; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: #1d48b8; border-color: #1d48b8; }
.btn-gold { background: var(--gold); color: var(--navy-900); border-color: var(--gold); font-weight: 600; }
.btn-gold:hover { background: var(--gold-600); border-color: var(--gold-600); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: #fff1f1; border-color: #f3c4c4; }
.btn-sm { padding: 5px 10px; font-size: 14px; border-radius: 8px; }
.btn[disabled] { opacity: .6; cursor: default; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 14px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; width: 100%;
}
.input:focus { outline: 2px solid rgba(37, 87, 214, .25); border-color: var(--blue); }
textarea.input { min-height: 80px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }

.search {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; background: #fff; min-width: 240px;
}
.search input { border: 0; outline: 0; padding: 9px 0; flex: 1; background: transparent; }
.search svg { width: 18px; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { padding: 6px 12px; border-radius: 10px; background: #fff; border: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.chip b { color: var(--text); margin-left: 4px; }
.chip.blue { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip.blue b { color: #fff; }
.chip.pink b { color: var(--pink); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar .right { margin-left: auto; display: flex; gap: 8px; }
.seg { display: inline-flex; background: #eef1f8; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg button svg { width: 18px; height: 18px; display: block; }
.icon-btn svg { width: 20px; height: 20px; }
.seg button.on { background: #fff; color: var(--blue); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  background: #f5f7fc; color: var(--navy-800); font-weight: 600; font-size: 14px;
  text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:hover td { background: #fafbff; }
.tbl td.num, .tbl th.num { text-align: center; width: 54px; color: var(--muted); }
.tbl .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tbl th.group { text-align: center; background: #e8f6ee; color: #1b6b45; }
.thumb {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #e8edf8;
  display: grid; place-items: center; color: var(--muted); font-weight: 600; overflow: hidden; flex-shrink: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.person { display: flex; align-items: center; gap: 10px; }
.person small { display: block; color: var(--muted); font-size: 12.5px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; }
.badge.m { background: var(--blue-50); color: var(--blue); }
.badge.f { background: #fdeef6; color: var(--pink); }
.badge.gold { background: var(--gold-50); color: #9a6b12; }
.badge.gray { background: #eef0f5; color: var(--muted); }
.badge.green { background: #e6f6ee; color: var(--green); }
.badge.red { background: #fdecec; color: var(--red); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 52px; height: 52px; color: #c3cbe0; }
.empty p { margin: 8px 0 16px; }

/* Student cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; padding: 16px; }
.scard { border: 1px solid var(--line); border-radius: 14px; padding: 16px 12px 12px; text-align: center; background: #fff; position: relative; }
.scard .ph { width: 92px; height: 112px; margin: 0 auto 10px; border-radius: 10px; background: #e8edf8; overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 30px; font-weight: 600; }
.scard .ph img { width: 100%; height: 100%; object-fit: cover; }
.scard b { display: block; }
.scard small { color: var(--muted); }
.scard .no { position: absolute; top: 8px; left: 10px; font-size: 12px; color: var(--muted); }
.scard:hover { border-color: #c9d3ea; box-shadow: var(--shadow); cursor: pointer; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 18px; display: flex; gap: 14px; align-items: center; }
.stat .ic { width: 50px; height: 50px; border-radius: 14px; display: grid; place-items: center; }
.stat .ic svg { width: 26px; height: 26px; }
.stat .v { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--navy-800); }
.stat .l { color: var(--muted); font-size: 14px; }
.hero {
  background: linear-gradient(120deg, var(--navy-800), var(--navy-600) 60%, #2a4fc9);
  color: #fff; border-radius: var(--radius); padding: 22px 24px; display: flex; align-items: center; gap: 20px;
  margin-bottom: 18px; position: relative; overflow: hidden;
}
.hero::after { content: ''; position: absolute; right: -60px; bottom: -80px; width: 320px; height: 200px; border-radius: 50%; border-top: 3px solid var(--gold); transform: rotate(-12deg); opacity: .8; }
.hero h2 { margin: 0 0 4px; font-size: 22px; }
.hero p { margin: 0; color: #d3dcfb; }
.hero img { width: 76px; border-radius: 12px; }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.quick a { display: flex; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: #fff; }
.quick a:hover { border-color: var(--gold); }
.quick a svg { width: 24px; height: 24px; color: var(--blue); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(11, 26, 74, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.sm { max-width: 440px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 18px; color: var(--navy-800); }
.modal-head button { margin-left: auto; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.photo-edit { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.photo-edit .ph { width: 96px; height: 116px; border-radius: 12px; background: #e8edf8; overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 30px; border: 2px dashed #c9d3ea; }
.photo-edit .ph img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--navy-800); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); animation: up .2s ease; max-width: 340px; }
.toast.error { background: var(--red); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Auth ---------- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 30% 10%, #2a4bb5 0%, var(--navy-800) 45%, var(--navy-900) 100%);
  position: relative; overflow: hidden;
}
.auth::after { content: ''; position: absolute; right: -10%; bottom: -30%; width: 70%; height: 60%; border-radius: 50%; border-top: 4px solid var(--gold); transform: rotate(-14deg); opacity: .7; pointer-events: none; }
.auth-card { position: relative; z-index: 1; background: #fff; border-radius: 20px; width: 100%; max-width: 420px; padding: 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.auth-card .logo { text-align: center; margin-bottom: 18px; }
.auth-card .logo img { width: 110px; border-radius: 16px; }
.auth-card .logo h1 { margin: 6px 0 0; font-size: 30px; color: var(--navy-800); }
.auth-card .logo h1 span { color: var(--gold-600); }
.auth-card .logo p { margin: 2px 0 0; color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .btn { width: 100%; padding: 11px; font-size: 16px; }
.auth-err { color: var(--red); font-size: 14px; min-height: 18px; }
.auth-note { background: var(--gold-50); color: #7a5410; border-radius: 10px; padding: 10px 12px; font-size: 14px; }

.coming { text-align: center; padding: 60px 20px; }
.coming img { width: 90px; border-radius: 14px; }
.coming h2 { color: var(--navy-800); margin: 12px 0 6px; }
.coming p { color: var(--muted); max-width: 480px; margin: 0 auto; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--navy-800); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 30; }
  .topbar img { width: 32px; border-radius: 6px; }
  .topbar b span { color: var(--gold); }
  .main { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .search { min-width: 0; flex: 1 1 100%; }
  .layout { display: block; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px; }
  .stat .ic { width: 40px; height: 40px; }
  .hero img { display: none; }
}

/* ---------- Score table ---------- */
.period-seg { gap: 2px; flex-wrap: wrap; max-width: 100%; }
.seg-sel {
  border: 0; background: transparent; padding: 6px 8px; border-radius: 8px; cursor: pointer; color: var(--muted);
  -webkit-appearance: none; appearance: none; padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7591' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center;
}
.seg-sel.on { background-color: #fff; color: var(--blue); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.save-state { font-size: 14px; color: var(--muted); }
.save-state.ok { color: var(--green); }
.save-state.err { color: var(--red); }
.lock-note { display: flex; gap: 8px; align-items: center; background: var(--gold-50); color: #7a5410; padding: 10px 16px; font-size: 14px; border-bottom: 1px solid var(--line); }
.lock-note svg { width: 18px; height: 18px; }
.score-wrap { overflow: auto; max-height: calc(100vh - 250px); }
body.fullscreen .sidebar, body.fullscreen .topbar { display: none; }
body.fullscreen .main { padding: 10px; }
body.fullscreen .score-wrap { max-height: calc(100vh - 150px); }
.score-tbl { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: 14px; }
.score-tbl th, .score-tbl td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.score-tbl thead th {
  position: sticky; background: #f5f7fc; color: var(--navy-800); font-weight: 600; padding: 7px 6px;
  text-align: center; z-index: 2; line-height: 1.3; font-size: 13.5px;
}
.score-tbl thead tr:first-child th { top: 0; }
.score-tbl thead tr:nth-child(2) th { top: 38px; }
.score-tbl thead th[rowspan="2"] { top: 0; }
.score-tbl th.subj { min-width: 78px; max-width: 110px; font-weight: 500; }
.score-tbl th small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
.score-tbl th.grp { font-weight: 700; height: 38px; }
.grp-0 { background: #e8f0ff !important; } .grp-1 { background: #e7f6ee !important; }
.grp-2 { background: #fff4df !important; } .grp-3 { background: #f3ecff !important; }
.score-tbl th.res-h { background: #eef1f8; min-width: 66px; }
.score-tbl .sticky { position: sticky; z-index: 1; background: #fff; }
.score-tbl thead .sticky { z-index: 3; background: #f5f7fc; }
.score-tbl .c-no { left: 0; width: 44px; min-width: 44px; text-align: center; color: var(--muted); }
.score-tbl .c-name { left: 44px; min-width: 190px; text-align: left !important; box-shadow: 2px 0 0 var(--line); }
.score-tbl td { padding: 0; height: 40px; text-align: center; white-space: nowrap; }
.score-tbl td.c-name { padding: 0 10px; }
.score-tbl .thumb.sm { width: 28px; height: 28px; font-size: 12px; }
.score-tbl .fem { font-size: 11px; color: var(--pink); background: #fdeef6; border-radius: 4px; padding: 0 4px; }
.score-tbl td.cell input {
  width: 100%; height: 39px; border: 0; text-align: center; background: transparent; font-weight: 500; outline: none; padding: 0 4px;
}
.score-tbl.editable td.cell input:focus { box-shadow: inset 0 0 0 2px var(--blue); background: #fff; }
.score-tbl td.cell input.low, .score-tbl td.low { color: var(--red); font-weight: 600; }
.score-tbl td.cell input.bad { background: #ffe3e3; color: var(--red); box-shadow: inset 0 0 0 2px var(--red); }
.score-tbl tbody tr:hover td, .score-tbl tr.focus-row td { background: #f6f9ff; }
.score-tbl tr.focus-row td.sticky { background: #eef3ff; }
.score-tbl td.res { background: #fafbfe; font-weight: 600; padding: 0 8px; }
.score-tbl td.res.total { color: var(--muted); font-weight: 500; }
.score-tbl td.res.avg { color: var(--navy-800); }
.score-tbl td.res.avg.low { color: var(--red); }
.score-tbl td.res.rank { color: var(--blue); }
.score-tbl td.ro { padding: 0 10px; }
.score-tbl td.ro.strong { font-weight: 600; background: #fbfcff; }
.grade { display: inline-grid; place-items: center; min-width: 26px; height: 24px; border-radius: 6px; font-weight: 700; font-size: 13px; padding: 0 4px; }
.g-A { background: #e3f6ea; color: #16834f; } .g-B { background: #e9f7d9; color: #4b8a12; }
.g-C { background: #e8efff; color: #2557d6; } .g-D { background: #fff4d6; color: #a07408; }
.g-E { background: #ffeadb; color: #c25e12; } .g-F { background: #fde5e5; color: #d63b3b; }
.legend { color: var(--muted); font-size: 13.5px; line-height: 2; }
.month-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.mpick input { display: none; }
.mpick span { display: inline-block; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 14px; }
.mpick input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
.print-head { display: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .topbar, .no-print, #toast-root { display: none !important; }
  .main { padding: 0; }
  .card { border: 0; box-shadow: none; }
  .print-head { display: block; text-align: center; margin-bottom: 8px; font-size: 14px; }
  .print-head b { font-family: 'Moul', serif; font-weight: 400; font-size: 15px; }
  .score-wrap { max-height: none; overflow: visible; }
  .score-tbl { font-size: 9.5px; width: 100%; min-width: 0; }
  .score-tbl th.subj, .score-tbl .c-name, .score-tbl th.res-h, .score-tbl .c-no { min-width: 0 !important; width: auto; }
  .score-tbl td { white-space: normal; }
  .score-tbl th, .score-tbl td { border: 1px solid #999 !important; height: auto; padding: 3px !important; }
  .score-tbl thead th { position: static; }
  .score-tbl .sticky { position: static; box-shadow: none; }
  .score-tbl .thumb { display: none; }
  .score-tbl td.cell input { height: auto; padding: 0; }
}

@media (max-width: 860px) {
  .score-tbl .c-name { min-width: 120px; }
  .score-tbl .c-name .thumb { display: none; }
  .score-tbl .c-no { width: 34px; min-width: 34px; }
  .score-tbl .c-name { left: 34px; }
  .score-wrap { max-height: none; }
}

/* ---------- Official document (print / PDF) ---------- */
#print-root { display: none; }
.rank-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.rank-stats > div { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; }
.rank-stats span { color: var(--muted); font-size: 13.5px; }
.rank-stats b { font-size: 24px; color: var(--navy-800); line-height: 1.2; }
.rank-stats small { color: var(--muted); }
.rank-stats .ok b { color: var(--green); } .rank-stats .bad b { color: var(--red); }
.rank-tbl .rk { display: inline-grid; place-items: center; min-width: 30px; height: 30px; border-radius: 50%; background: #eef1f8; font-weight: 700; color: var(--navy-800); }
.rank-tbl tr.top1 .rk { background: linear-gradient(135deg, #f7d77a, #e3b04b); color: #5a3e00; }
.rank-tbl tr.top2 .rk { background: linear-gradient(135deg, #e9edf3, #c3ccd9); }
.rank-tbl tr.top3 .rk { background: linear-gradient(135deg, #f3c9a4, #d99560); color: #5a2d00; }
.txt-red { color: var(--red); }
.sheet-bar { display: flex; justify-content: space-between; gap: 10px; padding: 8px 16px; font-size: 13.5px; color: var(--muted); background: #fafbfe; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sheet-tbl td.cell input { text-align: left; padding: 0 8px; font-weight: 400; }
.sheet-tbl tr.new-row td { background: #fcfdff; }
.sheet-tbl tr.new-row td.c-no { color: var(--blue); font-weight: 700; }

.doc { font-family: 'Battambang', 'Kantumruy Pro', serif; color: #111; font-size: 11.5px; line-height: 1.55; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; flex-direction: row-reverse; margin-bottom: 2px; }
.doc .kingdom { text-align: center; font-family: 'Moul', serif; color: #1f3a93; font-size: 13px; line-height: 1.9; }
.doc .kingdom .orn { width: 120px; height: 12px; color: #1f3a93; display: block; margin: 0 auto; }
.doc .office { text-align: center; font-family: 'Moul', serif; font-size: 11px; color: #1f3a93; line-height: 1.9; padding-top: 4px; }
.doc .office .moeys { width: 52px; display: block; margin: 0 auto 2px; }
.doc .office .l2 { color: #7030a0; } .doc .office .l3 { color: #c00000; }
.doc-title { font-family: 'Moul', serif; font-weight: 400; color: #0b5394; font-size: 18px; text-align: center; margin: 4px 0 0; line-height: 1.8; }
.doc-sub { font-family: 'Moul', serif; color: #7030a0; font-size: 12px; text-align: center; margin-bottom: 10px; }
.doc .dt { width: 100%; border-collapse: collapse; font-size: 11px; }
.doc .dt th { font-family: 'Moul', serif; font-weight: 400; color: #1f3a93; background: #ddebf7; font-size: 10px; padding: 4px 3px; border: 1px solid #5b7db1; line-height: 1.6; }
.doc .dt td { border: 1px solid #5b7db1; padding: 3px 4px; text-align: center; height: 22px; }
.doc .dt td.l { text-align: left; padding-left: 7px; white-space: nowrap; }
.doc .dt td.red { color: #c00000; }
.doc .dt td.rk { color: #c00000; font-weight: 700; }
.doc .dt td.b { font-weight: 700; }
.doc .dt th.gap, .doc .dt td.gap { border: 0; background: none; width: 10px; }
.doc .dt tr { page-break-inside: avoid; }
.doc .dt thead { display: table-header-group; }
.doc .score-dt th { font-size: 9px; padding: 3px 2px; }
.doc .score-dt td { font-size: 10.5px; padding: 2px; }
.doc .dg { font-weight: 700; } .doc .dg.g-F { color: #c00000; } .doc .dg.g-A { color: #16834f; }
.doc .dline { margin-top: 8px; color: #1f3a93; }
.doc .dstat { margin-top: 10px; border-collapse: collapse; color: #1f3a93; }
.doc .dstat td { padding: 1px 18px 1px 0; }
.doc-foot { display: flex; justify-content: space-between; margin-top: 12px; page-break-inside: avoid; text-align: center; }
.doc-foot .f-left { padding-top: 24px; min-width: 38%; }
.doc-foot .f-right { min-width: 46%; }
.doc-foot .f-role { font-family: 'Moul', serif; color: #0b5394; font-size: 12px; line-height: 2; }
.doc-foot .f-name { font-family: 'Moul', serif; color: #0b5394; font-size: 12px; margin-top: 54px; min-height: 18px; }

@media print {
  body.printing { background: #fff; }
  body.printing #app, body.printing #modal-root, body.printing #toast-root { display: none !important; }
  body.printing #print-root { display: block; }
  .doc { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Letterhead v2: office · logo · kingdom (matches official samples) */
.doc-top { margin-bottom: 8px; }
.doc-head3 { display: grid; grid-template-columns: 1fr 90px 1fr; align-items: start; gap: 8px; }
.doc-head3 .office { text-align: left; padding-top: 22px; font-size: 11px; line-height: 2; }
.doc-head3 .office .l4 { color: #1f3a93; }
.doc-head3 .logo { text-align: center; }
.doc-head3 .logo .moeys { width: 64px; display: inline-block; margin: 0; }
.doc-head3 .kingdom { text-align: center; justify-self: end; padding-right: 6px; }
.doc-top .title-band { text-align: center; padding: 2px 0 4px; }
.doc-top.band { margin: 0 0 0; }
.doc-top.band .doc-head3 { background: #dde9f7; padding: 6px 10px 4px; }
.doc-top.band .title-band { background: #d3e5c4; padding: 2px 0 6px; }
.doc-top.band .doc-title { color: #c00000; text-decoration: underline; text-underline-offset: 6px; font-size: 17px; }
.doc-top.band .doc-sub { color: #000; margin-bottom: 0; }
.doc .rank-dt { font-size: 12.5px; border: 1.5px solid #000; }
.doc .rank-dt th { background: #33aaee; color: #000; border: 1px solid #000; font-size: 11px; padding: 5px 3px; }
.doc .rank-dt td { border: 1px solid #000; height: 25.5px; font-size: 12.5px; padding: 0 4px; }
.doc .rank-dt td.num { font-family: 'Times New Roman', serif; font-size: 13.5px; }
.doc .rank-dt td.rk { color: #e00000; font-weight: 700; }
.doc .rank-dt td.fail { background: #ffff4d; }
.doc .rank-dt th.gap, .doc .rank-dt td.gap { background: #b0b0b0; width: 22px; border: 1px solid #000; }
.doc .rank-dt th.n { width: 34px; }
.doc .dstat { margin-top: 14px; color: #000; font-size: 12.5px; }
.doc .dstat td { padding: 2px 22px 2px 0; }
.doc .dstat td.v { font-family: 'Times New Roman', serif; font-size: 13.5px; text-align: center; min-width: 40px; }
.doc { line-height: 1.7; }
.doc .dt td, .doc .dt th { line-height: 1.5; }
/* Letterhead v3 — logo exactly centred, equal side columns */
.doc-head3 { grid-template-columns: minmax(0, 1fr) 92px minmax(0, 1fr); gap: 0; align-items: start; }
.doc-head3 .office { font-family: 'Moul', serif; font-size: 10.5px; line-height: 2.05; white-space: nowrap; padding-top: 20px; text-align: left; overflow: visible; }
.doc-head3 .office > div { width: max-content; }
.doc-head3 .logo { display: flex; justify-content: center; align-items: flex-start; padding-top: 2px; }
.doc-head3 .logo .moeys { width: 66px; height: auto; display: block; background: transparent; }
.doc-head3 .kingdom { justify-self: end; text-align: center; white-space: nowrap; padding: 4px 4px 0 0; font-size: 13px; line-height: 2.05; }
.doc-top.band .doc-head3 { padding: 6px 14px 6px; }
.doc-top .title-band { padding-top: 6px; }
.doc-top.band .title-band { padding: 6px 0 8px; }
.doc-title { letter-spacing: .2px; }
/* Score sheet: bigger, easier to read on A4 */
.doc .score-dt { font-family: 'Battambang', serif; }
.doc .score-dt th { font-size: 10px; padding: 4px 2px; line-height: 1.55; }
.doc .score-dt td { font-size: 12px; padding: 3px 2px; height: 27px; }
.doc .score-dt td.l { font-size: 12.5px; padding-left: 6px; }
.doc .score-dt td.num, .doc .score-dt td.n { font-family: 'Times New Roman', serif; font-size: 13px; }
.doc.land .doc-title { font-size: 20px; }
.doc .dt td.l { font-family: 'Battambang', serif; }
.doc .score-dt td { height: 24px; }
.doc.land .dstat { margin-top: 8px; }
.doc.land .dstat td { padding-top: 0; padding-bottom: 0; }
.doc.land .doc-foot { margin-top: 2px; }
.doc.land .doc-foot .f-name { margin-top: 44px; }
.doc.land .doc-foot .f-left { padding-top: 20px; }

/* ===================== Step 3–5 components ===================== */
/* Premium nav tiles */
.nav a .ni { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(145deg, var(--g1), var(--g2)); box-shadow: 0 3px 8px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.35); }
.nav a .ni svg { width: 18px; height: 18px; color: #fff !important; stroke-width: 2.1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.nav a.active .ni { box-shadow: 0 0 0 2px rgba(227,176,75,.85), 0 3px 10px rgba(0,0,0,.3); }
.hint { color: var(--muted); font-size: 13.5px; }
.input.sm { padding: 6px 8px; font-size: 14px; border-radius: 8px; min-width: 60px; width: 100%; }
.tbl.ed td { padding: 5px 6px; }
.tbl.ed th { white-space: nowrap; }
.legend-in { font-size: 13.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.thumb.lg { width: 84px; height: 84px; border-radius: 50%; font-size: 30px; }
textarea.input { min-height: 90px; resize: vertical; line-height: 1.8; }

/* Admin hub */
.hub { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.hub-sec { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
.hub-h { background: linear-gradient(135deg, var(--hc), color-mix(in srgb, var(--hc) 70%, #000)); color: #fff; font-weight: 600; padding: 12px 16px; font-size: 16px; }
.hub-i { display: flex; align-items: center; gap: 12px; padding: 11px 16px; color: var(--text); text-decoration: none; border-top: 1px solid var(--line); transition: background .15s; }
.hub-i:hover { background: color-mix(in srgb, var(--hc) 7%, #fff); }
.hub-ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--hc) 14%, #fff); color: var(--hc); flex-shrink: 0; }
.hub-ic svg { width: 18px; height: 18px; }
.hub-p { margin-left: auto; color: var(--muted); opacity: .6; } .hub-p svg { width: 16px; height: 16px; }

/* Signatures + border picker (settings) */
.sig-slot { display: flex; gap: 14px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.sig-prev { width: 130px; height: 64px; border: 1px dashed #c3cbe0; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: repeating-conic-gradient(#f3f5fa 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.sig-prev img { max-width: 120px; max-height: 58px; object-fit: contain; }
.sig-prev span { font-size: 12.5px; color: var(--muted); }
.border-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.bpick { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13.5px; }
.bpick span { width: 64px; height: 64px; border: 16px solid; border-image-slice: 32; border-image-repeat: round; display: block; }
.bpick.on { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(227,176,75,.25); }

/* Honor preview (screen) */
.honor-preview { display: flex; gap: 14px; flex-wrap: wrap; padding: 8px 0 12px; }
.hp { flex: 1 1 150px; max-width: 200px; background: linear-gradient(180deg, #fffaf0, #fff); border: 1px solid #f0e2bf; border-radius: 14px; padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; text-align: center; }
.hp small { color: var(--muted); }
.hp-rank { position: absolute; top: 8px; left: 8px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; background: #8a94ad; }
.hp-rank.r1 { background: linear-gradient(145deg, #f7d27a, #c9952f); } .hp-rank.r2 { background: linear-gradient(145deg, #e3e7ee, #9aa3b5); } .hp-rank.r3 { background: linear-gradient(145deg, #f2b9a0, #b5653f); }
.three-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 8px; }
.tc h4 { margin: 0 0 10px; padding: 8px 12px; border-radius: 10px; color: #fff; font-weight: 600; text-align: center; }
.tc-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.cat-study { background: linear-gradient(135deg, #2f6fe0, #173f9e); } .cat-moral { background: linear-gradient(135deg, #e7a51f, #b0700a); } .cat-labor { background: linear-gradient(135deg, #24a865, #11713f); }
@media (max-width: 760px) { .three-cols { grid-template-columns: 1fr; } }

/* Number badges */
.numbox { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-family: 'Moul', serif; font-size: 14px; flex-shrink: 0;
  background: radial-gradient(circle at 35% 30%, #5b8cf0, #1b3c99); box-shadow: 0 2px 4px rgba(0,0,0,.25), inset 0 0 0 2px rgba(255,255,255,.55); }
.numbox.n1 { background: radial-gradient(circle at 35% 30%, #ffe08a, #c08a12); } .numbox.n2 { background: radial-gradient(circle at 35% 30%, #f1f3f7, #8b94a7); color: #24304d; }
.numbox.n3 { background: radial-gradient(circle at 35% 30%, #f7c1a5, #a85a35); }
.numbox.sm { width: 28px; height: 28px; font-size: 12px; }

/* ---------- Printed pages ---------- */
.frame-page { border: 26px solid; border-image-slice: 32; border-image-width: 26px; border-image-repeat: round; padding: 10px 14px; min-height: 270mm; box-sizing: border-box; page-break-after: always; display: flex; flex-direction: column; }
.frame-page.land { min-height: 186mm; }
.doc.land .frame-page { min-height: 186mm; }
.frame-page:last-child { page-break-after: auto; }
.frame-in { flex: 1; display: flex; flex-direction: column; }
.frame-in > .doc-foot { margin-top: auto; }
.frame-page .doc-top.band .doc-head3, .frame-page .doc-top.band .title-band { background: none; }
.honor-title { font-family: 'Moul', serif; font-weight: 400; text-align: center; color: #0b3c8c; font-size: 30px; margin: 10px 0 0; line-height: 1.8; letter-spacing: .5px; }
.honor-title span { color: #c00000; margin-left: 10px; }
.honor-title.v2 { font-size: 24px; color: #c00000; }
.honor-class { text-align: center; font-family: 'Moul', serif; color: #0b3c8c; font-size: 15px; margin: 2px 0 10px; }
.podium { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 8px; }
.prow { display: flex; justify-content: center; gap: 70px; }
.hslot { display: flex; flex-direction: column; align-items: center; width: 210px; }
.hno { font-family: 'Moul', serif; color: #0b3c8c; font-size: 14px; margin-bottom: 4px; }
.hphoto { width: 112px; height: 136px; border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: linear-gradient(160deg, #eef3ff, #d9e3f7);
  border: 3px solid #fff; box-shadow: 0 0 0 2px #c9a646, 0 4px 10px rgba(0,0,0,.18); font-family: 'Moul', serif; font-size: 40px; color: #1f3a93; }
.hslot.first .hphoto { width: 132px; height: 160px; box-shadow: 0 0 0 3px #d4a017, 0 6px 14px rgba(0,0,0,.2); }
.hphoto img { width: 100%; height: 100%; object-fit: cover; }
.ribbon { position: relative; width: 230px; height: 50px; margin-top: -10px; display: grid; place-items: center; }
.ribbon svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ribbon span { position: relative; font-family: 'Moul', serif; font-size: 13px; margin-top: -6px; white-space: nowrap; }
.three { margin: 6px 0 10px; }
.cat-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin: 0 0 12px 48px; }
.catbox { font-family: 'Moul', serif; color: #fff; text-align: center; padding: 8px 4px; border-radius: 8px; font-size: 15px; box-shadow: 0 2px 5px rgba(0,0,0,.2); }
.catbox.study { background: linear-gradient(135deg, #2f6fe0, #173f9e); } .catbox.moral { background: linear-gradient(135deg, #e7a51f, #b0700a); } .catbox.labor { background: linear-gradient(135deg, #24a865, #11713f); }
.hrow { display: grid; grid-template-columns: 34px 1fr 1fr 1fr; gap: 14px; align-items: center; margin-bottom: 12px; }
.hrow > :nth-child(4) { display: none; }
.plaque { height: 46px; border-radius: 23px; display: grid; place-items: center; background: linear-gradient(180deg, #fffdf5, #f6ecd0); border: 1.5px solid #c9a646; box-shadow: inset 0 0 0 3px #fff, 0 2px 4px rgba(0,0,0,.12); padding: 0 8px; }
.plaque span { font-family: 'Battambang', serif; font-weight: 700; color: #0b3c8c; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.f-sig { height: 0; position: relative; }
.f-sig .sig-img { position: absolute; left: 50%; transform: translateX(-50%); top: 2px; max-height: 50px; max-width: 150px; object-fit: contain; }
.f-sig .sig-img.stamp { max-height: 84px; max-width: 84px; top: -18px; transform: translateX(-110%); opacity: .9; }

/* Follow-up book */
.fb-page { page-break-after: always; }
.fb-page:last-child { page-break-after: auto; }
.fb-info { display: flex; flex-wrap: wrap; gap: 6px 26px; margin: 2px 0 8px; font-size: 13px; }
.fb-info .nm { font-family: 'Moul', serif; font-weight: 400; color: #0b3c8c; }
.fb-tables { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.doc .fb td { height: 23px; font-size: 12px; }
.doc .fb th { font-size: 10px; }
.doc .fb .gcell { font-weight: 700; color: #0b3c8c; }
.fb-sum { display: flex; flex-wrap: wrap; gap: 4px 22px; margin-top: 8px; font-size: 12.5px; }
.fb-sum .rk { color: #c00000; }
.fb-cmt { margin-top: 6px; font-size: 12.5px; } .fb-cmt span { border-bottom: 1px dotted #777; padding: 0 6px; }
.fb-parent { font-size: 12px; margin-top: 4px; } .fb-parent .dots { border-bottom: 1px dotted #777; height: 18px; }
.doc.land .fb-page .doc-foot .f-name { margin-top: 34px; }

/* Attendance */
.att-tbl th.dh { cursor: pointer; min-width: 34px; font-size: 12px; }
.att-tbl th.wd { font-size: 11px; font-weight: 400; }
.att-tbl th.off, .att-tbl td.off { background: #eceff5; }
.att-tbl td.ac { cursor: pointer; text-align: center; min-width: 34px; height: 34px; }
.att-tbl td.ac:hover { background: #f1f5ff; }
.att-tbl td.tot { text-align: center; font-weight: 600; }
.ab { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #fff; }
.ab.P { background: #e3a21a; } .ab.A { background: #d63b3b; }
.doc .att-dt { font-size: 10px; table-layout: fixed; }
.doc .att-dt th, .doc .att-dt td { padding: 1px; height: 20px; font-size: 10px; }
.doc .att-dt td.l { font-size: 11px; }
.doc .att-dt th:nth-child(3) { width: 130px; } .doc .att-dt th:nth-child(1) { width: 24px; } .doc .att-dt th:nth-child(2) { width: 44px; } .doc .att-dt th:nth-child(4) { width: 24px; }
.doc .att-dt th.vt { height: 64px; vertical-align: bottom; padding: 2px 0; }
.doc .att-dt th.vt span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-size: 9px; }
.doc .att-dt .off { background: #e3e6ec; }
.doc .att-dt td.vlabel { vertical-align: middle; }
.doc .att-dt td.vlabel span { writing-mode: vertical-rl; transform: rotate(180deg); font-family: 'Moul', serif; color: #1f3a93; font-size: 10px; white-space: nowrap; }
.doc .att-dt td.ok { color: #1f9d62; } .doc .att-dt td.pp { color: #b07b14; font-weight: 700; } .doc .att-dt td.aa { color: #c00000; font-weight: 700; }
.doc .att-dt td.sum { font-weight: 700; }

/* Timetable, rules, programme */
.doc .tt td { height: 34px; font-size: 13px; }
.doc .tt td.time { font-family: 'Battambang', serif; white-space: nowrap; color: #0b3c8c; font-weight: 700; }
.doc .tt td.lab { background: #fff6dc; font-family: 'Moul', serif; color: #a8730f; letter-spacing: 1px; }
.tt-notes { margin-top: 10px; font-size: 12.5px; } .tt-notes .cols { columns: 3; margin-top: 4px; }
.rules { font-size: 14.5px; line-height: 2.1; margin: 6px 12px; }
.rules p { text-indent: 36px; margin: 0 0 6px; text-align: justify; }
.rules ol { margin: 0; padding-left: 26px; } .rules li { padding-left: 4px; }
.doc .dt td.subj { font-family: 'Moul', serif; color: #0b3c8c; font-size: 11px; }

/* Cleaning org chart */
.org { display: flex; flex-direction: column; align-items: center; gap: 22px; margin: 8px 0 12px; }
.oc-l2 { display: flex; gap: 60px; position: relative; }
.oc-l1, .oc-l2 { position: relative; }
.oc-l1::after { content: ''; position: absolute; left: 50%; bottom: -22px; height: 22px; border-left: 2px solid #1f3a93; }
.oc-node { display: flex; flex-direction: column; align-items: center; width: 130px; text-align: center; }
.oc-ph { width: 70px; height: 84px; border-radius: 8px; overflow: hidden; background: linear-gradient(160deg, #eef3ff, #d9e3f7); border: 2px solid #1f3a93; display: grid; place-items: center; font-family: 'Moul', serif; font-size: 26px; color: #1f3a93; }
.oc-ph img { width: 100%; height: 100%; object-fit: cover; }
.oc-nm { font-weight: 700; font-size: 12.5px; margin-top: 3px; } .oc-role { font-family: 'Moul', serif; color: #c00000; font-size: 10.5px; }
.oc-groups { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; width: 100%; }
.oc-g { border: 1.5px solid #1f3a93; border-radius: 8px; overflow: hidden; }
.oc-gh { background: #1f3a93; color: #fff; text-align: center; font-family: 'Moul', serif; font-size: 11px; padding: 3px 0; line-height: 1.7; }
.oc-gh small { display: block; font-family: 'Battambang', serif; font-size: 10.5px; color: #ffe08a; }
.oc-m { display: flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 4px; border-top: 1px solid #dfe5f2; white-space: nowrap; overflow: hidden; }
.oc-m .mini { width: 16px; height: 20px; border-radius: 3px; overflow: hidden; background: #eef3ff; flex-shrink: 0; }
.oc-m .mini img { width: 100%; height: 100%; object-fit: cover; }

/* Covers */
.cover-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.cover-card { display: flex; flex-direction: column; gap: 8px; }
.cover-mini { aspect-ratio: 210 / 297; border: 16px solid; border-image-slice: 32; border-image-width: 16px; border-image-repeat: round; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 8px; background: #fff; box-shadow: var(--shadow); }
.cover-mini img { width: 46px; }
.cover-mini b { font-family: 'Moul', serif; font-weight: 400; color: #0b3c8c; font-size: 13px; line-height: 1.8; }
.cover-mini small { color: var(--muted); }
.cover-actions { display: flex; justify-content: center; }
.cover { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10px 6px; }
.cv-king { font-family: 'Moul', serif; color: #0b3c8c; font-size: 16px; line-height: 2.1; align-self: center; }
.cv-king .orn { width: 140px; height: 14px; color: #0b3c8c; display: block; margin: 0 auto; }
.cv-office { font-family: 'Moul', serif; color: #0b3c8c; font-size: 13px; line-height: 2.1; align-self: flex-start; text-align: left; margin-top: 4px; }
.cv-office span { color: #c00000; }
.cv-logo { width: 150px; margin: 34px 0 14px; }
.cv-title { font-family: 'Moul', serif; font-weight: 400; color: #c00000; font-size: 34px; line-height: 1.8; margin: 8px 0 22px; }
.cv-photo { width: 120px; height: 150px; border: 2px solid #0b3c8c; border-radius: 6px; overflow: hidden; margin-bottom: 14px; }
.cv-photo img { width: 100%; height: 100%; object-fit: cover; }
.cv-line { font-size: 16px; line-height: 2.2; color: #17203a; } .cv-line b { font-family: 'Moul', serif; font-weight: 400; color: #0b3c8c; }
.cv-line.big { font-family: 'Moul', serif; color: #0b3c8c; font-size: 22px; margin-top: auto; }
/* podium fits one A4 page */
.podium { gap: 4px; margin: 4px 0 4px; }
.hphoto { width: 100px; height: 122px; font-size: 36px; }
.hslot.first .hphoto { width: 118px; height: 144px; }
.honor-title { font-size: 28px; margin-top: 4px; }
.frame-page .doc-foot .f-name { margin-top: 44px; }
.oc-l2::before { content: ''; position: absolute; top: -12px; left: 65px; right: 65px; border-top: 2px solid #1f3a93; }
.oc-l2 .oc-node { position: relative; }
.oc-l2 .oc-node::before { content: ''; position: absolute; top: -12px; left: 50%; height: 12px; border-left: 2px solid #1f3a93; }
.oc-l1::after { bottom: -10px; height: 10px; }

/* framed pages: exactly one sheet; content is zoomed to fit by Doc.fit() */
.frame-page { height: 276mm; min-height: 0 !important; overflow: hidden; }
.doc.land .frame-page { height: 189mm; }
.frame-in { min-height: 0; }
.frame-in > .doc-foot { margin-top: auto; padding-top: 6px; }
/* landscape podium: one row, winner in the middle */
.doc.land .podium { flex-direction: row; justify-content: center; align-items: flex-end; gap: 18px; margin-top: 8px; }
.doc.land .prow { display: contents; }
.doc.land .hslot { width: 170px; }
.doc.land .hslot.n4 { order: 1; } .doc.land .hslot.n2 { order: 2; } .doc.land .hslot.n1 { order: 3; } .doc.land .hslot.n3 { order: 4; } .doc.land .hslot.n5 { order: 5; }
.doc.land .hslot.n1 { margin-bottom: 26px; }
.doc.land .ribbon { width: 190px; }
.doc.land .honor-title { font-size: 26px; margin-top: 0; }

/* Cleaning roster v2 (org chart with photos) */
.org2 { border: 1.5px solid #c9a646; background: linear-gradient(180deg, #f3f8ff, #eaf2fd); border-radius: 6px; padding: 12px 10px 14px; margin: 6px 0 10px; }
.o2-top { display: flex; justify-content: center; position: relative; padding-bottom: 18px; }
.o2-top::after { content: ''; position: absolute; bottom: 0; left: 50%; height: 18px; border-left: 1.5px solid #4a6fa8; }
.o2-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; position: relative; padding-top: 16px; }
.o2-cols::before { content: ''; position: absolute; top: 0; left: 16.66%; right: 16.66%; border-top: 1.5px solid #4a6fa8; }
.o2-col { display: flex; flex-direction: column; align-items: center; position: relative; }
.o2-col::before { content: ''; position: absolute; top: -16px; left: 50%; height: 16px; border-left: 1.5px solid #4a6fa8; }
.o2-node { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.o2-av { width: 22px; height: 22px; border-radius: 50%; overflow: hidden; background: #fff; border: 1.5px solid #4a6fa8; display: grid; place-items: center; flex-shrink: 0; font-family: 'Moul', serif; font-size: 10px; color: #1f3a93; }
.o2-av.big { width: 58px; height: 58px; font-size: 22px; border: 2px solid #1f3a93; box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px #c9a646; }
.o2-av img { width: 100%; height: 100%; object-fit: cover; }
.o2-nm { font-family: 'Battambang', serif; font-weight: 700; color: #0b3c8c; font-size: 12.5px; margin-top: 3px; }
.o2-pill { background: linear-gradient(180deg, #ffe58a, #f5c84a); border: 1.2px solid #c9952f; border-radius: 99px; padding: 1px 16px; font-family: 'Moul', serif; color: #7a2c10; font-size: 10.5px; line-height: 1.9; white-space: nowrap; }
.o2-pill.g { border-radius: 10px; padding: 2px 6px; text-align: center; color: #0b3c8c; width: 100%; line-height: 1.6; }
.o2-pill.g small { display: block; font-family: 'Battambang', serif; font-size: 10px; color: #7a2c10; }
.o2-gs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; margin-top: 12px; position: relative; }
.o2-gs::before { content: ''; position: absolute; top: -12px; left: 25%; right: 25%; height: 6px; border: 1.5px solid #4a6fa8; border-bottom: 0; }
.o2-g { display: flex; flex-direction: column; gap: 4px; }
.o2-list { background: #fffbe8; border: 1.2px solid #e2c56a; border-radius: 8px; padding: 3px 4px; min-height: 40px; }
.o2-m { display: flex; align-items: center; gap: 4px; font-size: 11px; padding: 3px 0; border-bottom: 1px dashed #ecd99a; white-space: nowrap; overflow: hidden; }
.o2-m:last-child { border-bottom: 0; }
.o2-m span { overflow: hidden; text-overflow: ellipsis; }
.o2-m.empty { justify-content: center; color: #aaa; }

/* Border picker */
.bp-wrap .border-picks { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.bp-wrap .bpick span { border: 0; width: 60px; height: 60px; background: #fff; }
.bp-wrap.compact .border-picks { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.bp-wrap.compact .bpick { padding: 6px 4px; font-size: 11.5px; border-radius: 10px; }
.bp-wrap.compact .bpick span { width: 40px; height: 40px; }
.bc-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.bchip { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; cursor: pointer; background: linear-gradient(135deg, var(--c1) 55%, var(--c2) 55%); box-shadow: 0 0 0 1px #cfd6e4; }
.bchip.on { box-shadow: 0 0 0 3px var(--gold); }
.cover-mini { border: 0; }

/* ================= v5: accounts, dashboard, certificates, mobile ================= */
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
a.avatar { text-decoration: none; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.hint { color: var(--muted); font-size: 13.5px; }
.btn-lg { padding: 11px 18px; font-size: 15.5px; border-radius: 12px; }
.btn-navy { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }
.btn-navy:hover { background: var(--navy-700); border-color: var(--navy-700); }
a.btn { text-decoration: none; }

/* sign in / sign up */
.auth-tabs { display: flex; width: 100%; margin-bottom: 14px; }
.auth-tabs button { flex: 1; padding: 9px; font-size: 15px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 44px; width: 100%; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; padding: 8px; color: var(--muted); cursor: pointer; }
.pw-eye svg { width: 20px; height: 20px; display: block; }
.auth-card .pw-eye { width: auto; }
.auth-ok { text-align: center; padding: 6px 0; }
.auth-ok svg { width: 56px; height: 56px; color: var(--green); }
.auth-ok h3 { margin: 6px 0; color: var(--navy-800); }
.auth-ok p { color: var(--muted); margin: 0 0 14px; font-size: 14.5px; line-height: 1.7; }

/* dashboard */
.dash { display: flex; flex-direction: column; gap: 16px; max-width: 1100px; margin: 0 auto; }
.school-banner { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: 18px; color: #fff;
  background: radial-gradient(120% 140% at 0% 0%, #2a4cc7 0%, var(--navy-800) 55%, var(--navy-900) 100%); box-shadow: 0 8px 26px rgba(16, 36, 102, .25); position: relative; overflow: hidden; }
.school-banner::after { content: ''; position: absolute; right: -40px; bottom: -60px; width: 220px; height: 160px; border-radius: 50%; border-top: 3px solid var(--gold); opacity: .55; transform: rotate(-12deg); }
.school-banner img { width: 58px; height: 58px; object-fit: contain; flex-shrink: 0; background: #fff; border-radius: 50%; padding: 4px; }
.school-banner .sb-logo.tm { border-radius: 14px; padding: 0; object-fit: cover; }
.sb-text { flex: 1; min-width: 0; text-align: center; font-family: 'Moul', serif; font-size: 13.5px; line-height: 1.9; }
.sb-text .sb-2 { color: #d6defa; font-size: 12.5px; }
.sb-text .sb-3 { color: var(--gold); font-size: 15.5px; }
.prof-card { text-align: center; padding: 26px 18px 22px; }
.prof-ph { width: 132px; height: 132px; margin: 0 auto 12px; border-radius: 50%; padding: 5px; background: linear-gradient(135deg, #f8dc85, var(--gold-600) 55%, #fbe7a6); box-shadow: 0 8px 22px rgba(201, 149, 47, .35); }
.prof-ph img, .prof-ph span { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: #fff; border: 3px solid #fff; font-size: 46px; font-weight: 700; color: var(--navy-800); }
.prof-card h2 { margin: 0; font-family: 'Moul', serif; font-weight: 400; font-size: 21px; color: var(--navy-800); line-height: 1.8; }
.prof-role { color: var(--blue); font-weight: 600; margin-top: 2px; }
.prof-card .chips { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.prof-card .chip { display: inline-flex; align-items: center; gap: 6px; background: var(--blue-50); border-color: #dbe5ff; color: var(--navy-700); border-radius: 99px; padding: 6px 14px; }
.prof-card .chip svg { width: 16px; height: 16px; }
.prof-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 460px; margin: 0 auto; }
.prof-actions .btn { justify-content: center; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpis.mini { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
.kpi { --k: var(--blue); --kb: var(--blue-50); background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; min-height: 112px; }
.kpis.mini .kpi { min-height: 0; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--k); }
.kpi.k-green { --k: #1f9d62; --kb: #e6f6ee; } .kpi.k-teal { --k: #0d9488; --kb: #e0f5f2; } .kpi.k-red { --k: #d63b3b; --kb: #fdecec; }
.k-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 14px; }
.k-top svg { width: 34px; height: 34px; padding: 7px; border-radius: 10px; background: var(--kb); color: var(--k); flex-shrink: 0; }
.kpi b { font-size: 30px; color: var(--k); line-height: 1.2; }
.kpi small { color: var(--muted); margin-left: 4px; }
.k-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.k-sub em { font-style: normal; color: var(--k); font-weight: 700; }
.kpi.skel { background: linear-gradient(90deg, #eef1f8 0%, #f7f9fd 50%, #eef1f8 100%); background-size: 200% 100%; animation: skel 1.2s infinite linear; }
.kpi.skel::before { display: none; }
@keyframes skel { to { background-position: -200% 0; } }
.admin-strip { display: flex; flex-direction: column; gap: 10px; }
.pend { display: flex; align-items: center; gap: 8px; background: #fff4e5; color: #9a5b00; border-radius: 12px; padding: 10px 14px; text-decoration: none; font-weight: 600; }
.pend svg, .online b svg { width: 18px; height: 18px; vertical-align: -3px; }
.online { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.online b { color: var(--navy-800); }
.on-list { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.on-u { display: inline-flex; align-items: center; gap: 6px; background: #e6f6ee; color: #0f6b40; border-radius: 99px; padding: 3px 10px 3px 3px; font-size: 13.5px; }
.online a.hint { text-decoration: none; }

/* today's attendance */
.att-today { padding: 16px 18px; }
.at-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.at-head h3 { margin: 0; color: var(--navy-800); font-size: 18px; }
.at-done { margin-left: auto; font-size: 13.5px; color: var(--muted); }
.at-off { margin-top: 10px; background: var(--gold-50); color: #7a5410; padding: 8px 12px; border-radius: 10px; font-size: 14px; display: flex; gap: 6px; align-items: center; }
.at-off svg { width: 16px; height: 16px; }
.at-bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: #eef1f8; margin: 12px 0; }
.at-bar span { background: #1f9d62; } .at-bar .p { background: #e3a21a; } .at-bar .a { background: #d63b3b; }
.at-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.atf { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 14px; cursor: pointer; font-size: 14px; color: var(--muted); }
.atf b { margin-left: 4px; }
.atf.on { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.atf-ok.on { background: #1f9d62; border-color: #1f9d62; } .atf-P.on { background: #e3a21a; border-color: #e3a21a; } .atf-A.on { background: #d63b3b; border-color: #d63b3b; }
.at-list { display: flex; flex-direction: column; max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.at-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.at-row:last-child { border-bottom: 0; }
.at-no { width: 22px; text-align: center; color: var(--muted); font-size: 13px; flex-shrink: 0; }
.at-nm { flex: 1; min-width: 0; font-weight: 600; color: var(--navy-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.at-nm small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }
.at-btns { display: flex; gap: 4px; flex-shrink: 0; }
.at-btns button { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 6px 10px; min-width: 50px; cursor: pointer; font-size: 13.5px; color: var(--muted); }
.at-btns .ok.on { background: #1f9d62; border-color: #1f9d62; color: #fff; }
.at-btns .p.on { background: #e3a21a; border-color: #e3a21a; color: #fff; }
.at-btns .a.on { background: #d63b3b; border-color: #d63b3b; color: #fff; }
.at-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.at-foot .btn { justify-content: center; padding: 11px; }

/* users list */
.ulist { display: flex; flex-direction: column; }
.urow { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.urow:last-child { border-bottom: 0; }
.urow.pending { background: #fffaf0; }
.urow > .avatar { width: 44px; height: 44px; }
.u-main { flex: 1; min-width: 0; }
.u-main b { color: var(--navy-800); }
.u-main small { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-badges { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.u-time { text-align: right; font-size: 13.5px; color: var(--navy-800); white-space: nowrap; }
.u-time small { display: block; color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #c3cbe0; margin-right: 6px; vertical-align: 1px; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.urow .row-actions { display: flex; gap: 6px; }

/* profile editor */
.prof-photo { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.prof-photo .pp { width: 84px; height: 84px; border-radius: 50%; overflow: hidden; background: var(--gold); display: grid; place-items: center; font-size: 30px; font-weight: 700; color: var(--navy-900); border: 3px solid var(--gold-50); }
.prof-photo .pp img { width: 100%; height: 100%; object-fit: cover; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch input { display: none; }
.switch span { width: 46px; height: 26px; border-radius: 99px; background: #cfd6e4; position: relative; transition: background .2s; flex-shrink: 0; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- certificates ---------- */
.modal.xl { max-width: 1180px; }
.cert-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.cert-card { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.cert-thumb { width: 100%; overflow: hidden; position: relative; border-radius: 8px; background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, .12); }
.cp-scale { width: 279mm; transform-origin: 0 0; position: absolute; left: 0; top: 0; pointer-events: none; }
.cp-scale .doc { background: #fff; }
.cc-info b { display: block; color: var(--navy-800); font-family: 'Moul', serif; font-weight: 400; font-size: 14px; line-height: 1.9; }
.cc-info small { color: var(--muted); }
.cc-act { display: flex; gap: 6px; flex-wrap: wrap; }
.cc-act .btn-danger { margin-left: auto; }
.cert-empty svg { color: var(--gold-600); }
.cert-edit { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.ce-prev { position: sticky; top: 0; }
.ce-photo { display: flex; gap: 6px; flex-wrap: wrap; }
.ce-form textarea { min-height: 0; }

.cert { position: relative; isolation: isolate; display: flex; flex-direction: column; height: 100%; font-family: 'Khmer OS Battambang', 'Battambang', serif; color: #1a1a1a; text-align: center; }
.cert .ct-top { display: grid; grid-template-columns: 30mm 1fr 30mm; align-items: start; }
.cert .ct-logo { height: 27mm; display: flex; justify-content: flex-start; align-items: flex-start; }
.cert .ct-logo.r { justify-content: flex-end; }
.cert .ct-logo img { max-height: 25mm; max-width: 28mm; object-fit: contain; }
.cert .ct-logo .medal { width: 23mm; height: 30mm; margin-top: -2mm; }
.cert .ct-king { font-family: 'Khmer OS Muol Light', 'Moul', serif; color: #0f2668; font-size: 15px; line-height: 2; }
.cert .ct-king .orn { width: 140px; height: 13px; color: #a8730f; display: block; margin: 0 auto; }
.cert .ct-title { font-family: 'Khmer OS Muol Light', 'Moul', serif; font-weight: 400; color: #0f2668; font-size: 40px; margin: -4mm 0 0; line-height: 1.6; letter-spacing: 1px; text-shadow: 0 1px 0 #fff, 0 2px 0 rgba(168, 115, 15, .35); }
.cert .ct-issuer { font-family: 'Khmer OS Muol Light', 'Moul', serif; color: #0f2668; font-size: 15.5px; line-height: 1.9; }
.cert .ct-praise { color: #c00000; font-weight: 700; font-size: 16.5px; margin-top: 1mm; }
.cert .ct-name { font-family: 'Khmer OS Muol Light', 'Moul', serif; font-size: 34px; line-height: 1.75; margin: 1mm 0 0; color: #b8860b; text-shadow: 0 1px 0 #f6e3a1, 0 2px 1px rgba(122, 75, 0, .35); }
.cert .ct-line { font-size: 15.5px; line-height: 2; padding: 0 8mm; }
.cert .ct-line b { color: #0f2668; }
.cert .ct-bottom { margin-top: auto; display: grid; grid-template-columns: 1fr 27mm 1fr; gap: 8mm; align-items: end; padding: 2mm 4mm 0; }
.cert .ct-sign { font-size: 13.5px; line-height: 1.85; }
.cert .ct-sign .f-role { font-family: 'Khmer OS Muol Light', 'Moul', serif; color: #0f2668; font-size: 13.5px; line-height: 2; }
.cert .ct-sign .f-name { font-family: 'Khmer OS Muol Light', 'Moul', serif; color: #0f2668; font-size: 13.5px; margin-top: 17mm; min-height: 20px; }
.cert .ct-date { font-size: 13px; }
.cert .ct-photo { width: 26mm; height: 39mm; border: 1.5px solid #a8730f; padding: 1mm; background: #fff; display: grid; place-items: center; box-shadow: 0 0 0 1mm #fff, 0 0 0 calc(1mm + 1px) #e0b752; margin-bottom: 1mm; }
.cert .ct-photo img { width: 100%; height: 100%; object-fit: cover; }
.cert .ct-photo span { color: #a0a8bd; font-size: 11px; line-height: 1.8; }

/* ---------- phones ---------- */
@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cert-edit { grid-template-columns: 1fr; }
  .ce-prev { position: static; }
  .modal-bg { padding: 0; place-items: end center; }
  .modal { max-height: 94vh; border-radius: 18px 18px 0 0; }
  .modal-foot { flex-wrap: wrap; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .page-head { flex-wrap: wrap; }
  .page-head .actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .input, select.input, textarea.input { font-size: 16px; } /* stop iOS zoom on focus */
}
@media (max-width: 520px) {
  .main { padding: 12px 10px 28px; }
  .school-banner { padding: 12px; gap: 8px; border-radius: 14px; }
  .school-banner img { width: 44px; height: 44px; }
  .sb-text { font-size: 11px; } .sb-text .sb-2 { font-size: 10.5px; } .sb-text .sb-3 { font-size: 13px; }
  .prof-ph { width: 112px; height: 112px; }
  .prof-card h2 { font-size: 18px; }
  .kpi { padding: 12px; min-height: 100px; }
  .kpi b { font-size: 25px; }
  .k-top { font-size: 13px; }
  .k-top svg { width: 30px; height: 30px; padding: 6px; }
  .kpis.mini { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .kpis.mini .kpi b { font-size: 22px; }
  .kpis.mini .k-top svg { display: none; }
  .att-today { padding: 12px; }
  .at-row { gap: 8px; padding: 8px; }
  .at-row .avatar { display: none; }
  .at-btns button { min-width: 0; padding: 6px 8px; }
  .urow { flex-wrap: wrap; padding: 12px; row-gap: 8px; }
  .u-main { flex: 1 1 calc(100% - 60px); }
  .u-time { text-align: left; order: 3; flex: 1; }
  .urow .row-actions { order: 4; }
  .cert-grid { grid-template-columns: 1fr; }
  .modal-body { padding: 14px; }
  .toolbar { padding: 10px; }
  .btn { padding: 8px 12px; }
}
@media (max-width: 360px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .prof-actions { grid-template-columns: 1fr; }
  .at-foot { grid-template-columns: 1fr; }
}

/* picture frames (scanned Khmer ornaments); content is kept inside the inner rectangle */
.frame-page.imgf { border: 0 !important; border-image: none !important; background: var(--fp) center / 100% 100% no-repeat;
  padding: calc(var(--pt) * 276mm + 3mm) calc(var(--pr) * 192mm + 3mm) calc(var(--pb) * 276mm + 3mm) calc(var(--pl) * 192mm + 3mm);
  -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.doc.land .frame-page.imgf { background-image: var(--fl);
  padding: calc(var(--lt) * 189mm + 3mm) calc(var(--lr) * 279mm + 3mm) calc(var(--lb) * 189mm + 3mm) calc(var(--ll) * 279mm + 3mm); }
.bp-sub { font-size: 13.5px; color: var(--muted); font-weight: 600; margin: 12px 0 8px; }
.border-picks.imgs { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.border-picks.imgs .bpick span { width: 100%; height: 66px; border: 0; background: #fff center / contain no-repeat; }
.bp-wrap.compact .border-picks.imgs { grid-template-columns: repeat(3, 1fr); }
.bp-wrap.compact .border-picks.imgs .bpick span { width: 100%; height: 46px; }
.orn-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.opick { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 8px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; color: #a8730f; }
.opick img, .opick svg { height: 22px; max-width: 100%; object-fit: contain; }
.opick small { color: var(--muted); }
.opick.on { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-50); }
.orn.orn-img { height: auto !important; width: 150px !important; display: block; margin: 1px auto 0; }
.orn.orn-img.orn-flower { width: 92px !important; }
/* honor roll titles */
.honor-big { font-family: 'Khmer OS Muol Light', 'Moul', serif; font-weight: 400; text-align: center; font-size: 44px; line-height: 1.55; margin: 0;
  color: #f9c08f; -webkit-text-stroke: 1.2px #e2731b; text-shadow: 0 2px 0 rgba(226, 115, 27, .18); letter-spacing: 1px; }
.honor-res { font-family: 'Khmer OS Muol Light', 'Moul', serif; text-align: center; color: #0f2668; font-size: 24px; line-height: 1.7; margin-top: -4px; }
.honor-res span { color: #e2731b; }
.doc.land .honor-big { font-size: 36px; }
.doc.land .honor-res { font-size: 20px; }

/* faded logo watermark behind certificate text */
.cert .ct-wm { position: absolute; z-index: -1; left: 50%; top: 54%; transform: translate(-50%, -50%); width: 92mm; height: 92mm; object-fit: contain; opacity: .13; pointer-events: none; }

/* ===================== v7: premium icons, image/Word export ===================== */
svg.ph { stroke: none; }
.nav a .ni { position: relative; overflow: hidden; width: 34px; height: 34px; border-radius: 11px;
  background: radial-gradient(120% 90% at 30% 15%, rgba(255,255,255,.38), transparent 55%), linear-gradient(150deg, var(--g1), var(--g2));
  box-shadow: 0 4px 10px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.45), inset 0 -2px 0 rgba(0,0,0,.12); }
.nav a .ni svg { width: 20px; height: 20px; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.35)); }
.nav a:hover .ni { transform: translateY(-1px); transition: transform .15s; }
.btn svg.ph { width: 18px; height: 18px; }
.img-stage { position: fixed; left: -20000px; top: 0; pointer-events: none; background: #fff; }
.img-stage .doc.img-pad { padding: 9mm; background: #fff; box-sizing: border-box; }
.img-out { display: grid; gap: 10px; max-height: 55vh; overflow: auto; }
.img-out img { width: 100%; border-radius: 8px; box-shadow: 0 1px 8px rgba(0,0,0,.15); background: #fff; -webkit-touch-callout: default; }
.file-out { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 12px; background: #eef3ff; color: var(--navy-800); word-break: break-all; }
.file-out svg { width: 40px; height: 40px; flex-shrink: 0; color: #2b579a; }
.cc-act { flex-wrap: wrap; }
.cc-act { gap: 5px; }
.cc-act .btn-sm { padding: 5px 8px; gap: 4px; font-size: 13.5px; }
.cc-act .btn-danger { margin-left: auto; }

/* ===================== v8: 4×6 photo maker ===================== */
.idp { display: grid; grid-template-columns: minmax(260px, 380px) minmax(0, 1fr); gap: 18px; align-items: start; }
.idp-left { padding: 16px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 12px; }
.idp-frame { position: relative; width: 100%; aspect-ratio: 4 / 6; border-radius: 10px; overflow: hidden; background: #eef2f8; box-shadow: inset 0 0 0 1px #dfe5ef; }
.idp-frame canvas { width: 100%; height: 100%; display: block; }
.idp-drop, .idp-busy { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 20px; background: rgba(255,255,255,.9); cursor: pointer; color: var(--navy-800); }
.idp-drop[hidden], .idp-busy[hidden] { display: none; }
.idp-drop svg { width: 54px; height: 54px; color: var(--blue); }
.idp-drop small, .idp-busy small { color: var(--muted); font-size: 13px; }
.idp-busy { cursor: default; }
.spin { width: 38px; height: 38px; border-radius: 50%; border: 4px solid #d6e2fb; border-top-color: var(--blue); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.idp-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.idp-acts .btn { justify-content: center; }
.idp-note { display: flex; gap: 6px; align-items: flex-start; margin: 0; font-size: 12.5px; }
.idp-note svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }
.idp-right { display: flex; flex-direction: column; gap: 18px; }
.idp-sec { display: flex; flex-direction: column; gap: 10px; }
.idp-sec > b { color: var(--navy-800); }
.idp-cats { flex-wrap: wrap; }
.idp-tpls { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.idp-tpls button { border: 2px solid #e3e8f2; border-radius: 10px; background: #4d82dc; padding: 4px; cursor: pointer; aspect-ratio: 1; display: grid; place-items: center; }
.idp-tpls button img { max-width: 100%; max-height: 100%; }
.idp-tpls button.on { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(227,176,75,.35); }
.idp-bgs { display: flex; flex-wrap: wrap; gap: 10px; }
.idp-bgs button, .idp-bgc { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); font-size: 12px; }
.idp-bgs i { width: 38px; height: 38px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); display: block; }
.idp-bgs button.on i { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--gold); }
.idp-bgc input { width: 38px; height: 38px; border: 0; padding: 0; border-radius: 50%; overflow: hidden; background: none; cursor: pointer; }
.idp-sl { display: grid; grid-template-columns: 130px 1fr; align-items: center; gap: 10px; font-size: 14px; }
.idp-sl input { width: 100%; accent-color: var(--blue); }
.idp-chk { display: flex; gap: 8px; align-items: center; font-size: 14px; }
#idp-reset { align-self: flex-start; }
.idp-sheet { display: grid; grid-template-columns: repeat(4, 40mm); grid-auto-rows: 60mm; gap: 6mm 6mm; justify-content: center; padding-top: 4mm; }
.idp-sheet img { width: 40mm; height: 60mm; outline: 0.2mm dashed #9aa4b5; outline-offset: 1.5mm; }
@media (max-width: 820px) {
  .idp { grid-template-columns: 1fr; }
  .idp-left { position: static; }
  .idp-frame { max-width: 300px; margin: 0 auto; }
  .idp-sl { grid-template-columns: 105px 1fr; font-size: 13px; }
}

/* ---- certificate layouts ---- */
.cert.nophoto .ct-bottom { grid-template-columns: 1fr 10mm 1fr; }
.cert.off { text-align: left; }
.cert.off .co-top { display: grid; grid-template-columns: 1fr 1.1fr 1fr; align-items: start; }
.cert.off .co-office { font-family: 'Khmer OS Muol Light', 'Moul', serif; color: #0f2668; font-size: 13px; line-height: 1.95; padding-top: 14mm; text-align: center; justify-self: start; }
.cert.off .co-office .sch { color: #b3121f; }
.cert.off .co-office .no { font-family: 'Khmer OS Battambang', 'Battambang', serif; color: #1a1a1a; font-size: 13px; text-align: left; }
.cert.off .ct-king { text-align: center; }
.cert.off .ct-logo.r { justify-content: flex-end; }
.cert.off .co-title { text-align: center; margin: 3mm auto 1mm; padding: 0 14mm; border-top: 1px solid #0f2668; border-bottom: 1px solid #0f2668; width: max-content; line-height: 1.6; font-size: 40px; }
.cert.off .co-refs { font-size: 14.5px; line-height: 1.9; padding: 1.5mm 6mm 0 30mm; text-indent: -10mm; }
.cert.off .co-issuer { font-family: 'Khmer OS Muol Light', 'Moul', serif; color: #0f2668; font-size: 18px; text-align: center; line-height: 2.1; margin-top: 2mm; }
.cert.off .co-body { font-size: 17px; line-height: 2.2; text-indent: 12mm; text-align: justify; margin: 0; padding: 0 4mm; }
.cert.off .co-body b { color: #0f2668; }
.cert.off .co-body .nm { font-family: 'Khmer OS Muol Light', 'Moul', serif; font-weight: 400; color: #1f3fbf; font-size: 19px; }
.cert.off .co-bottom { margin-top: auto; display: grid; grid-template-columns: 1fr 27mm 1fr; gap: 8mm; align-items: end; padding: 2mm 4mm 0; }
.cert.off .co-left { font-size: 12.5px; align-self: start; padding-top: 2mm; color: #444; }
.cert.off .ct-sign { text-align: center; }
.ctpl-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.ctpl-picks button { border: 1.5px solid #dfe5ef; background: #fff; border-radius: 10px; padding: 8px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; font: inherit; }
.ctpl-picks button.on { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(227,176,75,.3); }
.ctpl-picks b { font-size: 13px; color: var(--navy-800); }
.ctpl-picks small { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.4; }
.ctpl-ic { position: relative; width: 64px; height: 44px; border: 2px solid #c9a23f; border-radius: 3px; display: block; background: #fffdf6; }
.ctpl-ic s { position: absolute; left: 14px; right: 14px; height: 3px; background: #9aa6c4; border-radius: 2px; }
.ctpl-ic s:nth-child(1) { top: 7px; left: 20px; right: 20px; background: #0f2668; height: 4px; }
.ctpl-ic s:nth-child(2) { top: 16px; } .ctpl-ic s:nth-child(3) { top: 22px; }
.ctpl-ic u { position: absolute; left: 28px; bottom: 4px; width: 8px; height: 12px; border: 1px solid #a8730f; background: #eef2f8; }
.ctpl-ic.o1::before, .ctpl-ic.o2::before, .ctpl-ic.o3::before, .ctpl-ic.o4::before { content: ''; position: absolute; left: 4px; top: 5px; width: 10px; height: 8px; border-top: 2px solid #0f2668; border-bottom: 2px solid #0f2668; }
.ctpl-ic.o2 s:nth-child(2), .ctpl-ic.o4 s:nth-child(2) { background: #c9a23f; }

/* v8: Google sign-in */
.auth-or { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; color: var(--muted); font-size: 13px; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.g-btn { display: flex; justify-content: center; min-height: 44px; }
.g-h { margin: 0 0 6px; color: var(--navy-800); display: flex; align-items: center; gap: 8px; }
.g-badge { display: inline-flex; align-items: center; gap: 4px; }
.g-badge svg { width: 12px; height: 12px; }

/* v8.1: "no border" choice */
.bpick.bnone span { border: 2px dashed #b8c2d6 !important; background: #fff linear-gradient(to top right, transparent calc(50% - 1px), #e2556b calc(50% - 1px), #e2556b calc(50% + 1px), transparent calc(50% + 1px)) !important; box-sizing: border-box; }
.frame-page.nofr { border: 0 !important; border-image: none !important; background: #fff; padding: 9mm 12mm; }

/* v8.1: AI finishing for the 4x6 photo */
.idp-ai { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.idp .btn.btn-ai, .btn.btn-ai { background: linear-gradient(135deg, #7c3aed, #2563eb 55%, #0ea5e9); color: #fff; border: 0; font-weight: 700; justify-content: center; box-shadow: 0 6px 18px rgba(79, 70, 229, .3); }
.idp .btn.btn-ai:disabled { opacity: .55; }
.idp-aibar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13.5px; color: #4338ca; }
.idp-aibar span { display: inline-flex; gap: 4px; align-items: center; font-weight: 700; }
.idp-aibar svg { width: 16px; height: 16px; }
.spin.sm { width: 16px; height: 16px; border-width: 2px; display: inline-block; vertical-align: middle; }
.idp-aibar[hidden] { display: none; }
.gem-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.gem-steps li { line-height: 1.6; }
.gem-steps textarea { margin-top: 6px; font-size: 12.5px; font-family: ui-monospace, monospace; }
.idp-ai #idp-load { justify-content: center; }
.idp .btn.idp-paid { background: none; border: 0; color: var(--muted); font-size: 12.5px; text-decoration: underline; box-shadow: none; }
