/* =====================================================================
   Absensi Sekolah — styles (mobile-first)
   ===================================================================== */
   :root {
    --bg: #f5f7f6;
    --surface: #ffffff;
    --surface-2: #f0f3f2;
    --text: #17201d;
    --muted: #5d6b66;
    --border: #dfe5e3;
    --primary: #0f766e;
    --primary-ink: #ffffff;
    --primary-soft: #e0f2ef;
    --danger: #b42318;
  
    --present: #16a34a;
    --late: #d97706;
    --excused: #2563eb;
    --sick: #7c3aed;
    --absent: #dc2626;
    --none: #64748b;
    --none-soft: #cbd5e1;
  
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 2px 8px rgba(16, 24, 20, .04);
    --nav-h: 64px;
    color-scheme: light;
  }
  
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0f1513;
      --surface: #18201d;
      --surface-2: #202a26;
      --text: #e6ecea;
      --muted: #9aa8a3;
      --border: #2b3632;
      --primary: #2bb3a3;
      --primary-ink: #04201c;
      --primary-soft: #143430;
      --danger: #f97066;
      --present: #22c55e;
      --late: #f59e0b;
      --excused: #60a5fa;
      --sick: #a78bfa;
      --absent: #f87171;
      --none: #94a3b8;
      --none-soft: #475569;
      --shadow: none;
      color-scheme: dark;
    }
  }
  
  * { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
  }
  body.modal-open { overflow: hidden; }
  h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
  h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
  p { margin: .4rem 0; }
  a { color: var(--primary); }
  code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
  .muted { color: var(--muted); }
  .small { font-size: .85rem; }
  .error-text { color: var(--danger); }
  [hidden] { display: none !important; }
  
  /* ---------- Layout ---------- */
  .loading { padding: 3rem 1rem; text-align: center; color: var(--muted); }
  .center-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
  .page { max-width: 1180px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
  .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
  .page-head p { margin: 2px 0 0; }
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
  }
  .card.narrow { width: 100%; max-width: 400px; }
  .card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
  .card-head h2 { margin: 0; }
  .empty-state { text-align: center; padding: 32px 16px; color: var(--muted); }
  .grid-2 { display: grid; gap: 16px; }
  .grid-2 > .card { margin-bottom: 0; }
  .grid-2 { margin-bottom: 16px; }
  @media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
  
  /* ---------- Top bar & navigation ---------- */
  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; min-width: 0; flex: 1; }
  .brand img { width: 30px; height: 30px; flex: none; }
  .brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .user { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .user-name { font-size: .9rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
  .pill { font-size: .7rem; background: var(--primary-soft); color: var(--primary); padding: 1px 7px; border-radius: 99px; font-weight: 600; }
  
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; justify-content: space-around;
    background: var(--surface);
    border-top: 1px solid var(--border);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
  }
  .nav a svg { width: 22px; height: 22px; }
  .nav a.active { color: var(--primary); }
  @media (min-width: 900px) {
    .nav { position: static; height: auto; border: 0; padding: 0; gap: 4px; justify-content: center; flex: none; }
    .nav a { flex-direction: row; gap: 8px; padding: 8px 14px; border-radius: 99px; font-size: .9rem; }
    .nav a svg { width: 18px; height: 18px; }
    .nav a.active { background: var(--primary-soft); }
    .page { padding-bottom: 32px; }
    .user-name { max-width: 220px; }
  }
  
  /* ---------- Forms & buttons ---------- */
  label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
  label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
  .field-label { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
  input, select, textarea {
    font: inherit; color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    min-height: 44px;
    width: 100%;
  }
  input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
  textarea { resize: vertical; min-height: 64px; }
  input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
  .inline-input { min-height: 36px; padding: 6px 10px; font-size: .9rem; }
  
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-weight: 600; font-size: .92rem;
    min-height: 44px; padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface); color: var(--text);
    cursor: pointer; text-decoration: none; white-space: nowrap;
  }
  .btn:hover { background: var(--surface-2); }
  .btn:disabled { opacity: .5; cursor: not-allowed; }
  .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
  .btn.primary:hover { filter: brightness(1.06); }
  .btn.ghost { background: transparent; }
  .btn.small { min-height: 36px; padding: 0 12px; font-size: .85rem; }
  .btn.block { width: 100%; }
  .link { background: none; border: 0; padding: 4px 2px; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; }
  .link.danger { color: var(--danger); }
  .btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  .btn-row.end { justify-content: flex-end; margin-top: 8px; }
  
  .controls { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
  .controls label { margin-bottom: 0; }
  .controls.card label { margin-bottom: 0; }
  .controls.inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin-bottom: 14px; }
  .controls.inline label { margin: 0; min-width: 150px; flex: 1 1 150px; }
  .controls.inline label.check { flex: 0 1 auto; min-width: 0; min-height: 44px; }
  .form-grid { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
  @media (min-width: 600px) { .form-grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
  .day-picks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 12px; }
  .day-picks label { margin: 0; }
  .steps { margin: 0 0 12px; padding-left: 20px; }
  
  /* ---------- Login ---------- */
  .login h1 { text-align: center; }
  .login > p.muted { text-align: center; margin-bottom: 18px; }
  .login-logo { display: flex; justify-content: center; margin-bottom: 10px; }
  .login-logo img { width: 56px; height: 56px; }
  .login .small { text-align: center; margin-top: 14px; }
  
  /* ---------- Status badges & chips ---------- */
  .badge {
    display: inline-flex; align-items: center;
    font-size: .76rem; font-weight: 700;
    padding: 3px 10px; border-radius: 99px;
    color: #fff; background: var(--none); white-space: nowrap;
  }
  .badge.present { background: var(--present); }
  .badge.late { background: var(--late); }
  .badge.excused { background: var(--excused); }
  .badge.sick { background: var(--sick); }
  .badge.absent { background: var(--absent); }
  .badge.none { background: transparent; color: var(--muted); border: 1px dashed var(--none-soft); }
  
  .chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
  .chip {
    flex: none; display: inline-flex; align-items: center; gap: 7px;
    border: 1px solid var(--border); background: var(--surface);
    border-radius: 99px; padding: 6px 12px 6px 6px;
    font: inherit; font-size: .85rem; font-weight: 600; color: var(--text); cursor: pointer;
  }
  .chip-n { min-width: 28px; height: 26px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center; color: #fff; background: var(--none); font-size: .82rem; }
  .chip.all .chip-n { background: var(--text); color: var(--surface); }
  .chip.present .chip-n { background: var(--present); }
  .chip.late .chip-n { background: var(--late); }
  .chip.excused .chip-n { background: var(--excused); }
  .chip.sick .chip-n { background: var(--sick); }
  .chip.absent .chip-n { background: var(--absent); }
  .chip.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
  
  /* ---------- Scanner ---------- */
  .scan-layout { display: grid; gap: 16px; }
  .scan-layout > .card { margin: 0; }
  @media (min-width: 900px) { .scan-layout { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; } }
  .reader { width: 100%; max-width: 480px; margin: 0 auto 12px; border-radius: var(--radius-sm); overflow: hidden; background: #000; aspect-ratio: 1; }
  .reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
  .reader img[alt="Info icon"], .reader img[alt="Camera based scan"] { display: none; }
  .scan-result {
    border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 12px; text-align: center;
    border: 2px solid var(--border); background: var(--surface-2); transition: background .15s, border-color .15s;
  }
  .sr-title { font-size: 1.25rem; font-weight: 800; }
  .sr-sub { font-size: .9rem; color: var(--muted); margin-top: 2px; }
  .scan-result.present { border-color: var(--present); background: color-mix(in srgb, var(--present) 14%, var(--surface)); }
  .scan-result.late { border-color: var(--late); background: color-mix(in srgb, var(--late) 16%, var(--surface)); }
  .scan-result.warn { border-color: var(--late); background: color-mix(in srgb, var(--late) 10%, var(--surface)); }
  .scan-result.error { border-color: var(--absent); background: color-mix(in srgb, var(--absent) 12%, var(--surface)); }
  .scan-result.loading { opacity: .75; }
  .scan-card .btn-row { justify-content: center; }
  
  .recent-list, .roster, .plain-list { list-style: none; margin: 0; padding: 0; }
  .recent-list li, .plain-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 0; border-bottom: 1px solid var(--border);
  }
  .recent-list li:last-child, .plain-list li:last-child, .roster li:last-child { border-bottom: 0; }
  .empty { color: var(--muted); padding: 18px 0; justify-content: center !important; text-align: center; }
  
  /* ---------- Roster ---------- */
  .roster-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .ri-main { flex: 1; min-width: 0; }
  .ri-name { font-weight: 700; }
  .ri-meta { font-size: .8rem; color: var(--muted); }
  .ri-notes { font-size: .82rem; margin-top: 3px; padding: 3px 8px; background: var(--surface-2); border-radius: 6px; display: inline-block; }
  .ri-side { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  @media (max-width: 520px) {
    .roster-item { flex-direction: column; align-items: stretch; gap: 8px; }
    .ri-side { justify-content: flex-start; }
  }
  
  .seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 14px; }
  @media (max-width: 420px) { .seg { grid-template-columns: repeat(3, 1fr); } }
  .seg-btn {
    font: inherit; font-size: .85rem; font-weight: 700;
    min-height: 44px; border-radius: var(--radius-sm);
    border: 2px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  }
  .seg-btn.active { color: #fff; }
  .seg-btn.present.active { background: var(--present); border-color: var(--present); }
  .seg-btn.late.active { background: var(--late); border-color: var(--late); }
  .seg-btn.excused.active { background: var(--excused); border-color: var(--excused); }
  .seg-btn.sick.active { background: var(--sick); border-color: var(--sick); }
  .seg-btn.absent.active { background: var(--absent); border-color: var(--absent); }
  
  /* ---------- Dashboard ---------- */
  .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  @media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
  @media (min-width: 1000px) { .stats { grid-template-columns: repeat(7, 1fr); } }
  .stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; border-top: 4px solid var(--none); }
  .stat-v { font-size: 1.6rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
  .stat-l { font-size: .8rem; color: var(--muted); font-weight: 600; }
  .stat-s { font-size: .75rem; color: var(--muted); }
  .stat.rate { border-top-color: var(--primary); grid-column: span 2; }
  @media (min-width: 1000px) { .stat.rate { grid-column: span 1; } }
  .stat.present { border-top-color: var(--present); }
  .stat.late { border-top-color: var(--late); }
  .stat.excused { border-top-color: var(--excused); }
  .stat.sick { border-top-color: var(--sick); }
  .stat.absent { border-top-color: var(--absent); }
  .stat.none { border-top-color: var(--none-soft); }
  .chart-box { position: relative; height: 280px; }
  .chart-empty { padding-top: 110px; text-align: center; }
  
  /* ---------- Tables ---------- */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { width: 100%; border-collapse: collapse; font-size: .88rem; }
  .table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
  .table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
  .table .num { text-align: right; font-variant-numeric: tabular-nums; }
  .table .actions { white-space: nowrap; text-align: right; }
  .table select { min-height: 36px; padding: 4px 8px; font-size: .88rem; }
  .warn-row td { background: color-mix(in srgb, var(--absent) 7%, transparent); }
  .muted-row td { color: var(--muted); }
  
  /* ---------- Tabs ---------- */
  .tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
  .tab {
    flex: none; font: inherit; font-weight: 600; font-size: .9rem;
    padding: 8px 16px; border-radius: 99px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted); cursor: pointer;
  }
  .tab.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
  
  /* ---------- Modal & toast ---------- */
  .modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(10, 16, 14, .5);
    display: flex; align-items: flex-end; justify-content: center;
  }
  .modal {
    background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .modal.wide { max-width: 720px; }
  .modal h2 { font-size: 1.2rem; margin-bottom: 2px; }
  @media (min-width: 600px) {
    .modal-backdrop { align-items: center; padding: 16px; }
    .modal { border-radius: var(--radius); padding: 24px; }
  }
  
  #toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
  @media (min-width: 900px) { #toast-root { bottom: 24px; } }
  .toast {
    max-width: 480px; padding: 11px 16px; border-radius: var(--radius-sm);
    background: var(--text); color: var(--surface); font-weight: 600; font-size: .9rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
    opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
  }
  .toast.show { opacity: 1; transform: none; }
  .toast.success { background: var(--present); color: #fff; }
  .toast.error { background: var(--absent); color: #fff; }
  
  /* ---------- QR cards (85 x 54 mm) ---------- */
  .cards-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
  .id-card {
    display: flex; gap: 10px; align-items: center;
    background: #fff; color: #111; border: 1px solid #cfd6d4; border-radius: 10px;
    padding: 10px; aspect-ratio: 85 / 54; overflow: hidden;
    border-left: 8px solid #0f766e;
  }
  .idc-qr { width: 44%; flex: none; }
  .idc-qr img, .idc-qr canvas { width: 100% !important; height: auto !important; display: block; }
  .idc-info { min-width: 0; }
  .idc-school { font-size: .7rem; font-weight: 700; color: #0f766e; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
  .idc-name { font-weight: 800; font-size: 1rem; line-height: 1.2; margin-bottom: 4px; word-break: break-word; }
  .idc-meta { font-size: .8rem; color: #444; }
  .idc-code { font-size: .72rem; color: #444; margin-top: 6px; padding-top: 4px; border-top: 1px dashed #cfd6d4; }
  
  @media print {
    @page { size: A4; margin: 10mm; }
    body { background: #fff; }
    .topbar, .nav, .no-print, .page-head, #toast-root { display: none !important; }
    .page { padding: 0; max-width: none; }
    .cards-sheet { display: grid; grid-template-columns: repeat(2, 85mm); grid-auto-rows: 54mm; gap: 4mm 6mm; justify-content: center; }
    .id-card { width: 85mm; height: 54mm; aspect-ratio: auto; padding: 3mm; border-radius: 3mm; break-inside: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .idc-qr { width: 40mm; }
    .idc-name { font-size: 11pt; }
    .idc-meta { font-size: 8.5pt; }
    .idc-school, .idc-code { font-size: 7pt; }
  }
  
  /* ---------- Small-screen & layout refinements ---------- */
  .page-head input[type="date"] { width: auto; }
  .nav a span { white-space: nowrap; }
  @media (max-width: 600px) {
    .user-name { display: none; }
  }
  
  /* ---------- Teacher accounts ---------- */
  .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; }
  .input-with-btn { display: flex; gap: 6px; }
  .input-with-btn input { flex: 1; min-width: 0; }
  .input-with-btn .btn { min-height: 44px; }
  .notice {
    font-size: .88rem; padding: 10px 12px; margin-bottom: 14px; border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--late) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--late) 40%, var(--border));
  }
  .cred-box { display: grid; gap: 10px; padding: 14px; margin: 12px 0; border-radius: var(--radius-sm); background: var(--surface-2); }
  .cred-box div { display: flex; flex-direction: column; gap: 2px; }
  .cred-box b { font-size: 1.05rem; word-break: break-all; }