/* PSA Monitor - Estilos */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.layout { min-height: 100vh; }

.nav {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-brand a { color: #f1f5f9; text-decoration: none; font-size: 1.1rem; display: flex; align-items: center; }
.nav-logo { height: 32px; width: auto; }
.nav-links { display: flex; gap: 1.5rem; align-items: center; }
.nav-links a { color: #94a3b8; font-size: 0.9rem; }
.nav-links a.active { color: #60a5fa; }
.nav-links a:hover { color: #f1f5f9; text-decoration: none; }
.nav-logout { color: #f87171 !important; }

.main-content { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.page-header h1 { font-size: 1.5rem; display: flex; align-items: center; gap: 0.5rem; }
.subtitle { color: #94a3b8; margin-top: 0.25rem; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 0.875rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #334155; text-decoration: none; }
.btn-primary { background: #F5B800; border-color: #F5B800; color: #0f172a; font-weight: 600; }
.btn-primary:hover { background: #d9a400; border-color: #d9a400; }
.btn-danger { background: #dc2626; border-color: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-small { padding: 0.25rem 0.75rem; font-size: 0.8rem; }

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

.device-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 1.25rem;
  display: block;
  color: #e2e8f0;
  transition: border-color 0.2s;
}
.device-card:hover { border-color: #60a5fa; text-decoration: none; }

.device-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.device-id { font-weight: 700; font-size: 1.1rem; }
.device-name { color: #94a3b8; font-size: 0.9rem; }
.device-location { color: #64748b; font-size: 0.8rem; margin-top: 0.25rem; }
.device-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: #64748b;
}

/* Status dot */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #64748b;
}
.status-dot.online { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-dot.offline { background: #64748b; }

/* Device info bar */
.device-info {
  display: flex;
  gap: 2rem;
  padding: 1rem;
  background: #1e293b;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

/* ===== Control Panel ===== */
.control-panel { }

/* Status bar */
.panel-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}
.panel-status-left { display: flex; align-items: center; gap: 1rem; }
.panel-status-right { }
.panel-stat { font-size: 0.8rem; color: #94a3b8; }
.panel-time { font-size: 0.8rem; color: #64748b; font-family: monospace; }

.stream-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stream-badge.connected {
  background: rgba(245, 184, 0, 0.15);
  color: #F5B800;
  border: 1px solid rgba(245, 184, 0, 0.3);
}
.stream-badge.disconnected { background: #7f1d1d; color: #f87171; border: 1px solid #991b1b; }

/* Section titles */
.panel-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: #F5B800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
  padding-left: 0.25rem;
  border-left: 3px solid #F5B800;
  padding: 0.15rem 0 0.15rem 0.75rem;
}

/* Gauge grid */
.gauge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.gauge-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 0.75rem 0.5rem 0.5rem;
  text-align: center;
  transition: border-color 0.3s;
}
.gauge-card:hover { border-color: #F5B800; }

.gauge-svg {
  width: 100%;
  max-width: 200px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.gauge-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #cbd5e1;
  margin-top: 0.25rem;
  letter-spacing: 0.03em;
}

/* Valve grid */
.valve-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.valve-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1rem 0.5rem 0.75rem;
  text-align: center;
  transition: all 0.4s ease;
}
.valve-card.valve-open {
  border-color: rgba(245, 184, 0, 0.4);
  box-shadow: 0 0 12px rgba(245, 184, 0, 0.08);
}
.valve-card.valve-alarm.valve-open {
  border-color: rgba(239, 68, 68, 0.5);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.15);
}

.valve-svg {
  width: 56px;
  height: 56px;
  display: block;
  margin: 0 auto 0.5rem;
}

.valve-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 0.2rem;
}

.valve-state {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.4s;
}

/* Empty / waiting */
.readings-empty {
  text-align: center;
  padding: 3rem;
  color: #64748b;
}
.readings-empty .hint { font-size: 0.85rem; margin-top: 0.5rem; }

/* Raw JSON */
.raw-json {
  margin-top: 1rem;
  padding: 1rem;
  background: #0f172a;
  border-radius: 6px;
  font-size: 0.8rem;
  overflow-x: auto;
  color: #94a3b8;
  font-family: monospace;
}

/* Login */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.login-logo { display: block; margin: 0 auto 1.25rem; height: 60px; width: auto; }
.login-box h1 { font-size: 1.5rem; text-align: center; }
.login-box .subtitle { text-align: center; color: #64748b; margin-bottom: 1.5rem; }

/* Forms */
.form { max-width: 500px; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; color: #94a3b8; margin-bottom: 0.25rem; }
.field input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 0.9rem;
}
.field input:focus { outline: none; border-color: #3b82f6; }
.field small { display: block; color: #64748b; font-size: 0.75rem; margin-top: 0.25rem; }
.form-actions { display: flex; gap: 1rem; margin-top: 1.5rem; }

.login-box button[type="submit"] {
  width: 100%;
  padding: 0.6rem;
  background: #F5B800;
  border: none;
  border-radius: 6px;
  color: #0f172a;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 0.5rem;
}
.login-box button[type="submit"]:hover { background: #d9a400; }

/* Alerts */
.error {
  background: #7f1d1d;
  border: 1px solid #991b1b;
  color: #fecaca;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.success-box {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 1.5rem;
}
.success-box p { margin-bottom: 0.75rem; }
.token-display {
  background: #0f172a;
  border: 1px solid #334155;
  padding: 1rem;
  border-radius: 6px;
  margin: 1rem 0;
  word-break: break-all;
}
.token-display code { color: #22c55e; font-size: 1rem; }
.warning { color: #fbbf24; font-size: 0.85rem; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: #64748b;
}
.empty-state .btn { margin-top: 1rem; }

/* Responsive */
@media (max-width: 640px) {
  .gauge-grid { grid-template-columns: repeat(2, 1fr); }
  .valve-grid { grid-template-columns: repeat(3, 1fr); }
  .device-grid { grid-template-columns: 1fr; }
  .nav { padding: 0 1rem; }
  .main-content { padding: 1rem; }
  .panel-status-bar { flex-direction: column; gap: 0.5rem; }
  .panel-status-left { flex-wrap: wrap; }
}
