/* =====================================================================
   Perpustakaan SMKI Muhammadiyah 8 Siliragung — Design System
   Hitam & putih. Mode terang = kertas putih + tinta hitam,
   mode gelap = hitam pekat + teks putih. Abu-abu netral di antaranya.
   Warna status (hijau/kuning/merah) dipakai hemat, hanya sebagai penanda.
   ===================================================================== */

:root {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #595959;
  --surface: #f6f6f6;
  --surface-2: #ececec;
  --line: #e0e0e0;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  color-scheme: light;
}

.dark {
  --bg: #000000;
  --fg: #ffffff;
  --muted: #a6a6a6;
  --surface: #0f0f0f;
  --surface-2: #1a1a1a;
  --line: #2a2a2a;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  color-scheme: dark;
}

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--fg); }
::selection { background: var(--fg); color: var(--bg); }

:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: var(--r-sm);
  font-weight: 600; transition: top .15s;
}
.skip-link:focus { top: 12px; }

.scroll-thin { scrollbar-width: none; }
.scroll-thin::-webkit-scrollbar { display: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.nav-link {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 500; color: var(--muted);
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface); color: var(--fg); }
.nav-link.is-active { color: var(--fg); font-weight: 700; box-shadow: inset 0 -2px 0 var(--fg); border-radius: 0; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 40px; width: 40px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: transparent; color: var(--fg);
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn[hidden] { display: none; }
.theme-icon-moon { display: none; }
.dark .theme-icon-sun { display: none; }
.dark .theme-icon-moon { display: inline-flex; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  height: 32px; width: 32px; border-radius: 999px;
  background: var(--fg); color: var(--bg); font-size: 12px; font-weight: 700;
}

/* ---------- Bottom nav (siswa, mobile) ---------- */
.bottom-nav { display: none; }
@media (max-width: 767px) {
  .has-bottom-nav { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(3, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--bg); border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0;
  }
  .bottom-nav a.is-active { color: var(--fg); }
  .bottom-nav-main { position: relative; }
  .bottom-nav-fab {
    display: inline-flex; align-items: center; justify-content: center;
    height: 48px; width: 48px; margin-top: -22px; border-radius: 999px;
    background: var(--fg); color: var(--bg); border: 4px solid var(--bg);
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 8px;
  border: 1px solid var(--fg); background: var(--fg); color: var(--bg);
  font-size: 14px; font-weight: 600; line-height: 1; white-space: nowrap;
  cursor: pointer; transition: opacity .15s, background .15s, color .15s, transform .05s;
}
.btn:hover { opacity: .86; }
.btn:active { transform: translateY(1px); }
.btn-outline { background: transparent; color: var(--fg); border-color: var(--fg); }
.btn-outline:hover { background: var(--fg); color: var(--bg); opacity: 1; }
.btn-ghost { background: transparent; color: var(--fg); border-color: transparent; }
.btn-ghost:hover { background: var(--surface); opacity: 1; }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: #fff; opacity: 1; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 52px; padding: 0 26px; font-size: 15px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: .4; cursor: not-allowed; pointer-events: none;
}

/* ---------- Form ---------- */
.label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.field {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.field:hover { border-color: var(--muted); }
.field:focus { outline: none; border-color: var(--fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 14%, transparent); }
.field[readonly], .field:disabled { background: var(--surface); color: var(--muted); cursor: not-allowed; }
select.field { appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
textarea.field { min-height: 96px; resize: vertical; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { height: 18px; width: 18px; accent-color: var(--fg); }

/* ---------- Surfaces ---------- */
.panel { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.panel-soft { border-radius: var(--r-md); background: var(--surface); }
.panel-strong { border: 1px solid var(--fg); border-radius: var(--r-md); background: var(--bg); }

/* ---------- Flash ---------- */
.flash {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px;
  border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--r-sm);
  background: var(--surface); font-size: 14px;
}
.flash-success { border-left-color: var(--ok); }
.flash-error   { border-left-color: var(--bad); }
.flash-info    { border-left-color: var(--fg); }
.flash-warning { border-left-color: var(--warn); }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--bg);
}
.badge::before { content: ""; height: 7px; width: 7px; border-radius: 999px; background: var(--muted); }
.badge-ok::before   { background: var(--ok); }
.badge-warn::before { background: var(--warn); }
.badge-bad::before  { background: var(--bad); }
.badge-bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.badge-plain::before { display: none; }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 4px;
  background: var(--surface-2); font-size: 12px; font-weight: 500;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 14px; font-size: 14px; font-weight: 500; color: var(--muted);
  white-space: nowrap; border: 0; background: transparent; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn:hover { color: var(--fg); }
.tab-btn[aria-selected="true"] { color: var(--fg); font-weight: 700; border-bottom-color: var(--fg); }
.tab-count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-size: 12px; font-weight: 700;
}
.tab-btn[aria-selected="true"] .tab-count { background: var(--fg); color: var(--bg); }
.tab-count-bad { background: var(--bad) !important; color: #fff !important; }
[data-tab-panel][hidden] { display: none; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 12px 14px; background: var(--surface); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Dialog / modal ---------- */
dialog.modal {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  padding: 0; border: 1px solid var(--fg); border-radius: var(--r-md);
  background: var(--bg); color: var(--fg); overflow: hidden;
}
dialog.modal[open] { display: flex; flex-direction: column; animation: modal-in .16s ease-out; }
dialog.modal::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--surface); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Kartu indeks (stok real-time) ---------- */
.index-card {
  position: relative; background: var(--bg);
  border: 1px solid var(--fg); border-radius: 4px;
  padding: 0 22px 44px;
}
.index-card::after {
  content: ""; position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  height: 14px; width: 14px; border-radius: 999px; border: 1px solid var(--fg); background: var(--surface);
}
.index-head {
  display: flex; align-items: flex-end; height: 56px; padding-bottom: 10px;
  font-size: 12px; color: var(--muted); border-bottom: 2px solid var(--fg);
}
.index-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  height: 64px; padding-top: 22px; border-bottom: 1px solid var(--line);
}
.index-row:last-of-type { border-bottom: 0; }
.index-row .k { font-size: 14px; color: var(--muted); }
.index-row .v {
  font-family: 'Newsreader', Georgia, serif; font-size: 34px; font-weight: 600;
  line-height: 1; font-variant-numeric: tabular-nums; border-radius: 4px;
}

/* ---------- Baris hasil katalog ---------- */
.catalog-row {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--line);
}
.catalog-row:first-child { border-top: 1px solid var(--fg); }
.dot { display: inline-block; height: 8px; width: 8px; border-radius: 999px; background: var(--muted); }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); }

