/*
 * Kerangka Dashboard (AppShell) — Phase 2 program redesign UI/UX v2.
 * Aturan: docs/32_UI_GUIDELINE.md §2.1 (breakpoint, sidebar 256px) dan §3 "Kerangka Dashboard".
 * Hanya tata letak; tampilan komponen ada di ds.css. Warna hanya lewat token --ds-*.
 *
 * Breakpoint:
 *   ≥1024px  sidebar tetap di kiri; bisa diciutkan menjadi deretan ikon (data-sidebar="collapsed")
 *   <1024px  sidebar menjadi laci yang dibuka tombol menu (data-nav-open="true")
 */

.dash-app.ds-app {
  --ds-topbar-height: 64px;
  --ds-sticky-top: var(--ds-topbar-height);
  display: grid;
  grid-template-columns: var(--ds-sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  /* Kolom sidebar berlatar putih sepanjang halaman (sidebar sendiri lengket setinggi layar), dengan
     garis batas yang menerus di sisi kanannya. */
  background: linear-gradient(90deg,
    var(--ds-color-surface) 0 calc(var(--ds-sidebar-width) - 1px),
    var(--ds-color-border) calc(var(--ds-sidebar-width) - 1px) var(--ds-sidebar-width),
    var(--ds-color-bg) var(--ds-sidebar-width));
}
.dash-app.ds-app[hidden] { display: none; }
.dash-app.ds-app[data-sidebar="collapsed"] { --ds-sidebar-width: 76px; }

/* --- Tautan lompat ke isi -------------------------------------------------------------------- */
.ds-skip-link {
  position: absolute;
  left: var(--ds-space-2);
  top: -100px;
  z-index: 2000;
  padding: var(--ds-space-2) var(--ds-space-4);
  border-radius: var(--ds-radius-input);
  background: var(--ds-color-primary-strong);
  color: var(--ds-color-on-strong);
  font-weight: 600;
  text-decoration: none;
}
.ds-skip-link:focus { top: var(--ds-space-2); }

/* --- Sidebar --------------------------------------------------------------------------------- */
.ds-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--ds-color-border);
  background: var(--ds-color-surface);
  z-index: 900;
}
.ds-sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  min-height: var(--ds-topbar-height);
  padding: 0 var(--ds-space-4);
  border-bottom: 1px solid var(--ds-color-border);
}
.ds-sidebar-brand img { width: 34px; height: auto; flex: none; } /* logo Majene BERWARNA */
.ds-sidebar-brand b { display: block; font-size: var(--ds-font-size-body); line-height: 1.3; }
.ds-sidebar-brand span { display: block; font-size: var(--ds-font-size-caption); color: var(--ds-color-text-muted); }

.ds-nav { flex: 1; padding: var(--ds-space-3) var(--ds-space-3) var(--ds-space-6); }
.ds-nav-group + .ds-nav-group { margin-top: var(--ds-space-4); }
.ds-nav-group-label {
  margin: 0 0 var(--ds-space-1);
  padding: 0 var(--ds-space-3);
  font-size: var(--ds-font-size-caption);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ds-color-text-muted);
}
.ds-nav-list { margin: 0; padding: 0; list-style: none; }
.ds-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  min-height: var(--ds-touch-min);
  padding: 0 var(--ds-space-3);
  border-radius: var(--ds-radius-input);
  color: var(--ds-color-text-label);
  font-weight: 600;
  text-decoration: none;
}
.ds-nav-item svg { width: 20px; height: 20px; flex: none; }
.ds-nav-item:hover { background: var(--ds-color-bg); color: var(--ds-color-primary-strong); }
.ds-nav-item[aria-current="page"] {
  background: var(--ds-color-primary-soft);
  color: var(--ds-color-primary-strong);
}
.ds-nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--ds-color-primary-strong);
}
.ds-nav-label { flex: 1; min-width: 0; line-height: 1.25; }
.ds-nav-external { display: inline-flex; color: var(--ds-color-text-muted); }
.ds-nav-external svg { width: 14px; height: 14px; }
.ds-nav-badge {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: var(--ds-radius-chip);
  background: var(--ds-color-warning-bg);
  color: var(--ds-color-warning-text);
  font-size: var(--ds-font-size-caption);
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.ds-sidebar-foot {
  padding: var(--ds-space-3);
  border-top: 1px solid var(--ds-color-border);
}
.ds-collapse-btn {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  width: 100%;
  min-height: var(--ds-touch-min);
  padding: 0 var(--ds-space-3);
  border: none;
  border-radius: var(--ds-radius-input);
  background: transparent;
  color: var(--ds-color-text-muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.ds-collapse-btn svg { width: 20px; height: 20px; flex: none; }
.ds-collapse-btn:hover { background: var(--ds-color-bg); color: var(--ds-color-primary-strong); }

/* Sidebar diciutkan: ikon saja; label tetap ada untuk pembaca layar (bukan display:none). */
.ds-app[data-sidebar="collapsed"] .ds-sidebar-brand div,
.ds-app[data-sidebar="collapsed"] .ds-nav-label,
.ds-app[data-sidebar="collapsed"] .ds-nav-group-label,
.ds-app[data-sidebar="collapsed"] .ds-nav-external,
.ds-app[data-sidebar="collapsed"] .ds-collapse-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.ds-app[data-sidebar="collapsed"] .ds-sidebar-brand { justify-content: center; padding: 0; }
.ds-app[data-sidebar="collapsed"] .ds-nav-item,
.ds-app[data-sidebar="collapsed"] .ds-collapse-btn { justify-content: center; padding: 0; }
.ds-app[data-sidebar="collapsed"] .ds-nav-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  padding: 0 5px;
  font-size: 11px;
}
.ds-app[data-sidebar="collapsed"] .ds-collapse-btn svg { transform: scaleX(-1); }

.ds-sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--ds-z-drawer) - 1);
  background: var(--ds-backdrop);
}

