/* ============================================================
   Belanja RT — token & komponen (PEDOMAN-UI §4, §8)
   ============================================================ */
:root {
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 24px; --r-pill: 999px;

  --bg: #f6f8f6;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --line: #e0e6e1;
  --text: #16211a;
  --text-muted: #5b6b60;
  --accent: #2e5e4e;
  --accent-ink: #ffffff;
  --ok: #1f8a4c; --warn: #a4690f; --danger: #b33227; --info: #2563eb;

  --e1: 0 1px 2px rgba(16,32,22,.06), 0 1px 3px rgba(16,32,22,.04);
  --e2: 0 4px 12px rgba(16,32,22,.08);
  --e3: 0 12px 32px rgba(16,32,22,.14);

  --dur-fast: 90ms; --dur-base: 180ms; --dur-slow: 280ms;
  --ease-out: cubic-bezier(.2,.8,.3,1);
  --ease-bounce: cubic-bezier(.2,1.6,.42,1);

  --pad-page: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1110; --surface: #141a17; --surface-2: #1b231e;
    --line: #263029; --text: #e8efe9; --text-muted: #9db0a4;
    --accent: #5cc08c; --accent-ink: #06130c;
    --e1: 0 1px 2px rgba(0,0,0,.5); --e2: 0 4px 14px rgba(0,0,0,.55);
    --e3: 0 14px 36px rgba(0,0,0,.65);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---------------------------------------------------------- layout */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: calc(var(--sp-3) + var(--safe-t)) var(--pad-page) var(--sp-3);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.app-bar__eyebrow {
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-muted);
}
.app-bar h1 { font-size: 22px; font-weight: 700; line-height: 1.2; }

.app-content {
  padding: var(--pad-page);
  padding-bottom: calc(var(--nav-h) + 32px + var(--safe-b));
  max-width: 720px; margin-inline: auto;
}

.view { display: none; }
.view.is-active { display: block; animation: fade var(--dur-base) var(--ease-out); }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-title { font-size: 17px; font-weight: 700; margin-bottom: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }

/* ------------------------------------------------------------ kartu */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-4); box-shadow: var(--e1);
}
.card + .card { margin-top: var(--sp-3); }

.hero {
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--r-xl); padding: var(--sp-5);
  box-shadow: var(--e2);
}
.hero__label { font-size: 14px; opacity: .9; }
.hero__value { font-size: 32px; font-weight: 700; line-height: 1.05; margin-top: var(--sp-1); font-variant-numeric: tabular-nums; }
.hero__meta { display: flex; gap: var(--sp-4); margin-top: var(--sp-4); font-size: 13px; }
.hero__meta b { font-variant-numeric: tabular-nums; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); margin-top: var(--sp-3); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-4); }
.stat__label { font-size: 13px; color: var(--text-muted); }
.stat__value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ------------------------------------------------------------ daftar */
.list { display: grid; gap: var(--sp-2); }
.list-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3);
  width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-base);
}
.list-item:active { transform: scale(.985); background: var(--surface-2); }
.list-item__main { min-width: 0; }
.list-item__title { font-weight: 600; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; }
.list-item__meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.list-item__value { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.list-item__value.is-in { color: var(--ok); }
.list-item__value.is-out { color: var(--danger); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text-muted); border-radius: var(--r-pill);
  padding: 6px 12px; font-size: 13px; font-weight: 600; min-height: 34px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip-row { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: var(--sp-2); margin-bottom: var(--sp-2); scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }

.status {
  display: inline-block; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: var(--r-pill);
  border: 1px solid currentColor;
}
.status--Diajukan { color: var(--info); }
.status--Disetujui { color: var(--warn); }
.status--Dibeli { color: var(--ok); }
.status--Ditolak { color: var(--danger); }
.status--Aktif { color: var(--ok); }
.status--Nonaktif, .status--Pindah { color: var(--text-muted); }

/* ----------------------------------------------------------- tombol */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 48px; padding: 14px 20px;
  border: 0; border-radius: var(--r-md);
  font-weight: 700; line-height: 1.1;
  transition: transform var(--dur-fast) var(--ease-out), opacity var(--dur-base);
}
.btn:active { transform: scale(.94); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn--primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn--secondary { background: var(--surface-2); color: var(--text); }
.btn--ghost { background: transparent; color: var(--accent); }
.btn--danger { background: var(--danger); color: #fff; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--accent);
  transition: transform var(--dur-fast) var(--ease-out);
}
.icon-btn:active { transform: scale(.92); }

.fab {
  position: fixed; right: var(--sp-4);
  bottom: calc(var(--nav-h) + var(--sp-4) + var(--safe-b));
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border: 0; border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--e3);
  transition: transform var(--dur-base) var(--ease-bounce);
  z-index: 25;
}
.fab:active { transform: scale(.9); }

