/* IPCS Global Attendance — mobile-first stylesheet (light/dark via CSS variables). */
:root {
  --primary: #0b5cab;
  --primary-ink: #ffffff;
  --primary-soft: #e6f0fa;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #17202c;
  --muted: #5b6676;
  --border: #d8dee8;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --success: #1b7f3b;
  --success-soft: #e7f5ec;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --info-soft: #e8f1fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --radius: 12px;
  --tap: 44px;
  --st-P: #1b7f3b; --st-L: #b26a00; --st-E: #c25400; --st-LE: #a33b00;
  --st-A: #c62828; --st-NC: #6a3fb5; --st-LV: #1565c0; --st-H: #607080;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #5aa2ea; --primary-ink: #06121f; --primary-soft: #16283d;
    --bg: #0e131a; --surface: #161d27; --surface-2: #1d2633; --text: #e7ecf3; --muted: #9aa6b6; --border: #2c3747;
    --danger: #ff6b6b; --danger-soft: #3a1c1f; --success: #4cc27a; --success-soft: #16301f; --warn: #f0b44c; --warn-soft: #33290f;
    --info-soft: #172a42; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --st-P: #4cc27a; --st-L: #f0b44c; --st-E: #ff9c52; --st-LE: #ff7a3d; --st-A: #ff6b6b; --st-NC: #b18cf0; --st-LV: #6fb0ff; --st-H: #9aa6b6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --primary: #5aa2ea; --primary-ink: #06121f; --primary-soft: #16283d;
  --bg: #0e131a; --surface: #161d27; --surface-2: #1d2633; --text: #e7ecf3; --muted: #9aa6b6; --border: #2c3747;
  --danger: #ff6b6b; --danger-soft: #3a1c1f; --success: #4cc27a; --success-soft: #16301f; --warn: #f0b44c; --warn-soft: #33290f;
  --info-soft: #172a42; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --st-P: #4cc27a; --st-L: #f0b44c; --st-E: #ff9c52; --st-LE: #ff7a3d; --st-A: #ff6b6b; --st-NC: #b18cf0; --st-LV: #6fb0ff; --st-H: #9aa6b6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .5rem;
  padding: .5rem 1rem; background: var(--primary); color: var(--primary-ink); min-height: 56px;
}
.topbar .brand { font-weight: 700; letter-spacing: .2px; text-decoration: none; color: inherit; display: flex; align-items: center; gap: .5rem; }
.topbar .brand img { width: 28px; height: 28px; border-radius: 6px; }
.topbar .brand span { white-space: nowrap; }
.topbar .spacer { flex: 1; }
@media (max-width: 420px) { .topbar .who { display: none; } .topbar { padding: .5rem .5rem .5rem .75rem; } }
.topbar .who { font-size: .85rem; opacity: .9; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 10px; background: transparent;
  color: inherit; font-size: 1.1rem; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .15); }
