/* ==========================================================================
   NOVA Dashboard — Kerangka aplikasi: sidebar, header, panel
   ========================================================================== */

/* Catatan penting soal tinggi:
   `.app` adalah grid dan `.sidebar`/`.main` adalah grid item. Secara bawaan
   grid item memakai `min-height: auto`, artinya ia menolak menyusut di bawah
   tinggi isinya. Bila daftar di sidebar memanjang, sidebar ikut melar melewati
   tinggi layar — bagian bawahnya terpotong dan area gulirnya tidak pernah
   aktif, sekaligus menarik baris grid sehingga area konten ikut melar.
   Karena itu setiap wadah pada rantai tinggi diberi `min-height: 0`. */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100%;
  height: 100vh;
  height: 100dvh;          /* ikut menyusut saat bilah peramban seluler muncul */
  max-height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns var(--normal);
}
.app.sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  z-index: 60;
}

.brand {
  display: flex; align-items: center; gap: 11px;
  height: var(--header-h);
  padding: 0 16px;
  flex: none;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px; height: 32px; flex: none;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), hsl(calc(var(--accent-h) + 42) 78% 62%));
  display: grid; place-items: center;
  color: #fff; box-shadow: 0 2px 9px hsl(var(--accent-h) var(--accent-s) 58% / .38);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { min-width: 0; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: -.025em; line-height: 1.15; }
.brand-sub { font-size: 10.5px; color: var(--text-muted); letter-spacing: .05em; text-transform: uppercase; font-weight: 570; }

.sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;              /* wajib agar area ini yang menggulir, bukan sidebar melar */
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 12px 10px 10px;
}

.nav-group { margin-bottom: 16px; }
.nav-group-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 8px 6px; gap: 6px;
}
.nav-group-head .section-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-soft);
  font-size: 13.5px; font-weight: 530;
  transition: background var(--fast), color var(--fast);
  cursor: pointer; position: relative;
  margin-bottom: 1px;
  text-align: left;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-icon { width: 18px; height: 18px; flex: none; display: grid; place-items: center; }
.nav-icon svg { width: 17px; height: 17px; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-trail { font-size: 11px; color: var(--text-muted); font-weight: 600; flex: none; }
.nav-emoji { font-size: 15px; line-height: 1; width: 18px; text-align: center; flex: none; }

.nav-item-sub { padding-left: 20px; font-size: 13px; }
.nav-sub-list { margin: 2px 0 6px; }

/* ---------- Baris induk yang bisa dilipat ---------- */
/* Tanpa overflow:hidden — penanda aktif di tepi kiri berada di luar kotak */
.nav-item.nav-parent { padding: 0; gap: 0; }

.nav-twisty {
  flex: none;
  width: 22px; align-self: stretch;
  display: grid; place-items: center;
  color: var(--text-muted);
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  transition: color var(--fast), background var(--fast);
  cursor: pointer;
}
.nav-twisty svg {
  width: 14px; height: 14px;
  transform: rotate(90deg);                 /* terbuka: panah menghadap bawah */
  transition: transform var(--normal);
}
.nav-twisty:hover { color: var(--text); background: var(--bg-active); }
.nav-group.is-folded .nav-twisty svg { transform: rotate(0deg); }

.nav-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px 8px 4px;
  color: inherit; font: inherit; text-align: left;
  cursor: pointer;
}

/* Melipat dengan animasi tanpa perlu tahu tinggi daftarnya */
.nav-sublist {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--normal);
}
.nav-sublist-inner { min-height: 0; overflow: hidden; }
.nav-group.is-folded .nav-sublist { grid-template-rows: 0fr; }

/* Setelah animasi lipat selesai, isinya benar-benar disembunyikan supaya
   tidak ikut terjangkau tombol Tab. Saat dibuka, langsung terlihat kembali. */
.nav-group.is-folded .nav-sublist-inner {
  visibility: hidden;
  transition: visibility 0s linear 220ms;
}

.nav-empty {
  padding: 7px 10px 7px 26px;
  font-size: 11.5px; color: var(--text-muted); line-height: 1.5;
}

/* Saat sidebar diciutkan jadi ikon, panah tidak muat lagi. Status lipatnya
   tetap dihormati — pilihan pengguna, dan panahnya kembali begitu sidebar
   dilebarkan lagi. */
