/* ==========================================================================
   KAPROD INTERNAL — LAYOUT & THEME (v4)
   --------------------------------------------------------------------------
   <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">

   Daftar isi
   1. Token (warna, ukuran, motion)
   2. Reset & dasar
   3. Shell & Sidebar
   3b. Sidebar Tree Navigation (REVISI PILAR & DIVISI)
   4. Form, chip, tombol menu
   5. Area utama & header
   6. Strip, card, tabel
   7. Modal, overlay, toast
   8. Animasi
   9. Responsive: tablet -> mobile -> HP kecil -> layar pendek
   10. Aksesibilitas
   ========================================================================== */


/* ==========================================================================
   1. TOKEN
   ========================================================================== */
/* Token dipindah ke variables.css (satu-satunya sumber). Jangan definisikan ulang di sini. */


/* ==========================================================================
   2. RESET & DASAR
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-tap-highlight-color: transparent;
}

/* Cegah teks membesar sendiri saat HP diputar (iOS Safari + Chrome Android) */
@supports (-webkit-text-size-adjust: 100%) or (text-size-adjust: 100%) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
}

/* Scrollbar tipis standar (Firefox, Chrome 121+, Safari 18.2+);
   browser lain memakai fallback ::-webkit-scrollbar di bawah */
@supports (scrollbar-width: thin) {
  html {
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
  }
}

html, body {
  width: 100%;
  height: var(--app-h) !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  background: var(--bg) !important;
  color: var(--ink) !important;
  font-family: var(--font) !important;
  scroll-behavior: auto !important;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Fallback scrollbar untuk browser yang belum support scrollbar-width */
@supports not (scrollbar-width: thin) {
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
}

:where(h1, h2, h3, .brand-title) { font-family: var(--display); letter-spacing: -.01em; }
:where(table, .strip) { font-variant-numeric: tabular-nums; }

:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}


/* ==========================================================================
   3. SHELL & SIDEBAR
   ========================================================================== */
.shell {
  position: relative;
  display: flex;
  width: 100%;
  height: var(--app-h);
  overflow: hidden;
  background: var(--bg);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  padding: 16px 12px;
  overflow: hidden;
  overscroll-behavior: contain;
  background: var(--side);
  color: var(--side-ink);
  border-right: 1px solid var(--side-line);
  transition: background-color var(--t-med) ease, border-color var(--t-med) ease;
}

/* ---- Brand ---- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-bottom: 14px;
  padding: 2px 4px 14px;
  border-bottom: 1px solid var(--side-line);
}
.brand-mark {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px var(--brand-line);
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-text  { min-width: 0; flex: 1 1 auto; }
.brand-title { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.2; }
.brand-sub   { margin-top: 2px; font-size: 11px; color: var(--ink-3); }

/* ---- Pencarian ---- */
.sidebar-search-box { flex-shrink: 0; margin-bottom: 12px; display: flex; gap: 6px; }
.search-field { position: relative; flex: 1 1 auto; min-width: 0; }
.sidebar-search-input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--side-line);
  border-radius: var(--r-s);
  background: var(--surface-2) var(--icon-search) no-repeat 10px center / 14px;
  color: var(--side-ink);
  font-size: 12px;
  outline: none;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.sidebar-search-input::placeholder { color: var(--ink-3); }
.sidebar-search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.search-kbd {
  position: absolute;
  top: 50%;
  right: 8px;
  translate: 0 -50%;
  padding: 1px 6px;
  border: 1px solid var(--side-line);
  border-radius: 5px;
  color: var(--ink-3);
  font: 500 10.5px/1.6 var(--font);
  pointer-events: none;
}
.search-clear {
  position: absolute;
  top: 50%;
  right: 4px;
  translate: 0 -50%;
  display: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
}
.search-clear svg { width: 14px; height: 14px; }
.search-clear:hover { background: var(--surface-3); color: var(--ink); }
.search-field.has-value .search-kbd { display: none; }
.search-field.has-value .search-clear { display: grid; }