/* ---------- Kartu pinjaman ---------- */
.loan-card { border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px; background: var(--bg); }
.loan-card.is-late { border-color: var(--bad); }
.loan-card.is-pending { border-color: var(--warn); }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--fg); border-radius: 999px; }
.meter.is-late > span { background: var(--bad); }

/* ---------- Stat ---------- */
.stat { border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 18px; background: var(--bg); }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-family: 'Newsreader', Georgia, serif; font-size: 34px; font-weight: 600; line-height: 1.1; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-strong { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.stat-strong .k { color: color-mix(in srgb, var(--bg) 70%, transparent); }

/* ---------- QR & scanner ---------- */
.qr-frame { display: inline-block; padding: 16px; background: #fff; border: 1px solid var(--fg); border-radius: var(--r-md); }
.qr-frame img, .qr-frame canvas { display: block; }
.scanner-box {
  width: 100%; max-width: 420px; margin: 0 auto; aspect-ratio: 1 / 1;
  border: 1px solid var(--fg); border-radius: var(--r-md); overflow: hidden; background: #000; position: relative;
}
.scanner-box video { object-fit: cover; }
.scanner-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; text-align: center; color: #fff; padding: 24px; font-size: 14px;
}
#reader__scan_region img { display: none; }
#reader__dashboard_section_csr button { display: none; }

/* ---------- Misc ---------- */
.prose-tight p + p { margin-top: .6rem; }
.divider { height: 1px; background: var(--line); }
.empty {
  border: 1px dashed var(--line); border-radius: var(--r-md); padding: 40px 20px;
  text-align: center; color: var(--muted);
}
.spinner {
  height: 18px; width: 18px; border-radius: 999px; border: 2px solid var(--line);
  border-top-color: var(--fg); animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.pulse-ok { animation: pulse-ok 1.2s ease-out 1; }
@keyframes pulse-ok { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .no-print { display: none !important; }
  body { background: #fff !important; color: #000 !important; }
  .qr-print-area { break-inside: avoid; }
  .topbar, footer, .bottom-nav { display: none !important; }
}