/* --- Ruang kerja: topbar + isi --------------------------------------------------------------- */
.ds-workspace { display: flex; flex-direction: column; min-width: 0; }

.ds-topbar {
  position: sticky;
  top: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  gap: var(--ds-space-4);
  min-height: var(--ds-topbar-height);
  padding: var(--ds-space-2) var(--ds-space-6);
  border-bottom: 1px solid var(--ds-color-border);
  background: var(--ds-color-surface);
}
.ds-menu-btn,
.ds-icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--ds-touch-min);
  height: var(--ds-touch-min);
  flex: none;
  border: 1px solid var(--ds-color-border-strong);
  border-radius: var(--ds-radius-input);
  background: var(--ds-color-surface);
  color: var(--ds-color-text-label);
  cursor: pointer;
}
.ds-menu-btn svg,
.ds-icon-btn svg { width: 20px; height: 20px; }
.ds-menu-btn { display: none; }
.ds-notif-btn { position: relative; }
.ds-notif-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--ds-color-danger-text);
  color: var(--ds-color-surface);
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.ds-notif-count[hidden] { display: none; }
.ds-icon-btn-danger { color: var(--ds-color-danger-text); }
.ds-icon-btn-danger:hover { background: var(--ds-color-danger-bg); border-color: var(--ds-color-danger-solid); }

.ds-topbar-titles { min-width: 0; flex: 1; }
.ds-breadcrumb {
  margin: 0;
  font-size: var(--ds-font-size-caption);
  color: var(--ds-color-text-muted);
}
.ds-topbar-title {
  margin: 0;
  font-size: var(--ds-font-size-section);
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ds-topbar-date {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-topbar-date label { font-weight: 600; color: var(--ds-color-text-label); }
.ds-topbar-date .ds-input { width: 168px; }
.ds-topbar-sub { display: block; font-size: var(--ds-font-size-caption); color: var(--ds-color-text-muted); }

.ds-conn {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: 4px 12px;
  border-radius: var(--ds-radius-chip);
  background: var(--ds-color-success-bg);
  color: var(--ds-color-success-text);
  font-size: var(--ds-font-size-caption);
  font-weight: 600;
  white-space: nowrap;
}
.ds-conn::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ds-color-success-solid);
}
.ds-conn[data-state="offline"] { background: var(--ds-color-warning-bg); color: var(--ds-color-warning-text); }
.ds-conn[data-state="offline"]::before { background: var(--ds-color-warning-solid); }

.ds-user { display: flex; align-items: center; gap: var(--ds-space-2); min-width: 0; }
.ds-user-text { line-height: 1.25; min-width: 0; }
.ds-user-text b { display: block; font-size: var(--ds-font-size-body); }
.ds-user-text span { display: block; font-size: var(--ds-font-size-caption); color: var(--ds-color-text-muted); }

