/* ============================================================
   HYFIS V3 - Main Stylesheet (Design System + Layout)
   ============================================================ */

:root {
  /* Palette */
  --bg:            #0a0a0f;
  --surface:       #12121a;
  --surface-2:     #1a1a2e;
  --surface-3:     #222234;
  --border:        rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --glass-bg:      rgba(255, 255, 255, 0.03);

  --text:          #e6e8f0;
  --text-muted:    #9ca3af;
  --text-dim:      #6b7280;

  --primary:       #3b82f6;
  --primary-dark:  #2563eb;
  --primary-fg:    #ffffff;

  --success:       #10b981;
  --warning:       #f59e0b;
  --orange:        #f97316;
  --danger:        #ef4444;
  --info:          #06b6d4;

  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     18px;
  --shadow-sm:     0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow:        0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg:     0 12px 40px rgba(0, 0, 0, 0.5);

  --transition:    180ms cubic-bezier(.4, 0, .2, 1);

  --sidebar-w:     260px;
  --topbar-h:      64px;
}

/* -----------------------------------------------------------
   RESET
   ----------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

h1, h2, h3, h4 { margin: 0 0 0.5em; letter-spacing: -0.02em; line-height: 1.25; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

p { margin: 0 0 1em; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* -----------------------------------------------------------
   BACKGROUND GRADIENT GLOW
   ----------------------------------------------------------- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 20% 0%, rgba(59, 130, 246, 0.08), transparent 50%),
    radial-gradient(ellipse 50% 50% at 90% 100%, rgba(16, 185, 129, 0.05), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* -----------------------------------------------------------
   LAYOUT: SIDEBAR + TOPBAR + MAIN
   ----------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.sidebar__brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--success));
  display: grid;
  place-items: center;
  font-size: 20px;
  box-shadow: var(--shadow-sm);
}

.sidebar__brand-text strong {
  font-size: 16px;
  font-weight: 700;
  display: block;
}
.sidebar__brand-text span {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar__section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 12px 12px 6px;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  transition: var(--transition);
}

.sidebar__link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar__link.is-active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
  color: var(--primary);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--primary);
}

.sidebar__link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar__footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

/* Topbar */
.topbar {
  grid-area: topbar;
  background: rgba(18, 18, 26, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__title {
  font-size: 16px;
  font-weight: 600;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.topbar__user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--success));
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
}

.main {
  grid-area: main;
  padding: 28px;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header h1 {
  margin: 0;
}
.page-header p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* -----------------------------------------------------------
   UTILS
   ----------------------------------------------------------- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* -----------------------------------------------------------
   HAMBURGER (mobile only, hidden di desktop)
   ----------------------------------------------------------- */
.topbar__hamburger {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.topbar__hamburger:hover { background: var(--surface-2); }
.topbar__hamburger svg { width: 22px; height: 22px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.sidebar-overlay.is-open {
  display: block;
  opacity: 1;
}

@media (max-width: 1100px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  /* Sidebar jadi drawer slide-in. Topbar full width. */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    max-width: 80vw;
    height: 100vh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.4);
  }
  .sidebar.is-open { transform: translateX(0); }

  .topbar { padding: 0 14px; gap: 10px; }
  .topbar__hamburger { display: inline-flex; }
  .topbar__title { font-size: 14px; }

  .main { padding: 16px; }
  .page-header h1 { font-size: 20px; }
}

@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .topbar__user-name { display: none; }
  .topbar__user { padding: 4px; }

  .main { padding: 12px; }
  h1 { font-size: 20px; }
  h2 { font-size: 17px; }

  /* Card padding lebih ringkas di HP */
  .card { padding: 14px; }
  .page-header { margin-bottom: 16px; }

  /* Tabel: scroll horizontal kalau kontennya kelebar */
  .table-wrap, .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; }

  /* TABS: scroll horizontal di HP, jangan kepotong */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 9px 12px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* UPLOAD ZONE: ringkas */
  .upload-zone { padding: 22px 14px; }
  .upload-zone__title { font-size: 14px; }
  .upload-zone__hint { font-size: 12px; }

  /* CHART: lebih pendek di HP biar muat */
  .chart-wrap { height: 220px; }
  .chart-wrap--short { height: 180px; }

  /* RISK MATRIX: scroll horizontal */
  .risk-matrix {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #risk-matrix-wrap { overflow-x: auto; }

  /* REGULATION CARD: ringkas */
  .reg-card { padding: 14px; }
  .reg-card__head { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* Button stretch, jangan terlalu sempit di HP */
  .btn--lg { padding: 12px 18px; font-size: 14px; }

  /* Form */
  .form-group { margin-bottom: 12px; }

  /* Hindari overflow horizontal global */
  body { overflow-x: hidden; }
  pre, code { overflow-x: auto; max-width: 100%; }
}

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.flex-gap { display: flex; gap: 12px; align-items: center; }
.flex-col { display: flex; flex-direction: column; gap: 12px; }

.text-muted { color: var(--text-muted); }
.text-dim   { color: var(--text-dim); }
.text-sm    { font-size: 12px; }
.text-lg    { font-size: 16px; }
.text-xl    { font-size: 20px; }
.text-2xl   { font-size: 26px; font-weight: 700; }
.text-3xl   { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }

.hidden { display: none !important; }

.mt-1 { margin-top: 8px; }   .mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }  .mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }.mb-4 { margin-bottom: 32px; }

/* -----------------------------------------------------------
   LOADER
   ----------------------------------------------------------- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* -----------------------------------------------------------
   TOAST (notifications)
   ----------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: toast-in 0.3s ease;
  display: flex;
  align-items: start;
  gap: 10px;
}
.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }
.toast--info    { border-left-color: var(--primary); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
