/* =======================================================
   AWS DASHBOARD - CLEAN STYLESHEET
   Framework: Vanilla CSS + CSS Variables
   ======================================================= */

/* ── 1. VARIABLES & RESET ── */
:root {
  /* Colors */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --danger: #ef4444;
  
  /* UI Elements */
  --sticky-bg: #ffffff;
  --header-bg: #f1f5f9;
  --header-sub-bg: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  margin: 0;
  padding: 16px;
  overflow-x: hidden; /* Mencegah scroll horizontal body */
}

/* ── 2. LAYOUT & DASHBOARD ── */
.aws-dashboard {
  max-width: 1200px;
  margin: 0 auto;
  background: var(--surface);
  padding: 20px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.controls select,
.controls input[type="date"],
.controls input[type="month"] { /* ✅ Tambahkan month picker ke selector */
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 13px; /* ✅ Ukuran lebih kecil & proporsional */
  text-align: center; /* ✅ Teks bulan/tahun rata tengah */
  cursor: pointer;
  min-width: 140px; /* ✅ Lebar minimum agar tidak terlalu sempit/lebar */
}

.unit-toggles { display: flex; gap: 8px; }

.unit-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}
.unit-btn:hover { background: #f1f5f9; }
.unit-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── 3. TABLE WRAPPER & BASE ── */
.table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 75vh; /* Batas tinggi agar bisa discroll vertikal */
  position: relative;
}

.aws-table {
  width: 100%;
  border-collapse: separate; /* 'separate' wajib untuk sticky columns yang stabil */
  border-spacing: 0;
  font-size: 14px;
  white-space: nowrap;
  background: #fff;
}

.aws-table th,
.aws-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
  background: inherit;
}
.aws-table th:last-child, .aws-table td:last-child { border-right: none; }

.aws-table th {
  background: var(--header-bg);
  font-weight: 600;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.aws-table tr:hover td { background: #f8fafc; }

/* ── 4. STICKY COLUMNS (Tanggal & Jam) ── */
.sticky-col-1, .sticky-col-2 {
  position: sticky;
  top: 0; /* ✅ WAJIB: Agar sticky saat scroll vertikal */
  background: var(--sticky-bg) !important;
  z-index: 40;
  border-right: 2px solid var(--border);
}

/* Kolom 1: Tanggal */
.sticky-col-1 { left: 0; min-width: 85px; z-index: 45; }

/* Kolom 2: Jam */
.sticky-col-2 { left: 85px; min-width: 70px; z-index: 42; }

/* ✅ PERBAIKAN: Header Sticky Kolom 1 & 2 */
.aws-table thead th.sticky-col-1,
.aws-table thead th.sticky-col-2 {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--header-bg) !important; /* ✅ Paksa warna solid */
  box-shadow: 
    0 2px 4px rgba(0,0,0,0.05),
    2px 0 4px rgba(0,0,0,0.05);
}

.aws-table td.sticky-col-2::after {
  display: none;
}


/* ── 5. WIND DIRECTION CELL (Layout Bertumpuk) ── */
/* Target kolom ke-7 (Arah Angin) agar bisa wrap text */
.aws-table td:nth-child(7) {
  white-space: normal;
  padding: 8px 4px;
  min-width: 100px;
}

.wind-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.wind-degree {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}
.wind-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
/* Panah CSS Clip-Path */
.css-arrow {
  width: 12px; height: 12px;
  background: var(--primary);
  clip-path: polygon(0 0, 100% 50%, 0 100%, 25% 50%);
  display: inline-block;
  flex-shrink: 0;
}
.wind-missing {
  color: var(--danger);
  font-weight: bold;
  font-size: 13px;
}

/* ── 6. DYNAMIC COLUMNS (Daily Interval Logic) ── */
/* Default: Sembunyikan kolom khusus harian */
.daily-only { display: none; }

/* Saat tabel punya kelas .show-daily, tampilkan kolom harian */
.aws-table.show-daily .daily-only { display: table-cell; }

/* Sub-header styling (Baris ke-2) */
.sub-header-row th {
  background-color: var(--header-sub-bg);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  padding: 6px 4px;
  text-align: center;
}

/* Sticky Sub-header Position */
.aws-table thead tr:first-child th { top: 0; z-index: 35; }
.aws-table thead tr.sub-header-row th { 
  top: 40px; /* Sesuaikan dengan tinggi header baris 1 */
  z-index: 32; 
}

/* Sembunyikan sub-header jika bukan mode harian */
.aws-table:not(.show-daily) .sub-header-row { display: none; }

/* ── 7. EVAPORASI / TEKANAN TOGGLE ── */
.evap-col { display: none; }
.aws-table.show-evap .evap-col { display: table-cell; }

/* ── 8. PAGINATION & UTILITIES ── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.page-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.page-btn:hover:not(:disabled) { background: #f1f5f9; }
.page-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.page-btn.info { 
  background: transparent; border: none; cursor: default; 
  color: var(--text-muted); font-weight: 500; 
}

.loading-msg {
  text-align: center;
  color: var(--text-muted);
  margin-top: 12px;
  display: none;
  font-style: italic;
}

/* ── 9. RESPONSIVE MOBILE ── */
@media (max-width: 768px) {
  body { padding: 10px; }
  .aws-dashboard { padding: 14px; }
  
  .controls { flex-direction: column; align-items: stretch; }
  .controls select, .controls input { width: 100%; }
  .unit-toggles { justify-content: center; }
  
  .aws-table { font-size: 13px; }
  
  /* Adjust sticky offsets for smaller screens */
  .sticky-col-1 { left: 0; min-width: 75px; }
  .sticky-col-2 { left: 75px; min-width: 60px; }
  .aws-table th.sticky-col-2, 
  .aws-table td.sticky-col-2 { left: 75px; }
  
  /* Paksa tabel tidak gepeng di mobile */
  .table-wrapper { overflow-x: auto; }
  .aws-table { min-width: 900px; }
}

/* Placeholder untuk sub-header yang tidak perlu label */
.sub-placeholder {
  background: #e2e8f0;
  visibility: hidden;
  padding: 0;
  border: none;
}

/* Pastikan placeholder tetap occupy space */
.aws-table.show-daily .sub-placeholder {
  display: table-cell;
  visibility: hidden;
}

/* ── FIX: Sticky Vertikal untuk Header Tanggal & Jam ── */
/* Target spesifik th.sticky dengan !important untuk override semua konflik */
.aws-table thead th.sticky-col-1,
.aws-table thead th.sticky-col-2 {
  position: -webkit-sticky !important; /* Safari support */
  position: sticky !important;
  top: 0 !important; /* ✅ WAJIB: Titik tempel vertikal */
  z-index: 100 !important; /* ✅ Paling atas */
  background: var(--header-bg) !important; /* ✅ Solid, timpa 'inherit' */
  backdrop-filter: none !important; /* ✅ Hapus efek blur jika ada */
}

/* Pastikan td sticky juga punya background solid agar tidak tembus */
.aws-table tbody td.sticky-col-1,
.aws-table tbody td.sticky-col-2 {
  background: var(--sticky-bg) !important;
  z-index: 40 !important;
}

/* Fix untuk table-wrapper yang punya overflow-y */
.table-wrapper {
  transform: translateZ(0); /* ✅ Hack GPU acceleration untuk fix sticky */
  -webkit-transform: translateZ(0);
}