.app.sidebar-collapsed .nav-twisty { display: none; }
.app.sidebar-collapsed .nav-main { justify-content: center; padding: 9px 0; }
.app.sidebar-collapsed .nav-empty { display: none; }

.sidebar-foot {
  flex: 0 0 auto; padding: 10px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-surface);
}

.add-menu-btn {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px dashed var(--border-strong);
  color: var(--text-muted); font-size: 13px; font-weight: 530;
  transition: all var(--fast); cursor: pointer;
}
.add-menu-btn:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.add-menu-btn svg { width: 16px; height: 16px; flex: none; }

/* Sidebar terlipat */
.app.sidebar-collapsed .brand-text,
.app.sidebar-collapsed .nav-label,
.app.sidebar-collapsed .nav-trail,
.app.sidebar-collapsed .nav-group-head .section-label,
.app.sidebar-collapsed .add-menu-btn span,
.app.sidebar-collapsed .user-chip-text { display: none; }
.app.sidebar-collapsed .nav-item,
.app.sidebar-collapsed .add-menu-btn { justify-content: center; padding: 9px 0; }
.app.sidebar-collapsed .brand { justify-content: center; padding: 0; }
.app.sidebar-collapsed .nav-group-head { justify-content: center; }
.app.sidebar-collapsed .nav-item-sub { padding-left: 0; }
.app.sidebar-collapsed .user-chip { justify-content: center; }

/* ---------- Area utama ---------- */
.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  height: 100%; max-height: 100%;
  overflow: hidden;
}

.header {
  display: flex; align-items: center; gap: 12px;
  height: var(--header-h); flex: none;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}
.header-title { min-width: 0; }
.header-title h1 { font-size: 17px; font-weight: 660; letter-spacing: -.02em; }
.header-title .crumb { font-size: 12px; color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; }

.search-trigger {
  display: flex; align-items: center; gap: 9px;
  height: 34px; padding: 0 11px; min-width: 210px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg-sunken); color: var(--text-muted);
  font-size: 13px; cursor: pointer; transition: all var(--fast);
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.search-trigger svg { width: 15px; height: 15px; flex: none; }
.search-trigger .kbd { margin-left: auto; }

.content {
  flex: 1 1 auto;
  min-height: 0;              /* pasangan dari flex:1 — tanpa ini area tidak menggulir */
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
}
.page {
  padding: 22px 24px;
  padding-bottom: max(72px, env(safe-area-inset-bottom, 0px));
  max-width: 1480px;
  margin: 0 auto;
  animation: fade-in 200ms var(--ease);
}
.page-narrow { max-width: 1060px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); font-size: 13.5px; margin-top: 3px; }

/* ---------- Lonceng notifikasi ---------- */
.bell-wrap { position: relative; }
.bell-btn.has-unread svg { animation: bell-swing 2.4s var(--ease) 1s 2; transform-origin: top center; }
.bell-dot {
  position: absolute; top: 3px; right: 3px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--danger); color: #fff;
  font-size: 9.5px; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--bg-surface);
  line-height: 1;
}

.notif-panel {
  position: fixed; z-index: 950;
  width: 396px; max-width: calc(100vw - 24px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
  max-height: min(560px, calc(100dvh - 90px));
  overflow: hidden;
  animation: pop-in 170ms var(--ease);
}
.notif-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 15px; border-bottom: 1px solid var(--border); flex: none;
}
.notif-tabs { display: flex; gap: 3px; padding: 8px 10px 0; flex: none; }
.notif-tabs button {
  padding: 5px 10px; border-radius: var(--r-xs); font-size: 12.5px; font-weight: 550;
  color: var(--text-muted); transition: all var(--fast);
}
.notif-tabs button:hover { background: var(--bg-hover); color: var(--text); }
.notif-tabs button.active { background: var(--accent-soft); color: var(--accent-text); }
.notif-list { overflow-y: auto; padding: 8px; flex: 1; }

