:root {
  --bg-dark: #090d16;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --bg-panel: #0d1322;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #06b6d4;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --primary: #06b6d4;
  --primary-glow: rgba(6, 182, 212, 0.25);
  --accent-blue: #3b82f6;
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.2);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.2);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.2);
  
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace, Consolas, Courier;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(6, 182, 212, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(59, 130, 246, 0.05) 0%, transparent 40%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* Glassmorphism Card Utility */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

/* Header & Navigation */
header.app-header {
  height: 70px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(13, 19, 34, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px var(--primary-glow);
}

.brand-logo svg {
  width: 22px;
  height: 22px;
  stroke: #ffffff;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #f3f4f6, #9ca3af);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text .badge-env {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  background: rgba(6, 182, 212, 0.15);
  color: var(--primary);
  border: 1px solid rgba(6, 182, 212, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  margin-left: 6px;
}

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

.pulse-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #06b6d4, #2563eb);
  color: #ffffff;
  box-shadow: 0 0 12px var(--primary-glow);
}

.btn-primary:hover {
  filter: brightness(1.15);
  box-shadow: 0 0 18px var(--primary-glow);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-dim);
}

.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ffffff;
}

/* Main Container */
main.dashboard-content {
  flex: 1;
  padding: 2rem;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* KPI Summary Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
}

.kpi-card {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.kpi-card.kpi-success::before { background: var(--success); }
.kpi-card.kpi-warning::before { background: var(--warning); }
.kpi-card.kpi-danger::before { background: var(--danger); }

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.kpi-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-icon {
  width: 20px;
  height: 20px;
  color: var(--text-dim);
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: #ffffff;
  margin-bottom: 0.25rem;
}

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Main Two-Column Layout */
.dashboard-columns {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .dashboard-columns {
    grid-template-columns: 1fr;
  }
}

/* Section Header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Devices Grid */
.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.device-card {
  padding: 1.25rem;
  transition: var(--transition);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.device-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(6, 182, 212, 0.4);
  transform: translateY(-2px);
}

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.device-info h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.device-id {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.device-badges {
  display: flex;
  gap: 6px;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-comfort-ok {
  background: var(--success-glow);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-comfort-alert {
  background: var(--danger-glow);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.device-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.metric-box {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: #ffffff;
}

.metric-value span {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
}

.device-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 0.75rem;
}

/* Side Column / Controls */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel-block {
  padding: 1.25rem;
}

.panel-block h4 {
  font-size: 0.9rem;
  margin-bottom: 1rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Form Styles for Simulator & Login */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-input, .form-select {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.85rem;
  transition: var(--transition);
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 10px var(--primary-glow);
}

/* Chart Card & Enhanced Toolbar */
.chart-card {
  margin-top: 1.5rem;
  padding: 1.25rem;
}

.chart-header-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chart-controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.control-group label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.form-select-sm, .form-input-sm {
  background: rgba(13, 19, 34, 0.95);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.75rem;
  transition: var(--transition);
}

.form-select-sm:focus, .form-input-sm:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 8px var(--primary-glow);
}

.y-range-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.y-range-inputs input {
  width: 52px;
  font-family: var(--font-mono);
  text-align: center;
}

.range-separator {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.btn-xs:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.btn-xs.active {
  background: var(--primary);
  color: #090d16;
  border-color: var(--primary);
  box-shadow: 0 0 8px var(--primary-glow);
}

/* Chart Canvas Container & Tooltip */
.chart-container {
  width: 100%;
  height: 270px;
  position: relative;
  margin-top: 0.85rem;
  cursor: crosshair;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  background: rgba(13, 19, 34, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.6), 0 0 12px var(--primary-glow);
  font-size: 0.75rem;
  color: var(--text-main);
  white-space: nowrap;
  transform: translate(-50%, -100%);
  margin-top: -12px;
  transition: opacity 0.1s ease, transform 0.1s ease;
}

.chart-tooltip-header {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 4px;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  line-height: 1.4;
}

.chart-tooltip-label {
  color: var(--text-dim);
  font-size: 0.7rem;
}

.chart-tooltip-val {
  font-family: var(--font-mono);
  font-weight: 600;
}

.chart-tooltip-val.val-temp {
  color: var(--primary);
}

.chart-tooltip-val.val-hum {
  color: #60a5fa;
}

.chart-tooltip-val.val-device {
  color: #f3f4f6;
}

/* TDI Color Scale Bar & Badges */
.tdi-scale-bar-wrapper {
  margin-top: 0.85rem;
  padding: 0.65rem 0.85rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tdi-scale-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.45rem;
  font-size: 0.72rem;
}

.tdi-scale-title {
  color: var(--text-muted);
  font-weight: 600;
}

.tdi-scale-legend-hint {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.tdi-gradient-track {
  height: 7px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    #22c55e 0%,      /* <= 20 Verde Confort */
    #84cc16 18%,     /* 25 Verde-Lima */
    #facc15 36%,     /* 30 Amarillo Moderado */
    #fb923c 54%,     /* 35 Naranja Alto */
    #ea580c 72%,     /* 40 Naranja Oscuro */
    #ef4444 85%,     /* 45 Rojo Crítico */
    #a855f7 100%     /* >= 50 Magenta/Púrpura Peligro */
  );
  margin-bottom: 0.4rem;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
}

.tdi-scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  font-weight: 600;
  flex-wrap: wrap;
  gap: 4px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  stroke: var(--text-dim);
  margin-bottom: 1rem;
}

/* Login Page Fullscreen Layout */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
  border-radius: var(--radius-lg);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header .brand-logo {
  margin: 0 auto 1rem auto;
  width: 48px;
  height: 48px;
}

.login-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.login-header p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.alert-box {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  margin-bottom: 1.25rem;
  display: none;
}

.alert-danger {
  background: var(--danger-glow);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.alert-success {
  background: var(--success-glow);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}
