/* =====================
   🌈 Global Variables
===================== */
:root {
  --primary: #1d4ed8;
  --bg: #f9fafb;
  --text-dark: #111827;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --shadow: rgba(0, 0, 0, 0.08);
}

/* =====================
   🌍 Global Layout
===================== */
body {
  font-family: "Segoe UI", Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-dark);
  line-height: 1.5;
}

.container {
  max-width: 1200px;
  margin: auto;
  padding: 20px;
}

/* =====================
   🧭 Navbar
===================== */
.navbar {
  background: var(--primary);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.navbar-left {
  display: flex;
  align-items: center;
}

.navbar .brand {
  font-weight: 600;
  font-size: 1.25rem;
  margin-left: 10px;
}

.navbar a {
  color: white;
  margin-left: 16px;
  text-decoration: none;
  font-weight: 500;
  transition: 0.2s;
}

.navbar a:hover {
  text-decoration: underline;
  opacity: 0.9;
}

.logo {
  height: 40px;
  margin-right: 12px;
  vertical-align: middle;
}

/* =====================
   🧩 Dashboard Layout
===================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
  padding: 0 10px;
}

.chart-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 8px var(--shadow);
  padding: 1rem 1.5rem;
  border: 1px solid var(--border);
  transition: all 0.2s ease-in-out;
}

.chart-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 10px var(--shadow);
}

.chart-card h2 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text-dark);
  font-weight: 600;
}

.chart-card canvas {
  width: 100% !important;
  height: 260px !important;
  margin: 0 auto;
}

.chart-card.full canvas {
  height: 300px !important;
}

/* =====================
   📊 Critical Table
===================== */
.critical-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.critical-table th {
  text-align: left;
  background-color: var(--primary);
  color: #fff;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.critical-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.critical-table tr:nth-child(even) {
  background-color: #f9fafb;
}

.critical-table tr:hover {
  background-color: #eef2ff;
}

/* Status warna */
.status {
  font-weight: 600;
  text-transform: capitalize;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.85rem;
}

.status.normal-serviceable {
  color: #15803d;
  background: #dcfce7;
}

.status.normal-unserviceable {
  color: #92400e;
  background: #fef3c7;
}

.status.not-normal-serviceable {
  color: #dc2626;
  background: #fee2e2;
}

.status.not-normal-unserviceable {
  color: #7f1d1d;
  background: #fecaca;
}

/* =====================
   📱 Responsive (Mobile)
===================== */
@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .navbar-right {
    margin-top: 8px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .chart-card canvas {
    height: 220px !important;
  }

  .critical-table th,
  .critical-table td {
    font-size: 0.85rem;
  }
}

/* =====================
   ⚓ Footer
===================== */
.footer {
  background: #111827;
  color: white;
  text-align: center;
  padding: 15px;
  margin-top: 50px;
  font-size: 14px;
}


/* =====================
   🧾 KPI Cards
===================== */
.kpi-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.5rem;
}
.kpi-card {
  flex: 1;
  min-width: 250px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}
.kpi-value {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0.2rem 0;
}
.kpi-status.good { color: #15803d; }
.kpi-status.warning { color: #b45309; }
.kpi-status.bad { color: #dc2626; }
.kpi-status.neutral { color: #475569; }

/* =====================
   🤖 Insight Box
===================== */
.insight-box {
  background: #f9fafb;
  border-left: 4px solid var(--primary);
  font-size: 0.95rem;
  color: #1e293b;
}
.insight-box h2 {
  margin-bottom: 0.5rem;
}


/* 🤖 AI Insight Box */
.insight-box {
  background: #f9fafb;
  border-left: 4px solid var(--primary);
  font-size: 0.95rem;
  color: #1e293b;
  margin-top: 1rem;
  line-height: 1.6;
}
.insight-box strong {
  color: var(--primary);
}
.insight-box h2 {
  margin-bottom: 0.4rem;
}


.insight-box {
  background: #f9fafb;
  border-left: 4px solid var(--primary);
  padding: 1rem 1.5rem;
  line-height: 1.6;
  font-size: 0.95rem;
}
.insight-box strong {
  color: var(--primary);
}


/* ===========================
   📊 FIX: Responsive Chart Container
=========================== */

/* Pastikan container chart bisa mengecil dan scroll horizontal kalau perlu */
.chart-card {
  position: relative;
  width: 100%;
  overflow-x: hidden;
  overflow-y: visible;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 1rem;
  margin-bottom: 1.5rem;
  box-sizing: border-box;
}

/* Biar canvas mengikuti ukuran parent */
.chart-card canvas {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  display: block;
  margin: 0 auto;
}

/* Di layar kecil, pastikan tidak melebar keluar grid */
@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr !important;
    overflow-x: hidden;
    padding: 0.5rem;
  }

  .chart-card {
    padding: 0.8rem;
    border-radius: 10px;
  }

  .chart-card canvas {
    min-height: 200px;
    max-height: 280px;
  }
}

/* ===========================
   📱 Mobile Chart Responsive Fix
=========================== */

.chart-card {
  position: relative;
  width: 100%;
  overflow: hidden;
  padding: 1rem;
  box-sizing: border-box;
}

.chart-card canvas {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}

/* Responsive grid untuk HP */
@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr !important;
    padding: 0.8rem;
    gap: 1rem;
  }

  .chart-card {
    padding: 0.8rem;
    border-radius: 10px;
  }

  .chart-card h2 {
    font-size: 1rem;
  }
}

/* ===========================
   🧭 Responsive Critical Table Fix
=========================== */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* smooth scroll di HP */
  scrollbar-width: thin; /* Firefox */
}

.table-wrapper::-webkit-scrollbar {
  height: 6px;
}
.table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.critical-table {
  min-width: 500px; /* biar struktur kolom tetap rapi */
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  text-align: left;
  background: white;
  border-radius: 6px;
}

.critical-table th,
.critical-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap; /* biar teks gak patah */
}

.critical-table tr:hover {
  background-color: #f3f4f6;
}

/* 🌐 Untuk layar kecil */
@media (max-width: 768px) {
  .critical-table {
    font-size: 0.85rem;
  }

  .critical-table th,
  .critical-table td {
    padding: 8px 10px;
  }
}

.legend-risk {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  font-size: 0.85rem;
  margin-top: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-item span {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: inline-block;
}

/* chart konsumsi energi */

#energyChart7 {
    height: 500px !important;
}


/* Date di energi harian */

/* ✅ Wrapper agar bisa di-center */
.energy-last-date-wrapper {
    display: flex;
    justify-content: center;
    margin-top: 14px;
}

/* ✅ Box tanggal data terakhir */
.energy-last-date-box {
    padding: 10px 14px;
    background: linear-gradient(90deg, #eef2ff 0%, #e0e7ff 100%);
    border-left: 4px solid #6366f1;
    border-radius: 10px;

    display: flex;
    align-items: center;
    gap: 8px;

    font-size: 0.9rem;
    color: #1e3a8a;
    font-weight: 500;

    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    text-align: center;
}

/* ✅ Ikon */
.energy-last-date-box .icon {
    font-size: 1.15rem;
}

/* ✅ Teks */
.energy-last-date-box .date {
    font-weight: 700;
    color: #4338ca;
}

/* ✅ Mobile friendly */
@media (max-width: 480px) {
    .energy-last-date-box {
        font-size: 0.5rem;
        padding: 8px 12px;
        gap: 6px;
    }
    .energy-last-date-box .icon {
        font-size: 0.82rem;     /* lebih kecil elegan */
        font-weight: 600;
    }
}