/* ---- Menu (area scroll) ---- */
.sidebar-nav-scroll {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 -4px 10px 0;
  padding-right: 4px;
  overflow: hidden auto;
  overscroll-behavior: contain;
}

/* ---- Footer sidebar ---- */
.sidebar-footer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--side-line);
}
.sidebar-footer > * { min-width: 0; margin: 0; }

.sidebar-user-box {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-m);
  background: var(--surface-2);
}
.sidebar-user-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 12px;
  font-weight: 700;
}
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.sidebar-user-name,
.sidebar-user-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-name { font-size: 12.5px; font-weight: 600; color: var(--side-ink); }
.sidebar-user-role { font-size: 11px; color: var(--ink-3); }

.sidebar-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid var(--side-line);
  border-radius: var(--r-s);
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease,
              border-color var(--t-fast) ease, scale var(--t-fast) ease;
}
.sidebar-action-btn svg { flex: none; width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }
.sidebar-action-btn:hover    { color: var(--ink); border-color: var(--line-strong); background: var(--surface-3); }
.sidebar-action-btn:active   { scale: .97; }
.sidebar-action-btn:disabled { opacity: .6; cursor: wait; }
.sidebar-action-btn.logout-btn:hover {
  background: var(--err-soft);
  color: var(--err);
  border-color: rgb(239 68 68 / .3);
}


/* ==========================================================================
   3b. SIDEBAR — TREE VIEW NAVIGATION (REVISI PILAR & SUB-DIVISI)
   ========================================================================== */

/* Ikon: semua svg di sidebar punya gaya dasar yang sama */
:where(.sidebar) svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Tombol ikon kecil ---- */
.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--r-s);
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease, scale var(--t-fast) ease;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { scale: .92; }
.brand-close { display: none; }

/* ---- Header Pilar (Muted, Kecil, Clean) ---- */
.nav-pilar-group {
  margin-bottom: 12px;
}

.pilar-header {
  font-size: 10px !important;
  font-weight: 700 !important;
  letter-spacing: 0.1em !important;
  color: var(--ink-3) !important;
  padding: 10px 8px 4px 8px !important;
  text-transform: uppercase !important;
  opacity: 0.75;
}

.nav-pilar-group:first-child .pilar-header {
  padding-top: 2px !important;
}

.pilar-divisions-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ---- Folder Sub-Divisi Header ---- */
.nav-group-head {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  width: 100% !important;
  margin: 1px 0 !important;
  padding: 6px 8px !important;
  border: 0 !important;
  border-radius: var(--r-s) !important;
  background: transparent !important;
  color: var(--ink-2) !important;
  font-family: inherit !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  text-align: left !important;
  cursor: pointer !important;
  transition: color var(--t-fast) ease, background-color var(--t-fast) ease !important;
}

.nav-group-head:hover {
  background: var(--surface-2) !important;
  color: var(--ink) !important;
}

.nav-group-head svg {
  width: 14px !important;
  height: 14px !important;
  color: var(--ink-3) !important;
  flex-shrink: 0;
}

.nav-group-head span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron-icon {
  width: 13px !important;
  height: 13px !important;
  margin-left: auto;
  transition: transform var(--t-fast) ease !important;
}

/* ---- Tree Guide Line & Indentasi Anak Modul ---- */
.nav-group-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--t-med) var(--ease);
}

.nav-group[data-open="false"] > .nav-group-body {
  grid-template-rows: 0fr;
}

.nav-group-inner {
  min-height: 0;
  overflow: hidden;
  margin-left: 15px !important;
  padding-left: 8px !important;
  border-left: 1px solid var(--side-line) !important; /* Garis pohon vertikal */
  display: flex !important;
  flex-direction: column !important;
  gap: 2px !important;
  margin-top: 2px !important;
  margin-bottom: 4px !important;
}

/* ---- Modul Item (Anak Folder) ---- */
.nav-row {
  position: relative;
  width: 100%;
}

