:root {
  --primary: #1a73e8;
  --primary-light: #a8c7fa;
  --primary-dark: #0d47a1;
  --accent: #2b6cb0;
  --accent-light: #4299e1;
  --accent-dark: #2c5282;
  --success: #2d7d46;
  --success-light: #38a169;
  --danger: #c53030;
  --danger-light: #fc8181;
  --light: #f7fafc;
  --light-gray: #edf2f7;
  --medium-gray: #e2e8f0;
  --text-dark: #1a202c;
  --text-light: #718096;
  --border: #cbd5e0;
  --gradient-primary: linear-gradient(
    135deg,
    var(--primary),
    var(--primary-dark)
  );
  --gradient-success: linear-gradient(135deg, var(--success), #22543d);
  --gradient-danger: linear-gradient(135deg, var(--danger), #9b2c2c);
  --auto-mode: #2d7d46;
  --manual-mode: #d69e2e;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Segoe UI", "Poppins", Roboto, Oxygen, Ubuntu, sans-serif;
}

.dashboard-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 15px;
  gap: 15px;
  width: 100%;
}

/* ==================== */
/* HEADER STYLES */
/* ==================== */

.dashboard-header {
  background: var(--gradient-primary);
  color: white;
  border-radius: 20px;
  padding: 18px 22px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  width: 100%;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 15px;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  margin-right: 5px;
}

.logo-polines {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-text h1 {
  font-size: 1.8rem !important;
  font-weight: 500;
  margin-bottom: 2px !important;
  line-height: 1;
  letter-spacing: 0.3px;
}

.logo-text p {
  font-size: 1rem !important;
  opacity: 0.95;
  font-weight: 200;
  letter-spacing: 0.3px;
}

.header-info {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.current-time,
.last-update {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 8px 14px;
  border-radius: 20px;
}

/* Main Content - FIXED GRID */
.dashboard-main {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 15px;
  flex: 1;
  width: 100%;
  min-height: 60vh;
}

.left-column,
.right-column {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
}

/* Card Styles */
.dashboard-card {
  background: var(--light);
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 200px;
  overflow: hidden;
}

.card-header {
  background: var(--gradient-primary);
  color: white;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 20px 20px 0 0;
}

.card-content {
  padding: 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Room Status Card */
.room-status-card .card-content {
  justify-content: center;
  align-items: center;
}

.room-status-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px;
  border-radius: 20px;
  color: white;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 300px;
}

.room-status-indicator.status-unused {
  background: var(--gradient-danger);
}

.room-status-indicator.status-used {
  background: var(--gradient-success);
}

.room-status-indicator .status-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.room-status-indicator h4 {
  font-size: 1.2rem;
  margin-bottom: 5px;
}

.room-status-indicator p {
  font-size: 0.9rem;
  opacity: 0.9;
}

/* Temperature Card */
.temperature-card {
  flex: 1;
}

.sensors-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.sensor-item {
  display: flex;
  padding: 15px;
  border-radius: 14px;
  background: var(--light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
  transition: all 0.3s ease;
  width: 100%;
}

.sensor-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.sensor-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.sensor-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sensor-header i {
  font-size: 1.5rem;
  color: var(--accent);
}

.sensor-location {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 1rem;
}

.sensor-data {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.temperature {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-dark);
}

.humidity {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 3px;
}

/* Room Overview Card */
.room-overview-card {
  flex: 1;
}

.status-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
  flex: 1;
}

.occupancy-container {
  display: flex;
  align-items: center;
  gap: 15px;
  width: 100%;
  min-height: 80px;
}

.status-item.occupancy-item.compact {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  min-height: 80px;
  border-radius: 14px;
  background: var(--light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.status-item.occupancy-item.compact .status-icon {
  font-size: 1.5rem;
  color: var(--accent);
  width: 40px;
  text-align: center;
}

.status-item.occupancy-item.compact .status-details {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.status-item.occupancy-item.compact .status-label {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-dark);
}

.status-value.small-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-dark);
  padding: 4px 16px;
  border-radius: 14px;
  background: rgba(43, 108, 176, 0.1);
  min-width: 50px;
  text-align: center;
}

.btn-snapshot {
  padding: 12px 20px;
  border: none;
  border-radius: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--gradient-primary);
  color: white;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 50px;
}

.btn-snapshot:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* AC Container */
.ac-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.ac-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  border-radius: 14px;
  background: var(--light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
  transition: all 0.3s ease;
  width: 100%;
}

.ac-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.ac-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.ac-header i {
  font-size: 2rem;
  color: var(--accent);
}

.ac-label {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 1rem;
}

.ac-details {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.ac-temperature {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-dark);
  padding: 5px 10px;
  border-radius: 14px;
  background: rgba(43, 108, 176, 0.1);
}

.ac-status {
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 14px;
  width: 100%;
  text-align: center;
}

.ac-status.status-on {
  background-color: rgba(45, 125, 70, 0.15);
  color: var(--success);
  border: 1px solid rgba(45, 125, 70, 0.3);
}

.ac-status.status-off {
  background-color: rgba(197, 48, 48, 0.15);
  color: var(--danger);
  border: 1px solid rgba(197, 48, 48, 0.3);
}

/* Mode Control */
.mode-control {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: auto;
  padding-top: 15px;
  border-top: 1px solid var(--border);
  width: 100%;
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 140px;
  justify-content: center;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-active {
  background: var(--gradient-primary);
  color: white;
}

/* Mode Indicator */
.mode-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-left: auto;
}

.mode-indicator.auto {
  background-color: rgba(45, 125, 70, 0.9);
  color: white;
  border: 1px solid rgba(45, 125, 70, 0.3);
}

.mode-indicator.manual {
  background-color: rgba(214, 158, 46, 0.9);
  color: white;
  border: 1px solid rgba(214, 158, 46, 0.3);
}

/* Footer */
.dashboard-footer {
  background: var(--gradient-primary);
  color: white;
  text-align: center;
  padding: 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  width: 100%;
}

/* ========================================= */
/* MODAL STYLES (MODIFIKASI POSISI TENGAH)   */
/* ========================================= */

.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);

  /* CENTER MODAL SECARA VERTIKAL DAN HORIZONTAL */
  align-items: center;
  justify-content: center;

  animation: fadeIn 0.3s ease;
}

