/* ===== CSS Variables ===== */
:root {
  /* Brand Colors */
  --gold: #E0C051;
  --cream: #F3E7BD;
  --dark: #212529;
  
  /* Background Colors */
  --bg-dark: #0f1216;
  --bg-medium: #1a1d23;
  --bg-light: #212529;
  
  /* Primary & Accents */
  --primary: #E0C051;
  --primary-light: #F3E7BD;
  --primary-glow: rgba(224, 192, 81, 0.4);
  --secondary: #c9a843;
  --accent: #F3E7BD;
  
  /* Text Colors */
  --text-primary: rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(255, 255, 255, 0.65);
  --text-muted: rgba(255, 255, 255, 0.45);
  
  /* Borders & Panels */
  --border: rgba(255, 255, 255, 0.10);
  --border-light: rgba(255, 255, 255, 0.06);
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.08);
  
  /* Status Colors (keep semantic) */
  --status-ok: #10b981;
  --status-warn: #f59e0b;
  --status-error: #ef4444;
  
  /* Shadows & Effects */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --glow: 0 0 20px rgba(224, 192, 81, 0.3);
  --glow-strong: 0 0 30px rgba(224, 192, 81, 0.5);
  
  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Rajdhani', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-dark);
  line-height: 1.6;
  position: relative;
}

/* ===== Animated Background ===== */
.ambient-bg {
  position: fixed;
  inset: 0;
  background: 
    radial-gradient(circle at 20% 30%, rgba(224, 192, 81, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(243, 231, 189, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 50% 100%, rgba(33, 37, 41, 0.8) 0%, transparent 60%);
  z-index: -2;
  animation: ambientShift 20s ease-in-out infinite;
}

@keyframes ambientShift {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.05); }
}

/* Scan Lines Effect */
.scan-lines {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0) 0px,
    rgba(224, 192, 81, 0.03) 1px,
    rgba(0, 0, 0, 0) 2px
  );
  pointer-events: none;
  z-index: -1;
  opacity: 0.5;
}

/* ===== Layout ===== */
.wrap {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  position: relative;
  z-index: 1;
}

/* ===== Header ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
  padding: 20px 24px;
  background: linear-gradient(135deg, rgba(33, 37, 41, 0.6), rgba(26, 29, 35, 0.4));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
  animation: slideDown 0.6s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.logo-container {
  position: relative;
  width: 70px;
  height: 70px;
}

.logo {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  background-image: url("/logo.png");
  background-size: cover;
  background-position: center;
  border: 2px solid var(--primary);
  box-shadow: var(--shadow-md), var(--glow);
  position: relative;
  z-index: 2;
  transition: transform 0.3s ease;
}

.logo:hover {
  transform: scale(1.05);
}

.logo-glow {
  position: absolute;
  inset: -4px;
  background: var(--primary);
  border-radius: var(--radius-md);
  opacity: 0.3;
  filter: blur(12px);
  z-index: 1;
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.05); }
}

.brand-info h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin: 0;
  background: linear-gradient(135deg, var(--gold), var(--cream));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-info p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 2px 0 0;
  letter-spacing: 0.3px;
}

.auth-status {
  display: flex;
  gap: 12px;
}

/* ===== Status Badge ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(33, 37, 41, 0.6);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  backdrop-filter: blur(8px);
  transition: all 0.3s ease;
}

.status-badge.small {
  padding: 6px 12px;
  font-size: 12px;
}

.status-badge:hover {
  background: rgba(33, 37, 41, 0.8);
  border-color: var(--primary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  box-shadow: 0 0 8px rgba(100, 116, 139, 0.5);
  transition: all 0.3s ease;
}

.status-dot.ok {
  background: var(--status-ok);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.6);
  animation: dotPulse 2s ease-in-out infinite;
}

.status-dot.warn {
  background: var(--status-warn);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
}

.status-dot.bad {
  background: var(--status-error);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
}

@keyframes dotPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.8; }
}

.status-text {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===== Dashboard Grid ===== */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 24px;
  animation: fadeIn 0.8s ease-out 0.2s both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-auth {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
}

.card-devices {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
}

.card-readings {
  grid-column: 1 / 3;
  grid-row: 2 / 3;
}

@media (max-width: 1200px) {
  .dashboard {
    grid-template-columns: 1fr;
  }
  
  .card-auth,
  .card-devices,
  .card-readings {
    grid-column: 1 / 2;
    grid-row: auto;
  }
}

/* ===== Cards ===== */
.card {
  background: linear-gradient(135deg, rgba(33, 37, 41, 0.5), rgba(26, 29, 35, 0.3));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0.5;
}

.card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), 0 0 32px rgba(224, 192, 81, 0.15);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

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

.card-icon {
  font-size: 24px;
  filter: drop-shadow(0 0 8px var(--primary-glow));
}

.card-title h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Form Elements ===== */
.input-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.input-group.flex-2 { flex: 2; }
.input-group.flex-1 { flex: 1; }