/* -------------------------------------------------------------- nav */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  min-height: var(--nav-h);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: transparent; color: var(--text-muted);
  font-size: 12px; font-weight: 600; min-height: 56px; padding: var(--sp-2) 2px;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.is-active { color: var(--accent); font-weight: 700; }
.nav-item:active { transform: scale(.96); }

/* ------------------------------------------------------------ sheet */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(8, 18, 12, .45);
  animation: fade var(--dur-base) var(--ease-out);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 88vh; overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-6) + var(--safe-b));
  box-shadow: var(--e3);
  transform: translateY(0);
  animation: sheet-in var(--dur-slow) var(--ease-out);
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet__handle { width: 40px; height: 4px; border-radius: var(--r-pill); background: var(--line); margin: var(--sp-2) auto var(--sp-4); }
.sheet__title { font-size: 18px; font-weight: 700; margin-bottom: var(--sp-4); }

/* ------------------------------------------------------------- form */
.form { display: grid; gap: var(--sp-3); }
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.field input, .field select, .field textarea {
  min-height: 48px; padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-md);
  scroll-margin-bottom: 88px;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field__hint { font-size: 13px; color: var(--text-muted); }
.field__error { font-size: 13px; color: var(--danger); font-weight: 600; }

.select-inline {
  min-height: 40px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
}

/* ----------------------------------------------------------- status */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-md); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-line { height: 14px; margin: 8px 0; }
.sk-card { height: 84px; margin-bottom: var(--sp-2); }

.empty { text-align: center; padding: var(--sp-8) var(--sp-4); color: var(--text-muted); }
.empty svg { width: 48px; height: 48px; color: var(--text-muted); margin-bottom: var(--sp-2); }
.empty p { font-size: 15px; margin-bottom: var(--sp-3); }

.error-box {
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  color: var(--text); border-radius: var(--r-md); padding: var(--sp-4);
}
.error-box p { margin-bottom: var(--sp-3); font-size: 15px; }

.offline-bar {
  position: sticky; top: 0; z-index: 35;
  background: var(--warn); color: #fff;
  font-size: 13px; font-weight: 600; text-align: center; padding: 6px var(--sp-3);
}

.toast {
  position: fixed; left: 50%; z-index: 50;
  bottom: calc(var(--nav-h) + var(--sp-4) + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  background: var(--text); color: var(--bg);
  border-radius: var(--r-md); padding: 12px 16px;
  font-size: 14px; font-weight: 600; box-shadow: var(--e2);
  animation: toast-in var(--dur-base) var(--ease-out);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------------------------------------------------------- laporan */
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.report-table th, .report-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
.report-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.report-table td:not(:first-child), .report-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.report-table td.is-pos { color: var(--ok); }
.report-table td.is-neg { color: var(--danger); }
.report-table tfoot td { font-weight: 700; border-bottom: 0; }

@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

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

@media print {
  .app-bar, .bottom-nav, .fab, .toast, .offline-bar, .chip-row, .select-inline { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .app-content { padding: 0; max-width: none; }
  .card, .hero, .stat { box-shadow: none; border: 1px solid #999; color: #000; background: #fff; }
  .hero { color: #000; }
  .report-table th, .report-table td { border: 1px solid #bbb; }
}