/* Paksa display flex agar centering bekerja meskipun di-trigger oleh JS */
.modal[style*="display: block"],
.modal[style*="display:block"] {
  display: flex !important;
}

.modal-content {
  background-color: var(--light);
  margin: 0; /* Reset margin agar Flexbox mengatur posisi */
  padding: 0;
  border-radius: 20px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  animation: slideIn 0.3s ease;
  border: 1px solid var(--border);
  overflow-y: auto;
}

.modal-header {
  background: var(--gradient-primary);
  color: white;
  padding: 15px 20px;
  border-radius: 20px 20px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.close {
  color: white;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close:hover {
  opacity: 0.8;
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.1);
}

.modal-body {
  padding: 20px;
}

/* Snapshot Modal Styles */
.snapshot-modal {
  max-width: 600px;
  margin: 0;
  max-height: 90vh;
  overflow-y: auto;
}

.snapshot-container {
  width: 100%;
}

.snapshot-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding: 10px;
  background: rgba(43, 108, 176, 0.1);
  border-radius: 12px;
}

.snapshot-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-dark);
  font-size: 0.95rem;
}

.snapshot-count-display {
  font-weight: 600;
  color: var(--accent-dark);
  background: rgba(43, 108, 176, 0.15);
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
}

/* MODIFIKASI: Container Gambar/Snapshot */
.snapshot-image-container {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);

  /* Flexbox untuk membuat konten di dalamnya (loading/image) ke tengah */
  display: flex;
  align-items: center;
  justify-content: center;

  background-color: transparent;
  margin-bottom: 15px;
  position: relative;

  line-height: 0;
}

#snapshot-image {
  width: 100%;
  height: auto;
  /* object-fit: contain; KUNCI: Agar gambar menyesuaikan wadah tanpa terpotong */
  display: block;
  border-radius: 12px;
}

/* MODIFIKASI: Placeholder Loading */
.snapshot-placeholder {
  /* Flexbox untuk membuat icon dan teks di dalam placeholder rapi */
  display: flex;
  flex-direction: column; /* Icon di atas teks */
  align-items: center; /* Tengah Horizontal */
  justify-content: center; /* Tengah Vertikal */

  width: 100%;
  min-height: 250px;
  background-color: #f5f5f5;

  line-height: 1.5;

  color: var(--text-light);
  border-radius: 12px;
  z-index: 2;
}

.snapshot-placeholder i {
  color: var(--accent);
  margin-bottom: 10px; /* Jarak antara icon dan teks */
}

.snapshot-placeholder p {
  margin: 0;
  font-weight: 500;
}

.snapshot-timestamp {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 10px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 12px;
}

.update-info {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-left: auto;
}

/* Snapshot Controls */
.snapshot-controls {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
}

.btn-refresh {
  background: var(--gradient-success);
  color: white;
  padding: 8px 16px;
  font-size: 0.85rem;
}

/* Control Group Styles */
.control-group {
  margin-bottom: 20px;
  padding: 15px;
  border-radius: 12px;
  background: var(--light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
}

.control-group h3 {
  margin-top: 0;
  margin-bottom: 15px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
}

.switch-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--medium-gray);
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--success);
}

input:checked + .slider:before {
  transform: translateX(24px);
}

.switch-status {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 0.9rem;
}

.temperature-control {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
}

.temperature-control label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-dark);
  font-size: 0.9rem;
}

.temperature-control input[type="range"] {
  width: 100%;
  height: 6px;
  background: var(--medium-gray);
  border-radius: 5px;
  outline: none;
}

.temperature-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 15px;
}