.nav-item {
  position: relative !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  width: 100% !important;
  margin-bottom: 2px !important;
  padding: 6px 8px !important;
  border: 0 !important;
  border-radius: var(--r-s) !important;
  background: transparent !important;
  color: var(--ink-2) !important;
  font-family: inherit !important;
  font-size: 12px !important;
  font-weight: 400 !important;
  text-decoration: none !important;
  cursor: pointer !important;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease !important;
}

.nav-item::before {
  display: none !important; /* Matikan garis tebal samping lama */
}

.nav-item:hover:not(.disabled) {
  background: var(--surface-2) !important;
  color: var(--ink) !important;
}

.nav-item svg {
  width: 14px !important;
  height: 14px !important;
  color: var(--ink-3) !important;
  flex-shrink: 0;
}

.nav-item-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Status Item Aktif */
.nav-item.active {
  background: var(--brand-soft) !important;
  color: var(--brand-ink) !important;
  font-weight: 600 !important;
}

.nav-item.active svg {
  color: var(--brand) !important;
}

.nav-item.disabled {
  opacity: .45 !important;
  cursor: not-allowed !important;
}

.badge-soon {
  margin-left: auto;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink-3);
  border: 1px solid var(--side-line);
}

/* Pin Button */
.pin-btn {
  position: absolute;
  top: 50%;
  right: 4px;
  translate: 0 -50%;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-3);
  opacity: 0;
  cursor: pointer;
  transition: opacity var(--t-fast) ease, color var(--t-fast) ease;
}
.pin-btn svg { width: 12px !important; height: 12px !important; }
.nav-row:hover .pin-btn,
.nav-row:focus-within .pin-btn,
.pin-btn.pinned { opacity: 1; }
.pin-btn:hover { background: var(--surface-3); color: var(--brand-ink); }
.pin-btn.pinned { color: var(--brand); }
.pin-btn.pinned svg { fill: currentColor; }

.nav-item mark {
  padding: 0 1px;
  border-radius: 3px;
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.nav-empty {
  padding: 24px 12px;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}
.nav-empty-clear {
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand-ink);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* ---- Mode Rail Collapsed (Desktop) ---- */
@media (min-width: 1025px) {
  :root[data-sidebar="collapsed"] { --sidebar-w: 72px; }

  [data-sidebar="collapsed"] .sidebar { padding-inline: 8px; }
  [data-sidebar="collapsed"] .brand { flex-direction: column; gap: 8px; padding-inline: 0; }
  [data-sidebar="collapsed"] .brand-collapse svg { rotate: 180deg; }

  [data-sidebar="collapsed"] :is(
    .brand-text, .sidebar-search-box, .pilar-header, .nav-group-head span, .chevron-icon,
    .nav-item-text, .badge-soon, .pin-btn, .sidebar-user-info, .sidebar-action-btn span
  ) { display: none !important; }

  [data-sidebar="collapsed"] .nav-group-inner {
    margin-left: 0 !important;
    padding-left: 0 !important;
    border-left: none !important;
  }

  [data-sidebar="collapsed"] .nav-row .nav-item { justify-content: center; padding: 8px 0 !important; }
  [data-sidebar="collapsed"] .sidebar-footer { grid-template-columns: minmax(0, 1fr); }
  [data-sidebar="collapsed"] .sidebar-user-box { justify-content: center; padding: 6px; }
}


/* ==========================================================================
   4. FORM, CHIP, TOMBOL MENU
   ========================================================================== */

/* :where() = specificity 0, jadi class apa pun (mis. input group + ikon)
   bisa menimpa tanpa perlu !important. */
:where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"],
                 [type="color"], [type="button"], [type="submit"], [type="reset"], [type="image"]),
       select, textarea) {
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  background-color: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease, background-color var(--t-fast) ease;
}
:where(input, select, textarea):hover:not(:focus, :disabled) { border-color: var(--line-strong); }
:where(input, select, textarea):focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
:where(input, select, textarea):disabled { opacity: .55; cursor: not-allowed; }
:where(input)::placeholder, :where(textarea)::placeholder { color: var(--ink-3); }
:where(input[type="checkbox"], input[type="radio"]) { accent-color: var(--brand); }
:where(textarea) { resize: vertical; }