.input-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input,
select {
  width: 100%;
  padding: 12px 16px;
  background: rgba(15, 18, 22, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Rajdhani', sans-serif;
  font-size: 15px;
  font-weight: 500;
  outline: none;
  transition: all 0.3s ease;
}

input:focus,
select:focus {
  border-color: var(--primary);
  background: rgba(15, 18, 22, 0.8);
  box-shadow: 0 0 0 3px rgba(224, 192, 81, 0.1);
}

input::placeholder {
  color: var(--text-muted);
}

.select-wrapper {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.select-wrapper select {
  flex: 1;
}

/* ===== Buttons ===== */
.button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.button-row.secondary-actions {
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(33, 37, 41, 0.6);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
  width: 300px;
  height: 300px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 16px;
  font-weight: 700;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--secondary));
  border-color: var(--gold);
  color: var(--dark);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(224, 192, 81, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(224, 192, 81, 0.5);
  border-color: var(--cream);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--cream), #d4c49a);
  border-color: var(--cream);
  color: var(--dark);
  box-shadow: 0 4px 12px rgba(243, 231, 189, 0.3);
}

.btn-secondary:hover {
  box-shadow: 0 6px 20px rgba(243, 231, 189, 0.5);
}

.btn-danger {
  background: linear-gradient(135deg, var(--status-error), #dc2626);
  border-color: var(--status-error);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover {
  background: rgba(33, 37, 41, 0.6);
  border-color: var(--primary);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 12px;
}

.btn-icon-only {
  padding: 10px;
  min-width: 40px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.spin-on-hover {
  transition: transform 0.6s ease;
}

.btn:hover .spin-on-hover {
  transform: rotate(360deg);
}

/* ===== Device Section ===== */
.device-selector-section {
  display: flex;
  gap: 16px;
}

.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 8px 0;
}

.claim-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-subtitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

/* ===== Current Readings Display ===== */
.current-readings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 0;
}

.reading-card {
  background: linear-gradient(135deg, rgba(33, 37, 41, 0.6), rgba(26, 29, 35, 0.4));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.reading-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 20px rgba(224, 192, 81, 0.15);
}

.reading-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.reading-card:hover::before {
  opacity: 1;
}

.reading-icon {
  font-size: 32px;
  filter: drop-shadow(0 0 8px var(--primary-glow));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-5px); }
}

.reading-card:nth-child(2) .reading-icon {
  animation-delay: 0.5s;
}

.reading-card:nth-child(3) .reading-icon {
  animation-delay: 1s;
}

.reading-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.reading-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.reading-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  font-family: 'Rajdhani', sans-serif;
  text-shadow: 0 0 10px rgba(224, 192, 81, 0.3);
}

.reading-unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.reading-indicator {
  width: 4px;
  height: 60px;
  border-radius: 2px;
  position: relative;
  overflow: hidden;
  background: rgba(100, 116, 139, 0.2);
}

.reading-indicator::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: currentColor;
  transition: height 1s ease;
  box-shadow: 0 0 10px currentColor;
}

.reading-card:hover .reading-indicator::after {
  height: 100%;
}

.reading-indicator.temp {
  color: #fc1d00;
}

.reading-indicator.humidity {
  color: #001aff;
}

.reading-indicator.sound {
  color: #f0b400;
}

@media (max-width: 768px) {
  .current-readings {
    grid-template-columns: 1fr;
  }
  
  .reading-value {
    font-size: 28px;
  }
  
  .reading-icon {
    font-size: 28px;
  }
}

/* ===== Chart ===== */
.chart-container {
  background: rgba(15, 18, 22, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  min-height: 450px;
  position: relative;
  overflow: hidden;
}

.chart-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 40px,
    rgba(224, 192, 81, 0.02) 40px,
    rgba(224, 192, 81, 0.02) 41px
  );
  pointer-events: none;
}

.legend-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  box-shadow: 0 0 8px currentColor;
}

.legend-dot.temp {
  background: #fc1d00;
}

.legend-dot.humidity {
  background: #001aff;
}

.legend-dot.sound {
  background: #f0b400;
}

/* ===== Helper Text ===== */
.helper-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.chart-info {
  text-align: center;
  padding-top: 8px;
}

/* ===== Footer ===== */
.footer {
  margin-top: 48px;
  padding: 24px;
  text-align: center;
  border-top: 1px solid var(--border-light);
}

.footer p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  width: min(1000px, 100%);
  max-height: 85vh;
  background: linear-gradient(135deg, rgba(33, 37, 41, 0.95), rgba(26, 29, 35, 0.95));
  border: 1px solid var(--primary);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(224, 192, 81, 0.3);
  overflow: hidden;
  animation: modalSlide 0.4s ease-out;
}

@keyframes modalSlide {
  from { opacity: 0; transform: scale(0.95) translateY(-20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  background: rgba(15, 18, 22, 0.6);
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin: 0;
  color: var(--primary);
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(85vh - 80px);
}

.console {
  width: 100%;
  height: 55vh;
  max-height: 55vh;
  overflow: auto;
  background: rgba(15, 18, 22, 0.8);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.console > div {
  padding: 4px 0;
  border-left: 2px solid transparent;
  padding-left: 8px;
  margin-bottom: 4px;
}

.console .statusOk {
  border-left-color: var(--status-ok);
  color: #6ee7b7;
}

.console .statusWarn {
  border-left-color: var(--status-warn);
  color: #fcd34d;
}

.console .statusBad {
  border-left-color: var(--status-error);
  color: #fca5a5;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
  .wrap {
    padding: 16px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .auth-status {
    width: 100%;
  }

  .status-badge {
    width: 100%;
    justify-content: center;
  }

  .card {
    padding: 20px;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .button-row {
    flex-direction: column;
    width: 100%;
  }

  .btn {
    width: 100%;
  }

  .chart-container {
    min-height: 350px;
  }

  .legend-row {
    flex-direction: column;
    gap: 12px;
  }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(33, 37, 41, 0.5);
}

::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--cream);
}