/* Pencarian global dan notifikasi berada di laci modal DS (Phase 11). */
.ds-global-body { margin-top: var(--ds-space-4); }
.ds-global-group { margin-bottom: var(--ds-space-6); }
.ds-global-group h3 { margin: 0 0 var(--ds-space-2); font-size: var(--ds-font-size-body); }
.ds-global-results, .ds-notif-list { margin: 0; padding: 0; list-style: none; }
.ds-global-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--ds-space-3);
  min-height: var(--ds-touch-min);
  padding: var(--ds-space-2) var(--ds-space-3);
  border-radius: var(--ds-radius-input);
  color: var(--ds-color-primary-strong);
  text-decoration: none;
}
.ds-global-result:hover, .ds-global-result:focus-visible { background: var(--ds-color-primary-soft); }
.ds-global-result small, .ds-global-muted { color: var(--ds-color-text-muted); font-size: var(--ds-font-size-caption); }
.ds-global-muted { margin: var(--ds-space-2) 0; }
.ds-global-actions { display: flex; justify-content: flex-end; margin-bottom: var(--ds-space-3); }
.ds-notif-item { padding: var(--ds-space-4) 0; border-top: 1px solid var(--ds-color-border); }
.ds-notif-head, .ds-notif-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--ds-space-3); }
.ds-notif-head strong { min-width: 0; overflow-wrap: anywhere; }
.ds-notif-item p { margin: var(--ds-space-2) 0; overflow-wrap: anywhere; }
.ds-notif-foot time { color: var(--ds-color-text-muted); font-size: var(--ds-font-size-caption); }
.ds-notif-more { width: 100%; margin-top: var(--ds-space-4); }

.ds-main { flex: 1; min-width: 0; padding: var(--ds-space-6); outline: none; }
.ds-content { max-width: 1440px; margin: 0 auto; }
.ds-route-back { display: flex; justify-content: center; margin: 0 0 var(--ds-space-8); }

/* Kartu administrasi lama masih dipakai dalam halaman baru. */
.ds-app .dash-card { margin-bottom: var(--ds-space-6); }

/* --- Tablet & ponsel: sidebar menjadi laci --------------------------------------------------- */
@media (max-width: 1023.98px) {
  .dash-app.ds-app,
  .dash-app.ds-app[data-sidebar="collapsed"] {
    --ds-sidebar-width: min(300px, 86vw);
    grid-template-columns: minmax(0, 1fr);
    background: var(--ds-color-bg);
  }
  .ds-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--ds-sidebar-width);
    height: auto;
    z-index: var(--ds-z-drawer);
    transform: translateX(-100%);
    transition: transform var(--ds-transition);
    box-shadow: var(--ds-shadow-md);
  }
  .ds-app[data-nav-open="true"] .ds-sidebar { transform: none; }
  .ds-menu-btn { display: inline-grid; }
  .ds-sidebar-foot { display: none; }
  /* Mode ciut tidak berlaku di laci: label selalu tampil. */
  .ds-app[data-sidebar="collapsed"] .ds-sidebar-brand div,
  .ds-app[data-sidebar="collapsed"] .ds-nav-label,
  .ds-app[data-sidebar="collapsed"] .ds-nav-group-label,
  .ds-app[data-sidebar="collapsed"] .ds-nav-external {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
  .ds-app[data-sidebar="collapsed"] .ds-sidebar-brand { justify-content: flex-start; padding: 0 var(--ds-space-4); }
  .ds-app[data-sidebar="collapsed"] .ds-nav-item { justify-content: flex-start; padding: 0 var(--ds-space-3); }
  .ds-app[data-sidebar="collapsed"] .ds-nav-badge { position: static; }
  .ds-topbar { padding: var(--ds-space-2) var(--ds-space-4); gap: var(--ds-space-3); }
  .ds-main { padding: var(--ds-space-4); }
}

@media (max-width: 767.98px) {
  /* Baris 1: menu · judul · koneksi · avatar · keluar. Baris 2: tanggal selebar layar. */
  .ds-topbar { flex-wrap: wrap; row-gap: var(--ds-space-2); column-gap: var(--ds-space-2); }
  .ds-topbar-titles { flex: 1 1 0; }
  .ds-user-text { display: none; }
  /* Titik status koneksi tetap terlihat; teksnya tetap terbaca pembaca layar. */
  .ds-conn { padding: 4px 8px; }
  .ds-conn .ds-conn-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .ds-topbar-date { order: 5; flex: 1 1 100%; }
  .ds-topbar-date .ds-input { flex: 1; width: auto; }
}

@media (max-width: 479.98px) {
  .ds-topbar { padding: var(--ds-space-2) var(--ds-space-3); }
  .ds-user { display: none; }
  .ds-topbar-titles { flex-basis: 72px; }
  .ds-global-result { align-items: flex-start; flex-direction: column; gap: 0; }
  .ds-notif-head, .ds-notif-foot { align-items: flex-start; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .ds-sidebar { transition: none; }
}