.nav { display: flex; gap: .25rem; overflow-x: auto; padding: .4rem .75rem; background: var(--surface); border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.nav a {
  flex: 0 0 auto; padding: .55rem .8rem; border-radius: 999px; text-decoration: none; color: var(--text);
  font-size: .92rem; min-height: 40px; display: inline-flex; align-items: center;
}
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.narrow { max-width: 480px; }
.page-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

@media (min-width: 960px) {
  body.has-side { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; }
  body.has-side .topbar { grid-column: 1 / -1; }
  body.has-side .nav { flex-direction: column; overflow: visible; border-bottom: 0; border-right: 1px solid var(--border); padding: .75rem; min-height: calc(100vh - 56px); }
  body.has-side .nav a { border-radius: 8px; }
  body.has-side main { min-width: 0; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-sm { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: .75rem; }
.stat { background: var(--surface-2); border-radius: 10px; padding: .75rem; }
.stat .v { font-size: 1.6rem; font-weight: 700; }
.stat .k { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: var(--tap);
  padding: .5rem 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 34px; padding: .25rem .65rem; font-size: .88rem; }
.btn-block { width: 100%; }
.btn-xl { min-height: 72px; font-size: 1.3rem; border-radius: 16px; width: 100%; }
.btn .spin { width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: .25rem; }
.field { margin-bottom: .85rem; }
.field .hint { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; margin-right: .4rem; transform: scale(1.2); }
.check { display: flex; align-items: center; font-weight: 500; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.filters { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; margin-bottom: 1rem; }
.filters .field { margin: 0; }

.toggle { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 1rem; }
.toggle button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: .6rem .9rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--text); border-color: var(--border); }
.empty { text-align: center; color: var(--muted); padding: 1.5rem .5rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.badge .l { display: inline-grid; place-items: center; min-width: 1.4em; height: 1.4em; border-radius: 4px; color: #fff; font-size: .72rem; padding: 0 .2em; }
.st-P .l { background: var(--st-P); } .st-L .l { background: var(--st-L); } .st-E .l { background: var(--st-E); } .st-LE .l { background: var(--st-LE); }
.st-A .l { background: var(--st-A); } .st-NC .l { background: var(--st-NC); } .st-LV .l { background: var(--st-LV); } .st-H .l { background: var(--st-H); }
.pill-ok { background: var(--success-soft); color: var(--success); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--danger-soft); color: var(--danger); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .55rem .65rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td:first-child { white-space: nowrap; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

/* check-in hero */
.hero { text-align: center; }
.hero .state { font-size: .95rem; color: var(--muted); margin: .5rem 0; }
.class-card { border-left: 4px solid var(--primary); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .75rem; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }

/* calendar */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar .dow { text-align: center; font-size: .75rem; color: var(--muted); font-weight: 700; }
.calendar .day { min-height: 54px; border-radius: 8px; background: var(--surface-2); padding: 4px; font-size: .78rem; display: flex; flex-direction: column; justify-content: space-between; }
.calendar .day.blank { background: transparent; }
.calendar .day.today { outline: 2px solid var(--primary); }
.calendar .day .code { align-self: flex-end; font-weight: 800; color: #fff; border-radius: 4px; padding: 0 .3em; }
.calendar .st-P .code { background: var(--st-P); } .calendar .st-L .code { background: var(--st-L); } .calendar .st-E .code { background: var(--st-E); }
.calendar .st-LE .code { background: var(--st-LE); } .calendar .st-A .code { background: var(--st-A); } .calendar .st-NC .code { background: var(--st-NC); }
.calendar .st-LV .code { background: var(--st-LV); } .calendar .st-H .code { background: var(--st-H); }

/* register grid */
.grid-table td, .grid-table th { padding: .3rem .35rem; text-align: center; font-size: .8rem; }
.grid-table td:nth-child(-n+2), .grid-table th:nth-child(-n+2) { text-align: left; white-space: nowrap; }
.grid-table .off { background: var(--surface-2); color: var(--muted); }
.grid-table .c-P { color: var(--st-P); font-weight: 800; } .grid-table .c-L { color: var(--st-L); font-weight: 800; }
.grid-table .c-E, .grid-table .c-LE { color: var(--st-E); font-weight: 800; } .grid-table .c-A { color: var(--st-A); font-weight: 800; }
.grid-table .c-NC { color: var(--st-NC); font-weight: 800; } .grid-table .c-LV { color: var(--st-LV); font-weight: 800; } .grid-table .c-H { color: var(--st-H); font-weight: 800; }

/* toast / loading / dialog */
.loading-bar { position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 100; background: linear-gradient(90deg, transparent, #ffd54f, transparent); background-size: 50% 100%; animation: load 1s linear infinite; }
@keyframes load { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: .5rem; width: min(92vw, 420px); }
.toast { padding: .75rem 1rem; border-radius: 10px; background: #1f2937; color: #fff; box-shadow: var(--shadow); font-size: .95rem; }
.toast.error { background: var(--danger); } .toast.success { background: var(--success); }
dialog { border: 0; border-radius: 14px; padding: 0; width: min(94vw, 560px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(10, 15, 25, .55); }
dialog .dlg-head { padding: 1rem 1rem .5rem; display: flex; align-items: center; justify-content: space-between; }
dialog .dlg-body { padding: 0 1rem 1rem; max-height: 70vh; overflow-y: auto; }
dialog .dlg-foot { padding: .75rem 1rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; }

/* ID card & certificate */
.idcard { max-width: 340px; margin: 0 auto; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
.idcard .top { background: var(--primary); color: var(--primary-ink); padding: .75rem 1rem; font-weight: 700; }
.idcard .body { padding: 1rem; text-align: center; }
.idcard .photo { width: 110px; height: 130px; object-fit: cover; border-radius: 10px; background: var(--surface-2); margin: 0 auto .5rem; display: block; }
.idcard .qr { display: flex; justify-content: center; margin-top: .75rem; }
.certificate { background: #fffdf6; color: #222; border: 10px double #b08d3c; padding: 2rem 1.5rem; text-align: center; max-width: 900px; margin: 0 auto; }
.certificate h1 { font-family: Georgia, "Times New Roman", serif; font-size: 2rem; color: #7a5b12; }
.certificate .name { font-family: Georgia, serif; font-size: 1.8rem; border-bottom: 1px solid #b08d3c; display: inline-block; padding: 0 1rem; margin: .5rem 0 1rem; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.logo-head { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.logo-head img { width: 48px; height: 48px; border-radius: 10px; }

@media print {
  .topbar, .nav, .no-print, .toasts, .loading-bar, .btn { display: none !important; }
  body { background: #fff; color: #000; display: block !important; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .table-wrap { overflow: visible; border: 0; }
  th { position: static; background: #eee !important; color: #000; }
  .grid-table td, .grid-table th { border: 1px solid #999; font-size: 9pt; padding: 2px; }
  @page { margin: 10mm; }
}
