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

  /* Sky blue brand */
  --brand: #0ea5e9;
  --brand-dark: #0284c7;
  --brand-light: #38bdf8;
  --brand-soft: rgba(14, 165, 233, .12);

  /* 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);

  --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-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; }

/* 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); }
.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); border-color: var(--brand); color: #fff; }

.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); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark); --bs-btn-active-bg: var(--brand-dark); }
.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-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; }