/* ---- Chip & badge ---- */
.chip, .badge-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}
.chip.brand, .badge-chip.brand { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand-line); }
.chip.ok,    .badge-chip.ok    { background: var(--ok-soft);    color: var(--ok);        border-color: rgb(16 185 129 / .28); }

.badge-soon {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 9px;
}

/* ---- Tombol hamburger (specificity 0: style lama di HTML tetap menang) ---- */
:where(.mobile-menu-btn) {
  display: none;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background-color var(--t-fast) ease, scale var(--t-fast) ease;
}
:where(.mobile-menu-btn):hover  { background: var(--surface-2); }
:where(.mobile-menu-btn):active { scale: .94; }


/* ==========================================================================
   5. AREA UTAMA & HEADER
   ========================================================================== */
.main {
  position: absolute;
  inset: 0 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  overflow: hidden auto;
  overscroll-behavior: contain;
  background: var(--bg);
}
@supports (scrollbar-gutter: stable) {
  .main { scrollbar-gutter: stable; }
}

/* Header Sticky */
.main-header-sticky {
  position: sticky;
  top: 0;
  z-index: 100;
  flex: 0 0 auto;
  margin: 0;
  padding: 14px var(--pad-x);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transition: padding 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

@supports (background: color-mix(in srgb, red, blue)) {
  .main-header-sticky {
    background: color-mix(in srgb, var(--bg) 88%, transparent);
  }
}

.main-header-sticky.is-scrolled {
  padding: 10px var(--pad-x);
  box-shadow: var(--shadow);
}

.header-container-flex { display: flex; justify-content: space-between; align-items: center; gap: 16px; width: 100%; min-width: 0; }
.header-left-wrap { display: flex; align-items: center; gap: 12px; flex: 1 1 auto; min-width: 0; }
.header-left { flex: 1 1 auto; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; position: relative; }

.main-header-sticky #pageTitle {
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  font-family: var(--display);
  line-height: 1.25;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-header-sticky #pageSub {
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.35;
  margin: 2px 0 0 0;
  max-height: 38px;
  opacity: 1;
  overflow: hidden;
  transition: all 0.2s ease;
}

.main-header-sticky.is-scrolled #pageSub {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  pointer-events: none;
}

.header-unit { font-size: 11px; font-weight: 700; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }

.header-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-s);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  font-size: 15px;
  transition: all 0.15s ease;
}
.header-icon-btn:hover { background: var(--surface); border-color: var(--brand); color: var(--brand); }

.header-user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}
.header-user-pill:hover, .header-user-pill.active { border-color: var(--brand); background: var(--surface); }

.header-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 700;
  font-size: 11px;
  display: grid;
  place-items: center;
}
.header-user-meta { display: flex; flex-direction: column; line-height: 1.1; }
.header-user-name { font-size: 12px; font-weight: 600; color: var(--ink); }
.header-user-role { font-size: 10px; color: var(--brand); font-weight: 700; letter-spacing: 0.5px; }

/* Profile Dropdown Card */
.profile-dropdown-card {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 330px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-pop);
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 12px;
  z-index: 1000;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  animation: pop-in 0.18s var(--ease) forwards;
}
.profile-dropdown-card.show { display: flex; }

.profile-info-box {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-detail-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-2);
  gap: 12px;
}

.profile-detail-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 90px;
  color: var(--ink-2);
  font-weight: 500;
}

.profile-detail-value {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  word-break: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
  flex: 1;
}

#viewContainer,
.dashboard-wrapper {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: var(--pad-y)
           max(var(--pad-x), var(--safe-right))
           calc(var(--pad-y) + var(--safe-bottom))
           max(var(--pad-x), var(--safe-left));
}
#viewContainer > *,
.dashboard-wrapper > * { min-width: 0; max-width: 100%; }

#viewContainer .dashboard-wrapper { padding: 0; }


/* ==========================================================================
   6. STRIP, CARD, TABEL
   ========================================================================== */