.control-actions .btn {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

/* ==================== */
/* RESPONSIVE DESIGN */
/* ==================== */

@media (max-width: 1024px) {
  .dashboard-main {
    grid-template-columns: 1fr;
  }

  .header-content {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .header-info {
    justify-content: center;
  }

  .snapshot-modal {
    width: 95%;
  }
}

@media (max-width: 768px) {
  .dashboard-container {
    padding: 12px;
  }

  .ac-container {
    grid-template-columns: 1fr;
  }

  .mode-control {
    flex-direction: column;
  }

  .modal-content {
    width: 95%;
  }

  .control-actions {
    flex-direction: column;
  }

  .control-actions .btn {
    width: 100%;
  }

  .mode-indicator {
    margin-left: 0;
    margin-top: 8px;
    justify-content: center;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .sensor-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .sensor-data {
    align-items: flex-start;
  }

  .logo-text h1 {
    font-size: 1.3rem;
  }

  .logo-text p {
    font-size: 0.9rem;
  }

  .occupancy-container {
    flex-direction: column;
    gap: 8px;
  }

  .status-item.occupancy-item.compact {
    width: 100%;
    border-radius: 12px;
  }

  .btn-snapshot {
    width: 100%;
    justify-content: center;
    padding: 10px 16px;
    font-size: 0.85rem;
    min-height: 45px;
    border-radius: 12px;
  }

  .status-item.occupancy-item.compact .status-label {
    font-size: 0.9rem;
  }

  .status-value.small-value {
    font-size: 1.1rem;
    border-radius: 12px;
  }

  .snapshot-info-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .snapshot-count-display {
    align-self: flex-start;
  }

  .snapshot-image-container {
    height: auto;
  }
}

@media (max-width: 480px) {
  .logo-section {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }

  .header-info {
    flex-direction: column;
    gap: 8px;
  }

  .btn {
    min-width: 120px;
    font-size: 0.85rem;
  }

  .logo-text h1 {
    font-size: 1.1rem;
    font-weight: 700;
  }

  .logo-text p {
    font-size: 0.8rem;
  }

  .logo-icon {
    width: 45px;
    height: 45px;
    font-size: 1.4rem;
  }

  /* --- PERBAIKAN UTAMA DI SINI --- */

  /* 1. Wadah Gambar: Tinggi Auto */
  /* Agar wadah menyusut pas mengikuti tinggi gambar (tanpa sisa putih) */
  .snapshot-image-container {
    height: auto;
    min-height: 0;
  }

  /* 2. Loading Placeholder: Tinggi Tetap */
  /* Agar saat loading (belum ada gambar), kotaknya tidak gepeng */
  .snapshot-placeholder {
    min-height: 180px;
  }

  /* ------------------------------- */

  .status-item.occupancy-item.compact {
    padding: 10px 12px;
    border-radius: 10px;
  }

  .status-item.occupancy-item.compact .status-label {
    font-size: 0.9rem;
  }

  .status-value.small-value {
    font-size: 1.1rem;
    padding: 3px 12px;
    border-radius: 10px;
  }

  .btn-snapshot {
    font-size: 0.8rem;
    padding: 10px 14px;
    min-height: 45px;
    border-radius: 10px;
  }

  .snapshot-controls {
    flex-direction: column;
  }

  .snapshot-controls .btn {
    width: 100%;
  }

  .snapshot-modal {
    width: 98%;
  }
}
/* ==================== */
/* COMPACT VERSION ADJUSTMENTS */
/* ==================== */

body {
  min-height: 100vh;
  height: auto;
  overflow-y: auto;
  overflow-x: hidden;
}

.dashboard-container {
  gap: 8px;
  padding: 8px;
}

.card-header {
  padding: 10px 14px;
  font-size: 0.85rem;
}

.card-content {
  padding: 14px;
}

.logo-text h1 {
  font-size: 1.1rem;
}
.logo-text p {
  font-size: 0.75rem;
}

.temperature,
.ac-temperature {
  font-size: 1.1rem;
}
.status-label,
.sensor-location {
  font-size: 0.9rem;
}

.dashboard-card {
  min-height: 160px;
}

.current-time,
.last-update {
  padding: 5px 10px;
  font-size: 0.75rem;
}

.room-status-indicator {
  max-width: 200px;
  padding: 16px;
}
.room-status-indicator .status-icon {
  font-size: 2rem;
}
.room-status-indicator h4 {
  font-size: 1.1rem;
}
.room-status-indicator p {
  font-size: 0.8rem;
}

.btn {
  padding: 8px 14px;
  font-size: 0.8rem;
  min-width: 120px;
}

.btn-snapshot {
  padding: 10px 16px;
  font-size: 0.85rem;
  min-height: 45px;
  border-radius: 12px;
}

.status-item.occupancy-item.compact {
  padding: 8px 10px;
  border-radius: 12px;
}

.status-item.occupancy-item.compact .status-label {
  font-size: 0.9rem;
}

.status-value.small-value {
  font-size: 1.1rem;
  padding: 3px 10px;
  border-radius: 12px;
}

.current-time,
.last-update {
  border-radius: 20px;
}

.sensor-item {
  border-radius: 14px;
}

.status-item.occupancy-item.compact {
  border-radius: 14px;
}

.ac-item {
  border-radius: 14px;
}

.btn {
  border-radius: 14px;
}

.mode-indicator {
  border-radius: 20px;
}
