/* ============================================================ THEME TOKENS */
:root {
  --sidebar-w: 248px;

  /* Sky blue brand */
  --brand: #0ea5e9;
  --brand-dark: #0284c7;
  --brand-light: #38bdf8;
  --brand-soft: rgba(14, 165, 233, .12);
  /* Isian pekat berteks putih: --brand (#0ea5e9) hanya 2,77:1 terhadap putih —
     di bawah ambang WCAG. Nada lebih tua ini 5,93:1 dan tetap satu keluarga. */
  --brand-solid: #0369a1;
  --brand-solid-hover: #075985;
  --brand-solid-ink: #ffffff;
  --accent-warn: #b45309;     /* amber bawaan hanya 2,15:1 di atas kertas putih */

  /* Light theme surfaces */
  --app-bg: #eef5fc;
  --surface: #ffffff;
  --surface-2: #f7fafd;
  --border: #e3ecf5;
  --ink: #0f2438;
  --muted: #6b7e92;

  --sidebar-bg: #0b2942;
  --sidebar-ink: #b9cde0;
  --sidebar-active: var(--brand);
  --topbar-bg: #ffffff;
  --shadow: 0 1px 2px rgba(8, 47, 73, .06);
  --shadow-lg: 0 10px 30px rgba(8, 47, 73, .10);
}

[data-bs-theme="dark"] {
  --brand: #38bdf8;
  --brand-dark: #0ea5e9;
  --brand-light: #7dd3fc;
  --brand-soft: rgba(56, 189, 248, .15);
  /* Di latar gelap dibalik: biru cerah dengan tinta gelap (7,43:1). */
  --brand-solid: #38bdf8;
  --brand-solid-hover: #7dd3fc;
  --brand-solid-ink: #04243a;
  --accent-warn: #f59e0b;

  --app-bg: #0a1422;
  --surface: #111f31;
  --surface-2: #16273c;
  --border: #20344c;
  --ink: #e6eef7;
  --muted: #8aa0b6;

  --sidebar-bg: #060f1c;
  --sidebar-ink: #9fb4ca;
  --topbar-bg: #0f1d2e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);

  --bs-body-bg: var(--app-bg);
  --bs-body-color: var(--ink);
}

* { box-sizing: border-box; }
body {
  background: var(--app-bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  transition: background-color .3s ease, color .3s ease;
}

/* ================================================================= LAYOUT */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 1040;
  transition: transform .25s ease;
}
.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
  font-size: 1.25rem; font-weight: 700; color: #fff;
  padding: 1.15rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand i { color: var(--brand-light); font-size: 1.4rem; }
.sidebar-brand .brand-logo { height: 40px; width: auto; max-width: 100%; object-fit: contain; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .6rem;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.14); border-radius: 100px;
  transition: background .2s;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--brand-light); }
.sidebar:hover .sidebar-nav { scrollbar-color: rgba(255,255,255,.28) transparent; }
.sidebar-nav .nav-section {
  display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: #6b8198; margin: 1rem .75rem .35rem; font-weight: 600;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .75rem; margin-bottom: 2px; border-radius: 9px;
  color: var(--sidebar-ink); text-decoration: none; font-size: .92rem; font-weight: 500;
  transition: background-color .15s, color .15s, transform .15s;
}
.sidebar-nav a i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; transform: translateX(2px); }
.sidebar-nav a.active { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(14,165,233,.45); }

.sidebar-footer { padding: .9rem 1.25rem; border-top: 1px solid rgba(255,255,255,.07); font-size: .82rem; color: #8aa3bc; }
.sidebar-footer .copyright { font-size: .7rem; margin-top: .3rem; opacity: .75; }

/* topbar */
.topbar {
  height: 62px; background: var(--topbar-bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem;
  position: sticky; top: 0; z-index: 1030;
  transition: background-color .3s ease, border-color .3s ease;
}
.topbar-title { font-weight: 600; font-size: 1.1rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; }

.theme-toggle .icon-light { display: none; }
[data-bs-theme="dark"] .theme-toggle .icon-dark { display: none; }
[data-bs-theme="dark"] .theme-toggle .icon-light { display: inline; }

.messages-wrap { padding: 1rem 1.5rem 0; }
.content { padding: 1.5rem; flex: 1; }

/* =============================================================== SURFACES */
.stat-card {
  background: var(--surface); border-radius: 14px; padding: 1.15rem 1.25rem;
  border: 1px solid var(--border); box-shadow: var(--shadow); height: 100%;
  transition: transform .18s ease, box-shadow .18s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.35rem; color: #fff; flex-shrink: 0;
}
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; color: var(--ink);
  overflow-wrap: anywhere; min-width: 0; }
.stat-card > div { min-width: 0; }
@media (max-width: 576px) { .stat-card .stat-value { font-size: 1.05rem; } }
.stat-card .stat-label { color: var(--muted); font-size: .82rem; font-weight: 500; }

.card {
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  background: var(--surface);
}
.card-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  font-weight: 600; border-radius: 14px 14px 0 0 !important; color: var(--ink);
}