/* Strip statistik: kolom otomatis (4 -> 2 -> 1) tanpa media query.
   Garis pemisah memakai trik margin negatif, jadi rapi di jumlah item berapa pun. */
.strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  flex-shrink: 0;
  margin-bottom: var(--gap);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.strip > div {
  min-width: 0;
  margin: -1px 0 0 -1px;
  padding: 18px 22px;
  border: solid var(--line);
  border-width: 1px 0 0 1px;
  overflow-wrap: anywhere;
}

.card {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 100%;
  min-width: 0;
  margin-bottom: var(--gap);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.card-header {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.card-header > * { min-width: 0; }

.strip, .card, .table-wrap {
  transition: background-color var(--t-med) ease, border-color var(--t-med) ease;
}

/* ---- Tabel ---- */
.table-wrap {
  flex-shrink: 0;
  width: 100%;
  min-height: 200px;
  max-height: calc(100vh - 280px);
  max-height: calc(100dvh - 280px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: var(--surface);
}
.data-table {
  width: 100%;
  border-collapse: separate;   /* sticky header + border aman saat scroll */
  border-spacing: 0;
  color: var(--ink);
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  text-align: left;
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr td { transition: background-color var(--t-fast) ease; }
.data-table tbody tr:hover td { background: var(--surface-2); }

/* ---- Blok kode ---- */
pre, .csv-preview-box {
  max-width: 100%;
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: var(--r-s);
  background: var(--code-bg);
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
}
pre code { padding: 0; background: transparent; }
code { font-size: .92em; }


/* ==========================================================================
   7. MODAL, OVERLAY, TOAST
   ========================================================================== */
#modalContainer,
#modal-container {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#modalContainer:empty,
#modal-container:empty { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.modal-backdrop > * {
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  box-shadow: var(--shadow-pop);
}
.modal-backdrop.hidden { display: none; }

/* Overlay sidebar (mobile): fade lewat opacity, bukan display */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  visibility: hidden;
  opacity: 0;
  background: var(--scrim);
  transition: opacity var(--t-med) ease, visibility 0s linear var(--t-med);
}
.overlay.on {
  visibility: visible;
  opacity: 1;
  transition: opacity var(--t-med) ease, visibility 0s;
}

.toast {
  z-index: 10001 !important;
  max-width: calc(100vw - 24px);
  margin-bottom: var(--safe-bottom);
  pointer-events: none;
  animation: toast-in .35s var(--ease) backwards;
}
.toast[data-type="error"]   { border-left: 3px solid var(--err); }
.toast[data-type="success"] { border-left: 3px solid var(--ok); }


/* ==========================================================================
   8. ANIMASI
   Memakai properti `translate` / `scale` (bukan `transform`) supaya tidak
   bentrok dengan transform yang sudah ada di elemen lain, dan hanya
   menganimasikan opacity/translate/scale agar tetap ringan (GPU).
   ========================================================================== */
@keyframes rise {
  from { opacity: 0; translate: 0 10px; }
}
@keyframes fade-in {
  from { opacity: 0; }
}
@keyframes pop-in {
  from { opacity: 0; translate: 0 14px; scale: .97; }
}
@keyframes toast-in {
  from { opacity: 0; translate: 0 12px; scale: .96; }
}
@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* Satu momen utama: isi halaman masuk berurutan saat view berganti.
   (fill-mode "backwards" => tidak meninggalkan transform setelah selesai) */
#viewContainer > * { animation: rise .45s var(--ease) backwards; }
#viewContainer > :nth-child(2) { animation-delay: .05s; }
#viewContainer > :nth-child(3) { animation-delay: .10s; }
#viewContainer > :nth-child(4) { animation-delay: .15s; }
#viewContainer > :nth-child(n+5) { animation-delay: .20s; }
/* Matikan jika view sering re-render (mis. live search): <div id="viewContainer" class="no-anim"> */
#viewContainer.no-anim > * { animation: none; }

.modal-backdrop    { animation: fade-in .2s ease; }
.modal-backdrop > * { animation: pop-in .35s var(--ease); }

/* Placeholder loading: tambahkan class "skeleton" ke elemen kosong */
.skeleton {
  border-radius: var(--r-s);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%) 0 0 / 200% 100%;
  color: transparent;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  animation: shimmer 1.4s linear infinite;
}


/* ==========================================================================
   9. RESPONSIVE
   ========================================================================== */

/* ---- Tablet & di bawahnya: sidebar jadi drawer ---- */
@media (max-width: 1024px) {
  :root { --pad-x: 16px; --pad-y: 16px; }

  .sidebar {
    z-index: 9999;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
    visibility: hidden;
    transform: translateX(-105%);
    transition: transform var(--t-med) var(--ease), visibility 0s linear var(--t-med);
  }
  .sidebar:is(.open, .active) {
    visibility: visible;
    transform: none;
    box-shadow: 8px 0 32px rgb(0 0 0 / .45);
    transition: transform var(--t-med) var(--ease), visibility 0s;
  }

  .main { left: 0; }
  :where(.mobile-menu-btn) { display: inline-grid; }
}

/* Overlay hanya relevan saat drawer dipakai */
@media (min-width: 1025px) {
  .overlay { display: none; }
}

/* ---- Mobile ---- */
@media (max-width: 768px) {
  :root { --pad-x: 12px; --gap: 12px; }

  html, body, .shell, .app-container, .main-layout { overflow-x: hidden !important; }

  .sidebar { width: min(310px, 85vw); padding-inline: 10px; }
  .nav-item { min-height: 42px; padding-block: 9px; }
  .sidebar-action-btn { min-height: 40px; }
  .nav-item :is(.badge-soon, .chip, .badge-chip) { padding: 2px 6px; font-size: 8.5px; letter-spacing: .02em; }

  .strip { border-radius: var(--r-m); }
  .strip > div { padding: 12px 14px; }

  .card { padding: 14px; border-radius: var(--r-m); }
  .card-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .card :is(h2, h3), .card-header h2, .card-title { margin: 0; font-size: 14.5px; line-height: 1.3; }
  .card :is(p, .card-sub, .text-muted) { font-size: 12px; line-height: 1.45; }

  /* Cegah auto-zoom Safari iOS + target sentuh nyaman */
  :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"],
                   [type="color"], [type="button"], [type="submit"], [type="reset"], [type="image"]),
         select, textarea),
  .sidebar-search-input {
    min-height: 42px;
    font-size: 16px;
  }

  .form-grid { grid-template-columns: 1fr !important; gap: 12px; }

  .table-wrap { max-height: 60vh; max-height: 60dvh; min-height: 0; }
  .data-table { min-width: 650px; }
  .data-table :is(th, td) { padding: 9px 10px; font-size: 12px; line-height: 1.45; }
  .data-table td[colspan] { padding-left: 14px; text-align: left; }
  .card select { width: 100%; }
  .data-table :is(select, input) { width: auto; }

  pre, .csv-preview-box { font-size: 11px; }
  code { word-break: break-word; }

  .modal-backdrop { padding: calc(10px + var(--safe-top)) 10px calc(10px + var(--safe-bottom)); }

  /* Susunan kartu & grid jadi satu kolom.
     !important dipertahankan agar mengalahkan grid/flex yang di-set inline. */
  #viewContainer > :first-child { margin-top: 0; }
  #viewContainer :has(> .card + .card) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: var(--gap) !important;
  }
  #viewContainer :has(> .card + .card) > .card { margin-bottom: 0; }
  #viewContainer [class*="grid"]:not(.strip) { grid-template-columns: minmax(0, 1fr) !important; }
}

/* ---- HP kecil ---- */
@media (max-width: 420px) {
  .sidebar { width: min(300px, 88vw); }
}

/* ---- Layar pendek (HP landscape) ---- */
@media (max-height: 520px) {
  .sidebar-user-box { display: none; }
  .brand { margin-bottom: 8px; padding-bottom: 8px; }
  .nav-item { min-height: 36px; }
}


/* ==========================================================================
   10. AKSESIBILITAS
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
} 