/* ===== MX60 Dashboard — Sidebar Layout + Dark Industrial Theme ===== */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2236;
  --bg-card-hover: #1f2a42;
  --bg-sidebar: #0d1220;
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(0, 229, 255, 0.2);

  --text-primary: #e8edf5;
  --text-secondary: #8896b0;
  --text-muted: #4b5a75;

  --accent: #00e5ff;
  --accent-glow: rgba(0, 229, 255, 0.15);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.15);
  --yellow: #eab308;
  --yellow-glow: rgba(234, 179, 8, 0.15);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.15);
  --orange: #f97316;

  --sidebar-w: 240px;
  --topbar-h: 52px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Subtle grid bg */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 229, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.015) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.sidebar-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.sidebar-subtitle {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all var(--transition);
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active svg {
  opacity: 1;
}

.nav-item span:first-of-type {
  flex: 1;
}

.nav-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 8px;
}

.nav-item.active .nav-badge {
  background: rgba(0, 229, 255, 0.2);
  color: var(--accent);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.status-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.last-update {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.refresh-ring {
  position: relative;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.refresh-ring svg {
  transform: rotate(-90deg);
}

.refresh-progress {
  transition: stroke-dashoffset 1s linear;
}

.refresh-seconds {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ===== MOBILE TOPBAR ===== */
.topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: rgba(10, 14, 23, 0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 150;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.topbar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
}

.topbar-title {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.topbar-status {
  display: flex;
  align-items: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 190;
}

/* ===== MAIN CONTENT ===== */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

/* Pages */
.page {
  display: none;
  padding: 24px;
  flex: 1;
}

.page.active {
  display: block;
}

.page-header {
  margin-bottom: 20px;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== SUMMARY BAR ===== */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.summary-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}

.summary-card:hover {
  border-color: var(--border-accent);
}

.summary-online .summary-value { color: var(--green); }
.summary-offline .summary-value { color: var(--red); }

.summary-value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.summary-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
  font-weight: 600;
}

/* ===== OVERVIEW SECTIONS ===== */
.overview-section {
  margin-bottom: 24px;
}

.overview-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.overview-section-header h3 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.overview-link {
  font-size: 0.72rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: opacity var(--transition);
}

.overview-link:hover {
  opacity: 0.7;
}

/* Mini grid for overview — smaller cards */
.grid-mini .thermo-card {
  padding: 12px;
}

.grid-mini .thermo-metrics {
  gap: 6px;
  margin-bottom: 8px;
}

.grid-mini .metric {
  padding: 6px 4px;
}

.grid-mini .metric-value {
  font-size: 1rem;
}

.grid-mini .thermo-outputs {
  gap: 4px;
}

.grid-mini .output-badge {
  padding: 4px 0;
  font-size: 0.6rem;
}

/* ===== TAB BAR ===== */
.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  width: fit-content;
}

.tab {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.tab:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
}

.tab.active {
  background: var(--accent-glow);
  color: var(--accent);
}

/* ===== PLANTA GROUP ===== */
.planta-group {
  margin-bottom: 20px;
}

.planta-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.planta-group-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.planta-group-count {
  font-size: 0.62rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 8px;
}

/* ===== THERMOSTAT CARDS ===== */
.grid-thermostats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.thermo-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.thermo-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--text-muted);
  transition: background var(--transition);
}

.thermo-card.online::before {
  background: linear-gradient(90deg, var(--accent), var(--green));
}

.thermo-card.offline::before {
  background: var(--red);
}

.thermo-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.thermo-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.thermo-id {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.thermo-planta {
  font-size: 0.6rem;
  font-weight: 600;
  background: rgba(0, 229, 255, 0.1);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.02em;
}

.thermo-device {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.thermo-status {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 6px;
}

.thermo-status.online {
  background: var(--green-glow);
  color: var(--green);
}

.thermo-status.offline {
  background: var(--red-glow);
  color: var(--red);
}

.thermo-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.metric {
  text-align: center;
  padding: 8px 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.metric-value.null-value {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.metric-unit {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
}

.metric-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* Digital outputs row */
.thermo-outputs {
  display: flex;
  gap: 8px;
}

.output-badge {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 0;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-muted);
  transition: all var(--transition);
}

.output-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition);
}

.output-badge.active {
  background: var(--green-glow);
  color: var(--green);
}

.output-badge.active .output-led {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

/* ===== CARCAMO CARDS ===== */
.grid-carcamos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.carcamo-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all var(--transition);
}

.carcamo-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
}

.carcamo-card.carcamo-offline {
  opacity: 0.6;
  border-color: rgba(239, 68, 68, 0.15);
}

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

.carcamo-header > div {
  display: flex;
  flex-direction: column;
}

.carcamo-id {
  font-size: 1rem;
  font-weight: 700;
}

.carcamo-ubicacion {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 1px;
}

.carcamo-nivel {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.carcamo-nivel .null-tag {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.carcamo-bar-track {
  height: 22px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 11px;
  overflow: hidden;
  position: relative;
}

.carcamo-bar-fill {
  height: 100%;
  border-radius: 11px;
  transition: width 0.6s ease, background 0.3s ease;
  position: relative;
}

.carcamo-bar-fill.level-low {
  background: linear-gradient(90deg, #059669, var(--green));
}

.carcamo-bar-fill.level-mid {
  background: linear-gradient(90deg, var(--yellow), var(--orange));
}

.carcamo-bar-fill.level-high {
  background: linear-gradient(90deg, var(--orange), var(--red));
}

.carcamo-bar-text {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.carcamo-null {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 11px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ===== PRESION CARDS ===== */
.grid-presion {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.presion-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: all var(--transition);
}

.presion-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
}

.presion-card.presion-offline {
  opacity: 0.6;
  border-color: rgba(239, 68, 68, 0.15);
}

.presion-id {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.presion-ubicacion {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.presion-dual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.presion-metric {
  flex: 1;
  text-align: center;
}

.presion-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
  margin: 0 10px;
}

.presion-value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.presion-value-psi {
  color: var(--text-secondary);
  font-size: 1.3rem;
}

.presion-value.null-value {
  color: var(--text-muted);
  font-size: 1rem;
}

.presion-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.presion-hp-tag {
  font-size: 0.55rem;
  background: rgba(249, 115, 22, 0.2);
  color: var(--orange);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.presion-indicator {
  margin-top: 10px;
  height: 4px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.presion-indicator-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.6s ease;
}

.presion-hp .presion-value:not(.presion-value-psi) {
  color: var(--orange);
}

.presion-hp .presion-indicator-fill {
  background: var(--orange);
}

/* ===== FOOTER ===== */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  margin-top: auto;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.footer code {
  background: rgba(0, 229, 255, 0.08);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
}

/* ===== LOGIN OVERLAY ===== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  transition: opacity 0.3s ease;
}

.login-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}

.login-logo {
  margin-bottom: 16px;
}

.login-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-input-wrap {
  position: relative;
  margin-bottom: 8px;
}

.login-input {
  width: 100%;
  padding: 12px 44px 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.login-input:focus {
  border-color: var(--accent);
}

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

.login-toggle-pass {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
}

.login-toggle-pass:hover {
  color: var(--text-secondary);
}

.login-error {
  font-size: 0.75rem;
  color: var(--red);
  font-weight: 600;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: opacity var(--transition);
  margin-top: 4px;
}

.login-btn:hover {
  opacity: 0.85;
}

.login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== LOADING / ERROR ===== */
.loading-skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
  min-height: 160px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.error-banner {
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--red-glow);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 0.8rem;
  font-weight: 600;
  display: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .sidebar-overlay.open {
    display: block;
  }

  .topbar {
    display: flex;
  }

  .main {
    margin-left: 0;
    padding-top: var(--topbar-h);
  }

  .page {
    padding: 16px;
  }

  .summary-bar {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

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

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

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

  .footer {
    flex-direction: column;
    gap: 4px;
    text-align: center;
    padding: 12px 16px;
  }
}

@media (max-width: 480px) {
  .summary-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-carcamos,
  .grid-presion {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1400px) {
  .grid-thermostats {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1700px) {
  .grid-thermostats {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.thermo-card,
.carcamo-card,
.presion-card {
  animation: fadeIn 0.3s ease both;
}

.grid-thermostats .thermo-card:nth-child(n) {
  animation-delay: calc(0.03s * var(--i));
}