.bg-grad-indigo { background: linear-gradient(135deg,#38bdf8,#0284c7); }
.bg-grad-green  { background: linear-gradient(135deg,#34d399,#059669); }
.bg-grad-amber  { background: linear-gradient(135deg,#fbbf24,#d97706); }
.bg-grad-sky    { background: linear-gradient(135deg,#7dd3fc,#0ea5e9); }
.bg-grad-rose   { background: linear-gradient(135deg,#fb7185,#e11d48); }
.bg-grad-slate  { background: linear-gradient(135deg,#94a3b8,#475569); }

/* tables */
.table { color: var(--ink); --bs-table-bg: transparent; }
.table > :not(caption) > * > * { padding: .7rem .75rem; background: transparent; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 2px solid var(--border); }
.table-hover tbody tr:hover { background: var(--brand-soft); }
.table td, .table th { border-color: var(--border); }
.asset-tag { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; font-size: .85rem; color: var(--brand-dark); }

/* sortable headers */
th.sortable { white-space: nowrap; }
.sort-link { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; }
.sort-link:hover { color: var(--brand); }
.sort-ic { font-size: .7rem; opacity: .45; }
.sort-ic.active { opacity: 1; color: var(--brand); }

/* pagination */
.pagination-bar { background: var(--surface-2); border-color: var(--border) !important; border-radius: 0 0 14px 14px; }
.page-link { color: var(--brand-dark); background: var(--surface); border-color: var(--border); }
.page-link:hover { background: var(--brand-soft); color: var(--brand-dark); }
.page-item.active .page-link { background: var(--brand-solid); border-color: var(--brand-solid); color: var(--brand-solid-ink); }

.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.5rem; font-weight: 700; margin: 0; color: var(--ink); }
.page-head .sub { color: var(--muted); font-size: .9rem; }

.btn { transition: transform .12s ease, box-shadow .12s ease, background-color .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  --bs-btn-bg: var(--brand-solid); --bs-btn-border-color: var(--brand-solid);
  --bs-btn-color: var(--brand-solid-ink); --bs-btn-hover-color: var(--brand-solid-ink);
  --bs-btn-active-color: var(--brand-solid-ink);
  --bs-btn-hover-bg: var(--brand-solid-hover); --bs-btn-hover-border-color: var(--brand-solid-hover);
  --bs-btn-active-bg: var(--brand-solid-hover);
}
.text-primary { color: var(--brand) !important; }
a { color: var(--brand-dark); }

/* timeline */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before { content:""; position:absolute; left:7px; top:4px; bottom:4px; width:2px; background:var(--border); }
.timeline-item { position: relative; padding-bottom: 1.1rem; }
.timeline-item::before {
  content:""; position:absolute; left:-1.5rem; top:3px; width:14px; height:14px;
  border-radius:50%; background:var(--surface); border:3px solid var(--brand);
}

/* forms in dark mode */
.form-control, .form-select { background: var(--surface); border-color: var(--border); color: var(--ink); }
.form-control:focus, .form-select:focus { border-color: var(--brand-light); box-shadow: 0 0 0 .2rem var(--brand-soft); }
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--bs-danger, #dc3545); }
.form-control.is-invalid:focus, .form-select.is-invalid:focus { box-shadow: 0 0 0 .2rem rgba(220,53,69,.2); }
.errorlist { list-style: none; padding: 0; margin: .3rem 0 0; font-size: .8125rem; color: var(--bs-danger, #dc3545); }
.errorlist li { margin: 0; }
.input-group-text { background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.list-group-item { background: var(--surface); border-color: var(--border); color: var(--ink); }
.dropdown-menu { background: var(--surface); border-color: var(--border); }
.dropdown-item { color: var(--ink); }
.dropdown-item:hover { background: var(--surface-2); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg,#082f49,#0ea5e9 60%,#38bdf8); padding: 1rem; }
.login-card { width: 100%; max-width: 410px; background: #fff; border-radius: 18px;
  padding: 2.25rem; box-shadow: 0 20px 60px rgba(0,0,0,.3); }

/* ============================================================= ACCESS DENIED */
.access-denied { max-width: 620px; margin: 2rem auto; }
.access-denied .ad-icon {
  width: 76px; height: 76px; margin: 0 auto; border-radius: 20px;
  display: grid; place-items: center; font-size: 2.1rem;
  color: var(--brand); background: var(--brand-soft);
}

/* ============================================================= SCROLLBARS */
/* Scrollbar dokumen & area scroll — mengikuti tema (light/dark). */
html { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 100px;
  border: 2px solid transparent; background-clip: padding-box;
  transition: background .2s;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }
/* Sidebar punya gaya sendiri (di atas) agar cocok dengan latar gelapnya. */

/* ============================================================= QR & TRACKING */
/* QR selalu di atas latar putih agar terbaca scanner di mode gelap/terang. */
.qr-svg { display: block; width: 100%; height: 100%; }
.qr-box {
  width: 150px; height: 150px; padding: 8px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px;
}
.qr-box .qr-svg { width: 100%; height: 100%; }

.track-wrap { max-width: 820px; }
.track-hero .track-qr {
  width: 92px; height: 92px; padding: 6px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px; flex: 0 0 auto;
}
.track-hero .track-qr .qr-svg { width: 100%; height: 100%; }

.scan-reader {
  width: 100%; max-width: 380px; margin: 0 auto; border-radius: 12px;
  overflow: hidden; background: #000; min-height: 260px;
}
.scan-reader video { width: 100% !important; height: auto !important; display: block; }

/* Grid card label QR */
.label-grid {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.label-card {
  position: relative; display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: .35rem; margin: 0; padding: 1rem .75rem .85rem;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .12s;
}
.label-card:hover { border-color: var(--brand-light); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.label-card.selected { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft) inset; background: var(--brand-soft); }
.label-card-chk { position: absolute; top: .6rem; left: .6rem; margin: 0; cursor: pointer; }
.label-card-status { position: absolute; top: .55rem; right: .55rem; font-size: .62rem; }
.label-card-qr {
  width: 118px; height: 118px; padding: 7px; margin-top: .35rem;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
}
.label-card-qr .qr-svg { width: 100%; height: 100%; display: block; }
.label-card-bc { height: 22px; background: #fff; border-radius: 3px; padding: 2px 4px; margin-top: .35rem; align-self: stretch; }
.label-card-bc svg { width: 100%; height: 100%; display: block; }
.label-card-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  font-size: .9rem; color: var(--brand-dark); margin-top: .2rem; word-break: break-all;
}
.label-card-name {
  font-size: .8rem; color: var(--ink); line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.label-card-cat { font-size: .72rem; color: var(--muted); }
.label-card-print { margin-top: .45rem; --bs-btn-padding-y: .15rem; --bs-btn-font-size: .74rem; }

/* ============================================================= ANIMATIONS */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: no-preference) {
  .content { animation: fadeInUp .32s cubic-bezier(.21,.6,.35,1); }
  .stat-card, .card { animation: fadeInUp .4s cubic-bezier(.21,.6,.35,1) both; }
  ::view-transition-old(root) { animation: vt-out .22s ease both; }
  ::view-transition-new(root) { animation: vt-in .28s ease both; }
}
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; } to { opacity: 1; } }

/* HTMX inflight subtle dim */
.htmx-request.htmx-settling { opacity: .6; }
#assetTableWrap.htmx-request, #moveWrap.htmx-request { opacity: .55; transition: opacity .15s; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
}

/* ============================================================= CALENDAR (jadwal pemeliharaan) */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  background: var(--border); border-top: 1px solid var(--border); }
.cal-weekday { background: var(--surface-2); text-align: center; font-size: .72rem;
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem 0; }
.cal-cell { background: var(--surface); min-height: 116px; padding: .3rem .35rem .4rem;
  display: flex; flex-direction: column; gap: .25rem; }
.cal-cell-muted { background: var(--app-bg); }
.cal-cell-muted .cal-daynum { opacity: .45; }
.cal-cell-today { box-shadow: inset 0 0 0 2px var(--brand); }
.cal-daynum { font-size: .8rem; font-weight: 600; color: var(--ink);
  width: 1.55rem; height: 1.55rem; display: grid; place-items: center; }
.cal-cell-today .cal-daynum { background: var(--brand); color: #fff; border-radius: 50%; }
.cal-events { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; max-height: 132px; }
.cal-event { display: block; text-decoration: none; border-radius: 5px; padding: 2px 6px; cursor: pointer;
  font-size: .72rem; line-height: 1.2; border-left: 3px solid var(--muted); background: var(--surface-2);
  color: var(--ink); overflow: hidden; transition: transform .12s, box-shadow .12s; }
.cal-event:hover { transform: translateX(1px); box-shadow: var(--shadow); }
.cal-event-tag { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-event-type { color: var(--muted); display: block; font-size: .68rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-event-info { border-left-color: rgb(var(--bs-info-rgb)); background: rgba(var(--bs-info-rgb), .12); }
.cal-event-warning { border-left-color: rgb(var(--bs-warning-rgb)); background: rgba(var(--bs-warning-rgb), .14); }
.cal-event-success { border-left-color: rgb(var(--bs-success-rgb)); background: rgba(var(--bs-success-rgb), .12); }
.cal-event-secondary { border-left-color: rgb(var(--bs-secondary-rgb)); background: rgba(var(--bs-secondary-rgb), .12); }
@media (max-width: 575.98px) {
  .cal-cell { min-height: 80px; padding: .2rem; }
  .cal-event-type { display: none; }
}
.modal-mt-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.25rem; flex-shrink: 0; }

/* ==================================================== PROCUREMENT FLOW STEPS */
.flow-steps {
  display: flex;
  align-items: flex-start;
  gap: .25rem;
  overflow-x: auto;
  padding-bottom: .25rem;
}
.flow-step { display: flex; flex-direction: column; align-items: center; min-width: 86px; text-align: center; }
.flow-dot {
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
  border: 2px solid var(--border);
}
.flow-step.done .flow-dot { background: #16a34a; border-color: #16a34a; color: #fff; }
.flow-step.current .flow-dot {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 0 0 4px var(--brand-soft);
}
.flow-step.danger .flow-dot { background: #dc2626; border-color: #dc2626; color: #fff; }
.flow-label { font-size: .74rem; margin-top: .35rem; line-height: 1.2; color: var(--muted); font-weight: 600; }
.flow-step.current .flow-label { color: var(--ink); }
.flow-label a { color: inherit; text-decoration: none; }
.flow-label a:hover { color: var(--brand); }
.flow-note { font-size: .68rem; font-weight: 500; color: var(--brand-dark); margin-top: .1rem; }
.flow-step.danger .flow-note { color: #dc2626; }
.flow-line { flex: 1; height: 2px; background: var(--border); margin-top: .95rem; min-width: 14px; }
.flow-line.done { background: #16a34a; }
.flow-hint {
  font-size: .82rem; color: var(--muted);
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: .5rem; padding: .45rem .7rem;
}

/* Chip filter status pada halaman daftar */
.status-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.status-chips .chip {
  font-size: .78rem; font-weight: 600; text-decoration: none;
  padding: .25rem .65rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface);
}
.status-chips .chip:hover { border-color: var(--brand); color: var(--brand); }
.status-chips .chip.active { background: var(--brand-solid); border-color: var(--brand-solid); color: var(--brand-solid-ink); }
.status-chips .chip .count { opacity: .85; font-weight: 700; margin-left: .15rem; }

/* Empty state daftar */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state > i { font-size: 2rem; display: block; margin-bottom: .5rem; color: var(--brand); opacity: .6; }
.empty-state .lead-line { font-weight: 600; color: var(--ink); font-size: .95rem; }
.empty-state .sub-line { font-size: .82rem; max-width: 34rem; margin: .25rem auto .9rem; }

/* Badge antrean pada sidebar */
.sidebar-nav a .nav-count {
  margin-left: auto; font-size: .68rem; font-weight: 700;
  background: #f59e0b; color: #1f2937;
  border-radius: 999px; padding: .1rem .45rem; line-height: 1.2;
}

/* Foto aset */
.asset-photo-thumb {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 8px;
  object-fit: cover; border: 1px solid var(--border); background: var(--surface);
}
.asset-photo-empty {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 1.05rem;
}
.asset-photo-thumb-lg {
  width: 120px; height: 120px; border-radius: 10px;
  object-fit: cover; border: 1px solid var(--border);
}
.asset-photo-detail {
  display: block; width: 100%; max-height: 260px; object-fit: cover;
  border-bottom-left-radius: var(--bs-card-inner-border-radius, .75rem);
  border-bottom-right-radius: var(--bs-card-inner-border-radius, .75rem);
}

/* Fallback brand tanpa logo */
.brand-fallback {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 800; font-size: 1.15rem; letter-spacing: .3px; color: #fff;
}
.brand-fallback i { font-size: 1.35rem; color: var(--brand, #0ea5e9); }

/* Item PR yang tidak disetujui — setelah keputusan, dan pratinjau saat memutus */
.pr-item-ditolak > td { opacity: .6; }
.pr-item-ditolak > td:not(:first-child) { text-decoration: line-through; }
.pr-item-dicoret > td { opacity: .55; }
.pr-item-dicoret > td:not(:first-child) { text-decoration: line-through; }
.pr-approve-summary {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .65rem; font-size: .82rem;
}

/* Amber bawaan Bootstrap terlalu pucat di atas kertas putih (2,15:1).
   Token --accent-warn menyesuaikan diri dengan mode terang/gelap. */
.text-warning { color: var(--accent-warn) !important; }