.notif-item {
  display: flex; gap: 11px; padding: 10px 11px;
  border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--fast); position: relative;
  width: 100%; text-align: left;
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread { background: var(--accent-soft); }
.notif-item.unread:hover { background: var(--accent-soft-2); }
.notif-avatar {
  width: 34px; height: 34px; flex: none; border-radius: var(--r-sm);
  display: grid; place-items: center; font-size: 16px;
}
.notif-avatar svg { width: 17px; height: 17px; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 13.2px; font-weight: 570; line-height: 1.4; }
.notif-desc { font-size: 12px; color: var(--text-soft); margin-top: 1px; line-height: 1.45; }
.notif-time { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.notif-close { opacity: 0; transition: opacity var(--fast); flex: none; align-self: flex-start; }
.notif-item:hover .notif-close { opacity: 1; }
.notif-foot { padding: 9px 12px; border-top: 1px solid var(--border); flex: none; background: var(--bg-surface-2); }

/* ---------- Command palette ---------- */
.palette-overlay {
  position: fixed; inset: 0; z-index: 980;
  background: rgba(13, 16, 27, .42); backdrop-filter: blur(5px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 90px 20px 20px;
  animation: fade-in 140ms var(--ease);
}
[data-theme="dark"] .palette-overlay { background: rgba(0, 0, 0, .6); }
.palette {
  width: min(620px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden; display: flex; flex-direction: column;
  max-height: min(480px, calc(100dvh - 130px));
  animation: pop-in 180ms var(--ease);
}
.palette-input-row {
  display: flex; align-items: center; gap: 11px;
  padding: 14px 17px; border-bottom: 1px solid var(--border); flex: none;
}
.palette-input-row svg { width: 18px; height: 18px; color: var(--text-muted); flex: none; }
.palette-input {
  flex: 1; border: none; background: none; font-size: 15.5px; outline: none; min-width: 0;
}
.palette-input::placeholder { color: var(--text-muted); }
.palette-results { overflow-y: auto; padding: 7px; flex: 1; }
.palette-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 9px 11px; border-radius: var(--r-sm);
  text-align: left; cursor: pointer; transition: background var(--fast);
}
.palette-item:hover, .palette-item.focus { background: var(--bg-hover); }
.palette-item.focus { background: var(--accent-soft); }
.palette-icon {
  width: 30px; height: 30px; flex: none; border-radius: var(--r-xs);
  display: grid; place-items: center; background: var(--bg-sunken); font-size: 14px;
}
.palette-icon svg { width: 15px; height: 15px; color: var(--text-soft); }
.palette-text { flex: 1; min-width: 0; }
.palette-title { font-size: 13.5px; font-weight: 550; }
.palette-sub { font-size: 11.5px; color: var(--text-muted); }
.palette-foot {
  padding: 8px 14px; border-top: 1px solid var(--border);
  background: var(--bg-surface-2); flex: none;
  display: flex; gap: 14px; font-size: 11px; color: var(--text-muted);
}

/* ---------- Chip pengguna ---------- */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px; border-radius: var(--r-sm);
  cursor: pointer; transition: background var(--fast); width: 100%;
}
.user-chip:hover { background: var(--bg-hover); }
.user-chip-text { min-width: 0; flex: 1; text-align: left; }
.user-chip-name { font-size: 13px; font-weight: 570; }
.user-chip-sub { font-size: 11px; color: var(--text-muted); }

/* ---------- Responsif ---------- */
.sidebar-backdrop { display: none; }

@media (max-width: 980px) {
  .app, .app.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform var(--normal);
    box-shadow: var(--shadow-lg);
  }
  .app.mobile-open .sidebar { transform: none; }
  .app.mobile-open .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(13, 16, 27, .45); animation: fade-in 160ms var(--ease);
  }
  .app.sidebar-collapsed .brand-text,
  .app.sidebar-collapsed .nav-label,
  .app.sidebar-collapsed .nav-trail,
  .app.sidebar-collapsed .add-menu-btn span,
  .app.sidebar-collapsed .user-chip-text { display: revert; }
  .app.sidebar-collapsed .nav-item,
  .app.sidebar-collapsed .add-menu-btn { justify-content: flex-start; padding: 8px 10px; }
  .app.sidebar-collapsed .nav-item.nav-parent { padding: 0; }
  .app.sidebar-collapsed .nav-twisty { display: grid; }
  .app.sidebar-collapsed .nav-main { justify-content: flex-start; padding: 8px 10px 8px 4px; }
  .app.sidebar-collapsed .nav-empty { display: block; }
  .app.sidebar-collapsed .brand { justify-content: flex-start; padding: 0 16px; }
  .search-trigger { min-width: 0; width: 34px; padding: 0; justify-content: center; }
  .search-trigger span, .search-trigger .kbd { display: none; }
  .page { padding: 16px 14px 60px; }
  .header { padding: 0 12px; }
}
@media (min-width: 981px) { .menu-toggle { display: none; } }
