:root {
  --white:         #ffffff;
  --border:        #e5e7eb;
  --text:          #1a1d27;
  --text-2:        #475569;
  --text-3:        #9ca3af;
  --accent:        #2563eb;
  --accent-light:  #dbeafe;
  --sidebar-width: 220px;
  --sidebar-mini:  58px;
  --topbar-h:      64px;
  --radius:        12px;
  --font:          'Plus Jakarta Sans', sans-serif;
  --mono:          'DM Mono', monospace;
  --transition:    .3s cubic-bezier(.4, 0, .2, 1);
  --green:  #22c55e;
  --yellow: #f59e0b;
  --red:    #ef4444;
  --blue:   #3b82f6;
  --orange: #f59e0b;
  --purple: #8b5cf6;
  --cyan:   #06b6d4;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--text);
  overflow-x: hidden;
}

@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width var(--transition), transform var(--transition);
}

.sidebar > div:first-child {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.logo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
  cursor: pointer;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.logo-circle {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(135deg, #22c55e, #3b82f6);
}
.logo-circle img { width: 100%; height: 100%; object-fit: cover; }

.logo-text { overflow: hidden; white-space: nowrap; }
.logo-text h2 { font-size: 16px; font-weight: 700; }
.logo-text p  { font-size: 10px; color: #64748b; }

.sidebar-toggle {
  width: 40px; height: 40px;
  border: none; border-radius: 12px;
  background: transparent; color: var(--accent);
  cursor: pointer; flex-shrink: 0;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: .2s;
}
.sidebar-toggle:hover { background: var(--accent); color: #fff; }

.nav {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  gap: 2px;
  flex-shrink: 0;
}

.nav a {
  display: flex; align-items: center;
  padding: 11px 10px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--text-2);
  font-size: 13px; font-weight: 600;
  transition: .2s;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}
.nav a i    { width: 18px; font-size: 14px; text-align: center; margin-right: 10px; flex-shrink: 0; }
.nav a span { overflow: hidden; }
.nav a:hover  { background: #eff6ff; color: var(--accent); }
.nav a.active { background: var(--accent-light); color: var(--accent); }

.sidebar-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-contact {
  padding: 10px 10px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-contact-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  padding: 4px 10px 6px;
  white-space: nowrap;
}

.sidebar-contact a {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 14px;
  transition: .2s;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-contact a:hover { background: #eff6ff; color: var(--accent); }
.sidebar-contact a i     { font-size: 13px; flex-shrink: 0; width: 18px; text-align: center; }
.sidebar-contact a span  { overflow: hidden; text-overflow: ellipsis; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border);
}
.sidebar-brand i      { font-size: 14px; color: var(--accent); flex-shrink: 0; }
.sidebar-brand p      { font-size: 11px; font-weight: 600; color: var(--text-2); line-height: 1.5; overflow: hidden; }
.sidebar-brand strong { color: var(--text); font-weight: 700; }

.sidebar.close                  { width: var(--sidebar-mini); }
.sidebar.close .logo            { display: none; }
.sidebar.close .logo-row        { justify-content: center; }
.sidebar.close .nav             { padding: 6px 8px; }
.sidebar.close .nav a           { width: 42px; height: 42px; padding: 0; margin: 0 auto; justify-content: center; }
.sidebar.close .nav a i         { margin-right: 0; }
.sidebar.close .nav a span      { display: none; }
.sidebar.close .sidebar-toggle  { margin: 0 auto; }
.sidebar.close .sidebar-footer  { display: none; }

.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  min-height: var(--topbar-h);
  padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  transition: left var(--transition);
}
.topbar.expand { left: var(--sidebar-mini); }

.topbar-left {
  display: flex; align-items: center;
  gap: 10px;
  flex: 1; min-width: 0;
}
.topbar-left h1 { font-size: 16px; font-weight: 900; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-left p  { font-size: 10px; color: #666; margin-top: 2px; }

.hamburger {
  display: none;
  width: 38px; height: 38px;
  border: none; border-radius: 10px;
  background: transparent; color: var(--accent);
  font-size: 15px; cursor: pointer;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: .2s;
}
.hamburger:hover { background: var(--accent); color: #fff; }

.topbar-bfright { margin-left: auto; flex-shrink: 0; }
.topbar-right   { display: flex; align-items: center; flex-shrink: 0; }
.topbar-left { min-width: 0;}

.topbar-right { margin-left: 8px; }

.time {
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--mono);
  white-space: nowrap;
}

.main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: calc(var(--topbar-h) + 16px) 16px 0 16px;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition);
  animation: pageFadeIn .32s ease forwards;
}
.main.expand { margin-left: var(--sidebar-mini); }

#sidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 150;
}

.btn-primary {
  display: inline-flex;
  align-items: center; justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: none; border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 13px; font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: .2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-primary i    { font-size: 14px; line-height: 1; }
.btn-primary span { line-height: 1; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--border); color: #6b7280;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%; background: #6b7280;
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%,100% { opacity:1; transform:scale(1); }
  50%      { opacity:.4; transform:scale(.8); }
}
.status.online-bg               { background: #dcfce7; color: #166534; }
.status.online-bg .status-dot  { background: #16a34a; }
.status.offline-bg              { background: var(--border); color: #6b7280; }
.status.offline-bg .status-dot { background: #6b7280; animation: none; }

.bottom {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  margin-top: auto;
  margin-left: -16px;
  margin-right: -16px;
}
.bottom p { padding: 14px 16px; }

@media (max-width: 900px) {
  .sidebar,
  .sidebar.close {
    width: var(--sidebar-width) !important;
    transform: translateX(-100%);
  }
  .sidebar.mobile-open { transform: translateX(0) !important; }

  .sidebar.close .logo           { display: flex; }
  .sidebar.close .logo-row       { justify-content: space-between; }
  .sidebar.close .nav            { padding: 8px 10px; }
  .sidebar.close .nav a          { width: auto; height: auto; padding: 11px 10px; margin: 0; justify-content: flex-start; }
  .sidebar.close .nav a i        { margin-right: 10px; }
  .sidebar.close .nav a span     { display: inline; }
  .sidebar.close .sidebar-toggle { margin: 0; }
  .sidebar.close .sidebar-footer { display: flex; }

  .hamburger { display: flex; }

  .topbar,
  .topbar.expand { left: 0 !important; }

  .main,
  .main.expand {
    margin-left: 0 !important;
    padding-top: calc(var(--topbar-h) + 16px);
  }

  .bottom { font-size: .75rem; }
}

@media (max-width: 600px) {
  .time {
    display: none;
  }

  .update-label {
    display: none;
  }

  .topbar .btn-primary {
    width: 38px;
    height: 38px;
    padding: 0;
  }

  .topbar .btn-primary span {
    display: none;
  }
}

@media (max-width: 480px) {
  :root {
    --topbar-h: 56px;
  }

  .topbar {
    padding: 0 12px;
    gap: 6px;
    /* HAPUS overflow: hidden — ini penyebab button terpotong */
  }

  .topbar-left {
    flex: 1;
    min-width: 0;
    overflow: hidden; /* pindah ke sini biar cuma judul yang terpotong */
  }

  .topbar-left h1 {
    font-size: 13px;
  }

  .topbar-left p,
  .topbar-bfright,
  .time {
    display: none;
  }

  .topbar-right {
    display: flex;
    flex-shrink: 0; /* tambah ini biar ga ikut menyusut */
  }

  .topbar-right .btn-primary {
    width: 38px;
    height: 38px;
    padding: 0;
    flex-shrink: 0;
  }

  .topbar-right .btn-primary span {
    display: none;
  }

  .main .btn-primary {
    width: auto;
    height: auto;
    padding: 9px 14px;
    border-radius: 10px;
  }

  .main .btn-primary span {
    display: inline;
  }

  .bottom {
    font-size: .65rem;
    margin-left: -12px;
    margin-right: -12px;
  }
}

.no-transition *,
.no-transition *::before,
.no-transition *::after {
  transition: none !important;
}

@media (max-width: 375px) {
  :root { --topbar-h: 52px; }

  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-left h1 { font-size: 11px; }
  .topbar-bfright { display: none; }
  .time { display: none; }

  .main {
    padding-left: 10px;
    padding-right: 10px;
  }

  .bottom {
    font-size: .6rem;
    margin-left: -10px;
    margin-right: -10px;
  }
  .bottom p { padding: 10px; }
}

/* --- PENGATURAN TOMBOL THEME TOGGLE --- */
.theme-toggle {
  width: 40px; height: 40px;
  border: none; border-radius: 10px;
  background: #f1f5f9; color: #475569;
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: 0.2s;
}
.theme-toggle:hover { background: #e2e8f0; color: var(--accent); }

/* --- ATURAN DARK MODE --- */
body.dark-mode {
  background-color: #0f172a; 
  color: #f8fafc;
}

/* 1. Background Komponen (Tambahkan f-card, guide-card, system-card, param-card dll) */
body.dark-mode .sidebar,
body.dark-mode .topbar,
body.dark-mode .monitor-hero,
body.dark-mode .d-card,
body.dark-mode .chart-card,
body.dark-mode .export-modal,
body.dark-mode .f-card,
body.dark-mode .guide-card,
body.dark-mode .system-card,
body.dark-mode .param-card,
body.dark-mode .setting-savebar,
body.dark-mode #loginSection,
body.dark-mode .site-footer {
  background: #1e293b;
  border-color: #334155;
}

/* 2. Teks Heading Utama */
body.dark-mode .topbar-left h1,
body.dark-mode .logo-text h2,
body.dark-mode .monitor-hero-title,
body.dark-mode .d-value,
body.dark-mode .chart-header h3,
body.dark-mode .export-modal-head h3,
body.dark-mode .f-card h3,
body.dark-mode .guide-title,
body.dark-mode .system-title,
body.dark-mode .param-head h3,
body.dark-mode .footer-col h4,
body.dark-mode .hero-title {
  color: #f8fafc;
}

/* 3. Teks Sub-heading / Deskripsi */
body.dark-mode .topbar-left p,
body.dark-mode .logo-text p,
body.dark-mode .monitor-hero-desc,
body.dark-mode .d-title,
body.dark-mode .chart-header p,
body.dark-mode .time,
body.dark-mode .f-card p,
body.dark-mode .goal-item p,
body.dark-mode .flow-item p,
body.dark-mode .sensor-item p,
body.dark-mode .footer-links a,
body.dark-mode .footer-col p,
body.dark-mode .hero-desc {
  color: #94a3b8 !important;
}

/* 4. Kotak-kotak kecil / Item Grid di halaman Panduan & Sistem */
body.dark-mode .status-box,
body.dark-mode .step-item,
body.dark-mode .monitor-item,
body.dark-mode .tip-card,
body.dark-mode .goal-item,
body.dark-mode .flow-item,
body.dark-mode .sensor-item {
  background: #0f172a; /* Lebih gelap dari card utama */
  border: 1px solid #334155;
}
body.dark-mode .step-item h4,
body.dark-mode .monitor-item h4 {
  color: #e2e8f0;
}

/* Mengubah tampilan kontrol interaktif (Input, Select, Toggle) */
body.dark-mode .theme-toggle,
body.dark-mode .chart-select,
body.dark-mode .chart-input,
body.dark-mode .param-field input {
  background: #334155;
  color: #f8fafc;
  border-color: #475569;
}
body.dark-mode .theme-toggle:hover { background: #475569; color: #fff; }

/* Menyesuaikan lencana status Offline */
body.dark-mode .status.offline-bg {
  background: #334155;
  color: #cbd5e1;
  border-color: #475569;
}

body.dark-mode .footer-links a:hover {
  color: #60a5fa; /* Biru muda cerah agar terlihat jelas di background gelap */
}

/* 5. Efek Fade (Overlay) pada Slider Beranda */
body.dark-mode .hero {
  background: #0f172a; /* Mengubah background dasar menjadi gelap */
}

body.dark-mode .hero-overlay {
  /* Mengubah gradasi dari putih menjadi warna gelap (RGB 15, 23, 42) */
  background: linear-gradient(to right, #0f172a 0%, rgba(15, 23, 42, 0.96) 35%, rgba(15, 23, 42, 0.2) 70%, transparent 100%);
}

/* Warna Status Mesin saat Dark Mode */
body.dark-mode .monitor-hero .status.ms-aktif { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
body.dark-mode .monitor-hero .status.ms-mulai { background: #451a03; color: #fcd34d; border-color: #78350f; }
body.dark-mode .monitor-hero .status.ms-standby { background: #1e293b; color: #94a3b8; border-color: #334155; }

/* Tombol Kotak Relay di Dark Mode */
body.dark-mode .btn-control.off {
  background: #334155;
  color: #94a3b8;
  border-color: #475569;
}
body.dark-mode .btn-control.off span {
  color: #64748b;
}

body.dark-mode .btn-control.on {
  background: #059669; /* Hijau yang lebih gelap & elegan */
  color: #ffffff;
  border-color: #047857;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.3);
}
body.dark-mode .btn-control.on span {
  color: #a7f3d0;
}

/* Menghilangkan motif lingkaran putih pada Hero di Dark Mode */
body.dark-mode .monitor-hero::before,
body.dark-mode .monitor-hero::after {
  display: none;
}

/* Tombol Kontrol Terkunci di Dark Mode */
body.dark-mode .btn-control.disabled {
  background: #1e293b !important;
  color: #475569 !important;
  border-color: #334155 !important;
}