:root {
  --primary: #00b894;
  --secondary: #6c5ce7;
  --success: #28a745;
  --warning: #fd7e14;
  --danger: #dc3545;
  --dark: #2d3436;
  --bg-gray: #f0f2f5;
  --sidebar-width: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
/* Safe area support untuk iPhone */
body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.sidebar {
  padding-top: max(20px, env(safe-area-inset-top));
}

body {
  background-color: var(--bg-gray);
  font-family: 'Inter', 'Segoe UI', sans-serif;
  color: var(--dark);
  overflow-x: hidden;
}

body.sidebar-open {
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  position: fixed;
  height: 100vh;
  background: white;
  padding: 20px;
  box-shadow: 10px 0 30px rgba(0,0,0,0.03);
  z-index: 1000;
  transition: all 0.3s;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.sidebar-close-btn,
.mobile-menu-btn {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 52, 54, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 999;
}

.sidebar-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 15px;
  margin-bottom: 8px;
  color: #636e72;
  text-decoration: none;
  border-radius: 15px;
  transition: 0.3s;
  cursor: pointer;
}

.nav-item:hover, .nav-item.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 15px rgba(0, 184, 148, 0.3);
}

.nav-item i { width: 30px; font-size: 1.1rem; }

/* Main Content */
.main-wrapper {
  margin-left: var(--sidebar-width);
  padding: 40px;
  transition: all 0.3s;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
  flex-wrap: wrap;
  gap: 15px;
}

.top-bar-title {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

/* System Card */
.system-card {
  background: white;
  border-radius: 30px;
  padding: 25px;
  margin-bottom: 30px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.04);
  position: relative;
  transition: all 0.3s;
}

.system-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 50px rgba(0,0,0,0.08);
}

/* Sensor Grid */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.sensor-box {
  padding: 15px;
  border-radius: 20px;
  background: #f8f9fa;
  border: 1px solid #f1f1f1;
  text-align: center;
  transition: all 0.3s;
}

.sensor-box.normal { background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%); }
.sensor-box.warning { background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%); }
.sensor-box.danger { background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%); }
.sensor-box.disabled { background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%); opacity: 0.6; }

.sensor-box i { font-size: 28px; margin-bottom: 10px; }
.sensor-box h5 { font-size: 28px; font-weight: bold; margin: 8px 0; }
.sensor-box h5 small { font-size: 12px; font-weight: normal; }

.target-info {
  font-size: 10px;
  color: #a0a0a0;
  font-weight: bold;
  margin-top: 5px;
  display: block;
}

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: bold;
  margin-top: 8px;
}

.status-badge.normal { background: #28a745; color: white; }
.status-badge.warning { background: #fd7e14; color: white; }
.status-badge.danger { background: #dc3545; color: white; }

/* Switch Row */
.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(0,0,0,0.08);
  gap: 10px;
}

.switch-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
}

.switch-label {
  font-size: 9px;
  font-weight: 600;
  color: #555;
}

/* Form Switch */
.form-switch .form-check-input {
  width: 40px;
  height: 20px;
  cursor: pointer;
}

.form-switch .form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* Progress Bar */
.harvest-progress {
  height: 8px;
  background: #eee;
  border-radius: 10px;
  margin-top: 10px;
  overflow: hidden;
}

.harvest-bar {
  height: 100%;
  background: var(--primary);
  transition: width 1s;
}

/* Table */
.table thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #636e72;
  border: none;
  padding: 15px;
}

.table tbody td {
  padding: 15px;
  font-size: 13px;
  border-color: #f8f9fa;
}

/* Modal */
.modal-content { border-radius: 20px; }
.modal-header { border-bottom: none; }

/* Dropdown 3 Titik */
.dropdown-three-dots {
  position: absolute;
  top: 20px;
  right: 20px;
}

.btn-three-dots {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #666;
  padding: 5px 10px;
  border-radius: 20px;
}

.btn-three-dots:hover { background: #f0f0f0; }

/* Responsive */
@media (max-width: 992px) {
  .sidebar {
    left: 0;
    transform: translateX(-110%);
    width: min(85vw, 320px);
    border-top-right-radius: 24px;
    border-bottom-right-radius: 24px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close-btn,
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .main-wrapper {
    margin-left: 0;
    padding: 20px 16px 32px;
  }

  .top-bar {
    margin-bottom: 24px;
    align-items: flex-start;
  }

  .top-bar-title {
    width: 100%;
  }

  .top-bar h2 {
    font-size: 1.4rem;
  }

  .top-bar p {
    margin-bottom: 0;
  }

  #action-area,
  #action-area .btn {
    width: 100%;
  }

  .system-card {
    padding: 20px 18px;
    border-radius: 24px;
  }

  .sensor-grid {
    grid-template-columns: 1fr;
  }

  .switch-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .table-responsive {
    font-size: 12px;
  }
}
@media (max-width: 768px) {
  /* Font size lebih kecil di HP */
  body {
    font-size: 14px;
  }

  /* Header */
  .top-bar h2 {
    font-size: 1.25rem;
  }

  .top-bar p {
    font-size: 0.75rem;
    margin-bottom: 0;
  }

  /* Card Sistem */
  .system-card {
    padding: 16px;
    border-radius: 20px;
  }

  .system-card h4 {
    font-size: 1.1rem;
  }

  /* Sensor Card */
  .sensor-box {
    padding: 12px;
  }

  .sensor-box i {
    font-size: 22px;
  }

  .sensor-box h5 {
    font-size: 22px;
  }

  .sensor-box h5 small {
    font-size: 10px;
  }

  .target-info {
    font-size: 9px;
  }

  .status-badge {
    font-size: 9px;
    padding: 3px 8px;
  }

  /* Switch Row - lebih rapat */
  .switch-row {
    gap: 8px;
  }

  .switch-item {
    font-size: 9px;
  }

  /* Switch toggle lebih kecil sedikit (tetap mudah diclick) */
  .form-switch .form-check-input {
    width: 36px;
    height: 18px;
  }

  /* Progress bar */
  .harvest-progress {
    margin-top: 12px;
  }

  /* Tombol action area */
  #action-area .btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  /* Badge di header card */
  .system-card .badge {
    font-size: 10px;
    padding: 4px 10px;
  }

  /* Indikator Relay ON */
  .motor-active-indicator,
  .text-warning {
    font-size: 9px;
  }
}

/* Untuk HP ukuran sangat kecil (≤480px) */
@media (max-width: 480px) {
  .top-bar-title {
    flex-wrap: wrap;
    gap: 8px;
  }

  .mobile-menu-btn {
    width: 36px;
    height: 36px;
  }

  .mobile-menu-btn i {
    font-size: 14px;
  }

  .sensor-value {
    font-size: 18px;
  }

  .sensor-unit {
    font-size: 10px;
  }

  .btn-three-dots {
    padding: 4px 8px;
  }
}

/* Pastikan dropdown tidak terpotong di mobile */
@media (max-width: 768px) {
  .dropdown-menu {
    min-width: 160px;
    right: 0;
    left: auto !important;
  }
}
