/* ==========================================================================
   IoT Smart Monitoring PWA - Style System
   Theme: Sleek Cyber Glassmorphism
   ========================================================================== */

:root {
  --bg-dark: #090d16;
  --card-bg: rgba(18, 24, 38, 0.72);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-hover-border: rgba(255, 255, 255, 0.15);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #64748b;
  --accent-temp: #f97316;
  --accent-temp-glow: rgba(249, 115, 22, 0.25);
  --accent-hum: #0ea5e9;
  --accent-hum-glow: rgba(14, 165, 233, 0.25);
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.25);
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(at 0% 0%, rgba(56, 189, 248, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(139, 92, 246, 0.12) 0px, transparent 50%),
    radial-gradient(at 50% 100%, rgba(16, 185, 129, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 16px 40px;
  overflow-x: hidden;
}

.container {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   Header Bar & Brand Section
   ========================================================================== */

header {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.36);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(139, 92, 246, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #38bdf8;
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.15);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #ffffff 40%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-device {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

.device-tag {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  color: #cbd5e1;
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Live Status Beacon */
.status-beacon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.25);
  transition: all 0.3s ease;
}

.status-beacon.syncing {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.25);
}

.status-beacon.offline {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.25);
}

.beacon-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  position: relative;
}

.status-beacon.online .beacon-dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  animation: pulseRadar 1.8s infinite cubic-bezier(0, 0, 0.2, 1);
  opacity: 0.8;
}

@keyframes pulseRadar {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* Refresh Icon Button */
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: var(--card-hover-border);
}

.btn-icon:active {
  transform: scale(0.92);
}

.btn-icon.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  100% { transform: rotate(360deg); }
}

/* ==========================================================================
   Telemetry Cards (Suhu & Kelembapan)
   ========================================================================== */

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  padding: 18px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.32);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.card:hover {
  border-color: var(--card-hover-border);
  transform: translateY(-2px);
}

/* Ambient Radial Glows */
.card.temp-card::before {
  content: "";
  position: absolute;
  top: -30px;
  right: -30px;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, var(--accent-temp-glow), transparent 70%);
  pointer-events: none;
}

.card.hum-card::before {
  content: "";
  position: absolute;
  top: -30px;
  right: -30px;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, var(--accent-hum-glow), transparent 70%);
  pointer-events: none;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sensor-icon-pill {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.temp-card .sensor-icon-pill {
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid rgba(249, 115, 22, 0.25);
  color: #fb923c;
}

.hum-card .sensor-icon-pill {
  background: rgba(14, 165, 233, 0.15);
  border: 1px solid rgba(14, 165, 233, 0.25);
  color: #38bdf8;
}

.condition-pill {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.value-wrapper {
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin-bottom: 12px;
}

.value {
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.temp-card .value {
  background: linear-gradient(135deg, #fed7aa 0%, #fb923c 60%, #ea580c 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hum-card .value {
  background: linear-gradient(135deg, #bae6fd 0%, #38bdf8 60%, #0284c7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.unit {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Mini Progress Bar Gauge */
.mini-gauge {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.mini-gauge-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.temp-card .mini-gauge-fill {
  background: linear-gradient(90deg, #fb923c, #f97316);
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.5);
}

.hum-card .mini-gauge-fill {
  background: linear-gradient(90deg, #38bdf8, #0ea5e9);
  box-shadow: 0 0 10px rgba(14, 165, 233, 0.5);
}

.range-marks {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 0.62rem;
  color: var(--text-sub);
  font-weight: 600;
}

/* ==========================================================================
   Actuator / LED Control Card
   ========================================================================== */

.control-card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 22px 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.36);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.control-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-icon-pill {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.3s ease;
}

.control-card.is-on .control-icon-pill {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.3);
}

.control-card h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.control-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 1px;
}

/* Dynamic Lamp / Diode Visualizer */
.lamp-display-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 0;
  position: relative;
}

.lamp-aura {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.04) 0%, transparent 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.4s ease;
}

.control-card.is-on .lamp-aura {
  background: radial-gradient(circle, rgba(16, 185, 129, 0.3) 0%, rgba(16, 185, 129, 0.1) 45%, transparent 70%);
  box-shadow: 0 0 45px rgba(16, 185, 129, 0.3);
  animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.08); opacity: 1; }
}

.lamp-circle {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #1e293b;
  border: 2px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 2;
}

.control-card.is-on .lamp-circle {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: #6ee7b7;
  color: #ffffff;
  box-shadow: 0 0 25px rgba(16, 185, 129, 0.65), inset 0 0 10px rgba(255, 255, 255, 0.4);
}

.lamp-circle svg {
  width: 32px;
  height: 32px;
  transition: transform 0.3s ease;
}

.control-card.is-on .lamp-circle svg {
  transform: scale(1.1);
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.3s ease;
}

.status-badge.on {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.2);
}

.status-badge.syncing {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.35);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.2);
  animation: pulseSync 1.4s ease-in-out infinite;
}

@keyframes pulseSync {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(0.97); }
}

/* Big Toggle Button */
.btn-toggle-wrapper {
  margin-top: 16px;
}

button#toggleBtn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 16px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  position: relative;
}

button#toggleBtn:active:not(:disabled) {
  transform: scale(0.98);
}

button#toggleBtn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  filter: grayscale(0.2);
}

.btn-on {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.35) !important;
}

.btn-on:hover:not(:disabled) {
  background: linear-gradient(135deg, #34d399 0%, #059669 100%);
  box-shadow: 0 10px 28px rgba(16, 185, 129, 0.5) !important;
}

.btn-off {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.35) !important;
}

.btn-off:hover:not(:disabled) {
  background: linear-gradient(135deg, #f87171 0%, #dc2626 100%);
  box-shadow: 0 10px 28px rgba(239, 68, 68, 0.5) !important;
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.btn-loading .btn-spinner {
  display: block;
}

.btn-loading .btn-icon-svg {
  display: none;
}

/* ==========================================================================
   Diagnostics & Telemetry Footer Card
   ========================================================================== */

.footer-card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.footer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.last-update-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.last-update-row svg {
  color: var(--text-sub);
  flex-shrink: 0;
}

#lastUpdate {
  font-weight: 500;
}

.footer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.chip {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-sub);
  background: rgba(255, 255, 255, 0.04);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* ==========================================================================
   Toast Notification System
   ========================================================================== */

.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  max-width: 90%;
  width: 380px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #fff;
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 9999;
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.toast-container.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.toast-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toast-container.toast-success .toast-icon {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.toast-container.toast-error .toast-icon {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.toast-container.toast-info .toast-icon {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
}

/* Responsive Breakpoints */
@media (max-width: 360px) {
  .value { font-size: 1.9rem; }
  .grid { gap: 10px; }
  .card { padding: 14px 12px; }
}
