/* ===================================================
   WLTE Valve Control — Design System & Styles
   =================================================== */

/* --- Fonts & Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* --- Theme Variables --- */
/* LIGHT MODE (Default / Day Mode) */
:root {
  --c-bg: #F8FAFC;
  --c-surface: rgba(255, 255, 255, 0.8);
  --c-surface-hover: rgba(255, 255, 255, 0.95);
  --c-border: rgba(148, 163, 184, 0.16);
  --c-border-bright: rgba(148, 163, 184, 0.3);

  --c-purple: #7C3AED;
  --c-purple-light: #8B5CF6;
  --c-blue: #2563EB;
  --c-blue-light: #3B82F6;
  --c-cyan: #0891B2;
  --c-green: #059669;
  --c-green-light: #10B981;
  --c-red: #DC2626;
  --c-red-light: #EF4444;
  --c-yellow: #D97706;
  --c-gray: #64748B;

  --c-text: #0F172A;
  --c-text-dim: #334155;
  --c-text-muted: #64748B;

  --c-pipe-color: #E2E8F0;
  --c-pipe-inner: #CBD5E1;
  --c-valve-body-bg: #F1F5F9;
  --c-valve-body-border: #94A3B8;
  --c-valve-core: #CBD5E1;
  --c-gate-color: #94A3B8;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --shadow-glow-purple: 0 10px 30px rgba(124, 58, 237, 0.12), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-glow-green: 0 10px 30px rgba(5, 150, 105, 0.15), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-glow-red: 0 10px 30px rgba(220, 38, 38, 0.15), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 20px 40px -15px rgba(15, 23, 42, 0.05), 0 1px 0 rgba(255, 255, 255, 0.6) inset;

  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* DARK MODE (Night Mode Option) */
body.dark-theme {
  --c-bg: #090B11;
  --c-surface: rgba(17, 24, 39, 0.6);
  --c-surface-hover: rgba(31, 41, 55, 0.7);
  --c-border: rgba(255, 255, 255, 0.08);
  --c-border-bright: rgba(255, 255, 255, 0.16);

  --c-purple: #8B5CF6;
  --c-purple-light: #A78BFA;
  --c-blue: #3B82F6;
  --c-blue-light: #60A5FA;
  --c-cyan: #06B6D4;
  --c-green: #10B981;
  --c-green-light: #34D399;
  --c-red: #EF4444;
  --c-red-light: #F87171;
  --c-yellow: #F59E0B;
  --c-gray: #9CA3AF;

  --c-text: #F8FAFC;
  --c-text-dim: #CBD5E1;
  --c-text-muted: #64748B;

  --c-pipe-color: #1E293B;
  --c-pipe-inner: #0F172A;
  --c-valve-body-bg: #1E293B;
  --c-valve-body-border: #384252;
  --c-valve-core: #0F172A;
  --c-gate-color: #4B5563;

  --shadow-glow-purple: 0 0 40px rgba(139, 92, 246, 0.25), 0 4px 20px rgba(0, 0, 0, 0.5);
  --shadow-glow-green: 0 0 40px rgba(16, 185, 129, 0.3), 0 4px 20px rgba(0, 0, 0, 0.5);
  --shadow-glow-red: 0 0 40px rgba(239, 68, 68, 0.3), 0 4px 20px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 4px 32px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

html { font-size: 16px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  transition: background var(--transition), color var(--transition);
}

/* --- Background Grid & Orbs --- */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(124, 58, 237, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 58, 237, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  transition: background-image var(--transition);
}
body.dark-theme .bg-grid {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
}

.bg-orb {
  position: fixed; z-index: 0; border-radius: 50%;
  filter: blur(120px); pointer-events: none; opacity: 0.5;
  transition: background var(--transition);
}
.orb-1 {
  width: 600px; height: 600px;
  top: -200px; left: -200px;
  background: radial-gradient(circle, rgba(124, 58, 237, 0.08) 0%, transparent 70%);
}
body.dark-theme .orb-1 {
  background: radial-gradient(circle, rgba(139, 92, 246, 0.22) 0%, transparent 70%);
}
.orb-2 {
  width: 500px; height: 500px;
  bottom: -150px; right: -150px;
  background: radial-gradient(circle, rgba(8, 145, 178, 0.06) 0%, transparent 70%);
}
body.dark-theme .orb-2 {
  background: radial-gradient(circle, rgba(6, 182, 212, 0.15) 0%, transparent 70%);
}

/* --- Floating Theme Toggle FAB --- */
.theme-toggle-fab {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  color: var(--c-text-dim);
  outline: none;
}
.theme-toggle-fab:hover {
  background: var(--c-surface-hover);
  color: var(--c-text);
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 10px 20px rgba(0,0,0,0.08);
}
body.dark-theme .theme-toggle-fab:hover {
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

.theme-icon-container {
  position: relative;
  width: 20px;
  height: 20px;
}
.theme-icon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: opacity var(--transition), transform var(--transition);
}

/* Icons toggle animation */
.theme-icon.sun { opacity: 0; transform: rotate(90deg) scale(0.5); }
.theme-icon.moon { opacity: 1; transform: rotate(0) scale(1); }

body.dark-theme .theme-icon.sun { opacity: 1; transform: rotate(0) scale(1); }
body.dark-theme .theme-icon.moon { opacity: 0; transform: rotate(-90deg) scale(0.5); }

/* --- Screens --- */
.screen {
  position: relative; z-index: 1;
  display: none; min-height: 100vh;
}
.screen.active { display: flex; }

/* --- Modals --- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.active {
  opacity: 1; pointer-events: auto;
}
body.dark-theme .modal-overlay {
  background: rgba(0, 0, 0, 0.75);
}
.modal-card {
  transform: scale(0.95);
  transition: transform var(--transition);
}
.modal-overlay.active .modal-card {
  transform: scale(1);
}

/* --- Glass Card --- */
.glass-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-lg);
  transition: background var(--transition), border var(--transition), box-shadow var(--transition);
}

/* ===================================================
   SETUP SCREEN (Login)
   =================================================== */
#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.setup-card {
  width: 100%;
  max-width: 440px;
  padding: 44px 36px;
}

.logo-area {
  text-align: center;
  margin-bottom: 36px;
}
.logo-icon {
  width: 68px; height: 68px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.12), rgba(8, 145, 178, 0.12));
  border: 1px solid rgba(124, 58, 237, 0.25);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
}
.logo-icon svg { width: 100%; height: 100%; }
.logo-title {
  font-size: 1.625rem; font-weight: 800;
  background: linear-gradient(135deg, var(--c-purple) 0%, var(--c-cyan) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; margin-bottom: 6px;
}
body.dark-theme .logo-title {
  background: linear-gradient(135deg, #fff 0%, var(--c-purple-light) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-subtitle { color: var(--c-text-dim); font-size: 0.875rem; font-weight: 400; }

/* Form Elements */
.form-group { margin-bottom: 22px; }
.form-group label {
  display: block; font-size: 0.8125rem; font-weight: 600;
  color: var(--c-text-dim); margin-bottom: 8px; letter-spacing: 0.02em;
  text-transform: uppercase;
}
.input-wrapper {
  position: relative; display: flex; align-items: center;
}
.input-icon {
  position: absolute; left: 14px; width: 18px; height: 18px;
  color: var(--c-text-muted); pointer-events: none; flex-shrink: 0;
}
.input-wrapper input {
  width: 100%; height: 48px;
  background: rgba(148, 163, 184, 0.06);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text);
  font-family: inherit; font-size: 0.9375rem;
  padding: 0 44px 0 44px;
  outline: none;
  transition: all var(--transition);
}
.input-wrapper input:focus {
  border-color: var(--c-purple-light);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}
body.dark-theme .input-wrapper input:focus {
  background: rgba(17, 24, 39, 0.8);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.16);
}
.input-wrapper input::placeholder { color: var(--c-text-muted); }

.toggle-pass {
  position: absolute; right: 12px;
  background: none; border: none; cursor: pointer;
  color: var(--c-text-muted); padding: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition);
  outline: none;
}
.toggle-pass:hover { color: var(--c-text-dim); }
.eye-icon { width: 18px; height: 18px; }

.field-hint { font-size: 0.75rem; color: var(--c-text-muted); margin-top: 6px; padding-left: 2px; }

.error-banner {
  display: flex; align-items: center; gap: 10px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--c-red);
  font-size: 0.875rem;
  margin-bottom: 16px;
  animation: slideIn 0.2s ease;
}
body.dark-theme .error-banner {
  background: rgba(239, 68, 68, 0.12);
  color: var(--c-red-light);
}
.error-banner svg { width: 18px; height: 18px; flex-shrink: 0; }
.error-banner.hidden { display: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; font-family: inherit; font-weight: 600;
  border-radius: var(--radius-sm); transition: all var(--transition);
  text-decoration: none; position: relative; overflow: hidden;
  outline: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--c-purple), #6D28D9);
  color: white; font-size: 0.9375rem; height: 52px; width: 100%;
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.3);
}
.btn-primary:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(124, 58, 237, 0.4);
}
.btn-lg { font-size: 1rem; height: 56px; border-radius: var(--radius-md); }

.btn-ghost {
  background: transparent; color: var(--c-text-dim);
  border: 1px solid var(--c-border); font-size: 0.8125rem;
  padding: 6px 14px; height: 32px;
}
.btn-ghost:hover { background: rgba(0, 0, 0, 0.04); color: var(--c-text); }
body.dark-theme .btn-ghost:hover { background: var(--c-surface-hover); }

.btn-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--c-surface); border: 1px solid var(--c-border);
  color: var(--c-text-dim);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover {
  background: var(--c-surface-hover);
  color: var(--c-text);
  transform: translateY(-1px);
}
.btn-danger-icon:hover {
  background: rgba(239, 68, 68, 0.08);
  color: var(--c-red);
  border-color: rgba(239, 68, 68, 0.2);
}
body.dark-theme .btn-danger-icon:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--c-red-light);
  border-color: rgba(239, 68, 68, 0.3);
}

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

.setup-footer {
  text-align: center; font-size: 0.75rem;
  color: var(--c-text-muted); margin-top: 24px;
}

/* ===================================================
   CONTROL SCREEN
   =================================================== */
#control-screen {
  flex-direction: column;
  padding: 24px 20px;
  gap: 18px;
  min-height: 100vh;
}

.control-layout {
  width: 100%; max-width: 960px;
  margin: 0 auto;
  display: flex; flex-direction: column; gap: 18px;
}

/* Header */
.control-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-radius: var(--radius-md);
}
.header-left { display: flex; align-items: center; }
.header-device-info { display: flex; align-items: center; gap: 14px; }
.device-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-gray);
  box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.2);
  transition: all var(--transition);
  flex-shrink: 0;
}
.device-dot.online {
  background: var(--c-green-light);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25), 0 0 10px rgba(16, 185, 129, 0.4);
  animation: pulse-dot 2s infinite;
}
.device-dot.offline {
  background: var(--c-red);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
}

.header-title { font-size: 1.0625rem; font-weight: 700; color: var(--c-text); }
.header-device-id { font-size: 0.75rem; color: var(--c-text-dim); margin-top: 2px; font-family: monospace; }
.header-right { display: flex; align-items: center; gap: 12px; }

.header-status-badge {
  padding: 6px 14px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em;
  background: rgba(100, 116, 139, 0.1); color: var(--c-gray);
  border: 1px solid rgba(100, 116, 139, 0.15);
  transition: all var(--transition-slow);
  text-transform: uppercase;
}
.header-status-badge.online {
  background: rgba(5, 150, 105, 0.08); color: var(--c-green);
  border-color: rgba(5, 150, 105, 0.2);
}
body.dark-theme .header-status-badge.online {
  background: rgba(16, 185, 129, 0.15); color: var(--c-green-light);
  border-color: rgba(16, 185, 129, 0.25);
}
.header-status-badge.offline {
  background: rgba(220, 38, 38, 0.08); color: var(--c-red);
  border-color: rgba(220, 38, 38, 0.2);
}
body.dark-theme .header-status-badge.offline {
  background: rgba(239, 68, 68, 0.15); color: var(--c-red-light);
  border-color: rgba(239, 68, 68, 0.25);
}

/* Cards Row */
.cards-row {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 18px;
}

/* Card Common */
.card-header {
  display: flex; align-items: flex-start; gap: 14px;
  margin-bottom: 24px;
}
.card-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-icon svg { width: 22px; height: 22px; }
.card-icon--blue {
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.15);
  color: var(--c-blue);
}
body.dark-theme .card-icon--blue {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.25);
  color: var(--c-blue-light);
}
.card-icon--purple {
  background: rgba(124, 58, 237, 0.08);
  border: 1px solid rgba(124, 58, 237, 0.15);
  color: var(--c-purple);
}
body.dark-theme .card-icon--purple {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.25);
  color: var(--c-purple-light);
}
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 2px; color: var(--c-text); }
.card-subtitle { font-size: 0.75rem; color: var(--c-text-muted); }

/* --- System Status Card (Canal 1) --- */
.status-card { padding: 28px 24px; }
.status-indicator-area {
  display: flex; align-items: center; justify-content: center;
  padding: 24px 0;
}
.big-status-ring {
  width: 150px; height: 150px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.06);
  border: 4px solid var(--c-border);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: all var(--transition-slow);
}
.big-status-ring.active {
  border-color: var(--c-green);
  background: rgba(5, 150, 105, 0.02);
  box-shadow: 0 0 0 8px rgba(5, 150, 105, 0.06), 0 10px 40px rgba(5, 150, 105, 0.12);
}
body.dark-theme .big-status-ring.active {
  background: transparent;
  box-shadow: 0 0 0 8px rgba(16, 185, 129, 0.08), 0 0 45px rgba(16, 185, 129, 0.2);
}
.big-status-ring.inactive {
  border-color: var(--c-red);
  background: rgba(220, 38, 38, 0.02);
  box-shadow: 0 0 0 8px rgba(220, 38, 38, 0.06);
}
body.dark-theme .big-status-ring.inactive {
  background: transparent;
  box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.08);
}
.big-status-inner {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.big-status-icon { width: 38px; height: 38px; transition: color var(--transition); }
.big-status-icon svg { width: 100%; height: 100%; }

.big-status-ring.active .big-status-icon { color: var(--c-green); }
body.dark-theme .big-status-ring.active .big-status-icon { color: var(--c-green-light); }
.big-status-ring.inactive .big-status-icon { color: var(--c-red); }
body.dark-theme .big-status-ring.inactive .big-status-icon { color: var(--c-red-light); }
.big-status-ring:not(.active):not(.inactive) .big-status-icon { color: var(--c-gray); }

.big-status-label {
  font-size: 0.8125rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--c-text-muted);
  transition: color var(--transition);
}
.big-status-ring.active .big-status-label { color: var(--c-green); }
body.dark-theme .big-status-ring.active .big-status-label { color: var(--c-green-light); }
.big-status-ring.inactive .big-status-label { color: var(--c-red); }
body.dark-theme .big-status-ring.inactive .big-status-label { color: var(--c-red-light); }

.card-meta {
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--c-border);
  padding-top: 18px; margin-top: 12px;
}
.meta-label { font-size: 0.75rem; color: var(--c-text-muted); font-weight: 500; }
.meta-value {
  font-size: 0.875rem; font-weight: 700; color: var(--c-text-dim);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* --- Premium Valve Card (Canal 2) --- */
.valve-card { padding: 28px 24px; display: flex; flex-direction: column; gap: 0; }

.valve-visual-area {
  display: flex; align-items: center; gap: 28px;
  margin-bottom: 24px;
  flex: 1;
  background: rgba(148, 163, 184, 0.04);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
}
.valve-svg-wrapper {
  width: 170px; height: 110px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  flex-shrink: 0;
}
.valve-svg {
  width: 100%; height: 100%;
}

/* SVG Parts Dynamic Styling */
.valve-pipe-outer {
  stroke: var(--c-pipe-color);
  stroke-width: 24;
  transition: stroke var(--transition);
}
.valve-pipe-inner {
  stroke: var(--c-pipe-inner);
  stroke-width: 16;
  transition: stroke var(--transition);
}
.valve-body-outer {
  fill: var(--c-valve-body-bg);
  stroke: var(--c-valve-body-border);
  stroke-width: 3.5;
  transition: fill var(--transition), stroke var(--transition), filter var(--transition-slow);
}
.valve-body-inner {
  fill: var(--c-valve-core);
  transition: fill var(--transition);
}
.valve-gate-line {
  stroke: var(--c-gate-color);
  stroke-width: 6;
  transform-origin: 100px 60px;
  transition: transform var(--transition-slow), stroke var(--transition-slow);
}
.valve-status-light {
  fill: var(--c-gray);
  transition: fill var(--transition-slow), filter var(--transition-slow);
}

/* Flow animation path */
.flow-line {
  stroke-dashoffset: 0;
  animation: flowMove 1.5s linear infinite;
  display: none;
}

@keyframes flowMove {
  to { stroke-dashoffset: -27; }
}

/* Dynamic State Classes applied on #valve-container */
.valve-visual-area.state-open .flow-line {
  display: block;
}
.valve-visual-area.state-open .valve-gate-line {
  transform: rotate(90deg);
  stroke: var(--c-green);
}
.valve-visual-area.state-open .valve-body-outer {
  border-color: var(--c-green);
  stroke: var(--c-green);
}
.valve-visual-area.state-open .valve-status-light {
  fill: var(--c-green-light);
  filter: drop-shadow(0 0 3px var(--c-green));
  animation: indicator-pulse 2s infinite;
}

.valve-visual-area.state-closed .flow-line {
  display: none;
}
.valve-visual-area.state-closed .valve-gate-line {
  transform: rotate(0deg);
  stroke: var(--c-red);
}
.valve-visual-area.state-closed .valve-body-outer {
  stroke: var(--c-red);
}
.valve-visual-area.state-closed .valve-status-light {
  fill: var(--c-red);
  filter: drop-shadow(0 0 3px var(--c-red));
}

@keyframes indicator-pulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; filter: drop-shadow(0 0 5px var(--c-green-light)); }
}

.valve-state-text { flex: 1; }
.valve-badge-row { margin-bottom: 8px; }
.valve-state-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all var(--transition);
}
.valve-state-badge.open {
  background: rgba(5, 150, 105, 0.1);
  color: var(--c-green);
  border: 1px solid rgba(5, 150, 105, 0.2);
}
body.dark-theme .valve-state-badge.open {
  background: rgba(16, 185, 129, 0.15);
  color: var(--c-green-light);
  border-color: rgba(16, 185, 129, 0.3);
}
.valve-state-badge.closed {
  background: rgba(220, 38, 38, 0.1);
  color: var(--c-red);
  border: 1px solid rgba(220, 38, 38, 0.2);
}
body.dark-theme .valve-state-badge.closed {
  background: rgba(239, 68, 68, 0.15);
  color: var(--c-red-light);
  border-color: rgba(239, 68, 68, 0.3);
}
.valve-state-badge.unknown {
  background: rgba(100, 116, 139, 0.1);
  color: var(--c-gray);
  border: 1px solid rgba(100, 116, 139, 0.2);
}

.valve-state-label {
  display: block;
  font-size: 1.625rem; font-weight: 800;
  color: var(--c-text);
  margin-bottom: 6px;
  transition: all var(--transition);
}
.valve-state-desc { font-size: 0.8125rem; color: var(--c-text-muted); line-height: 1.45; }

/* Control Action Button */
.control-action-area { border-top: 1px solid var(--c-border); padding-top: 24px; }

.valve-control-btn {
  width: 100%; border: none; cursor: pointer;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
  transition: all var(--transition);
  position: relative; overflow: hidden;
}
.valve-control-btn::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(5, 150, 105, 0.06), rgba(8, 145, 178, 0.04));
  opacity: 0; transition: opacity var(--transition);
}
body.dark-theme .valve-control-btn::before {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(6, 182, 212, 0.08));
}
.valve-control-btn:not(:disabled):hover::before { opacity: 1; }
.valve-control-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.04);
  border-color: rgba(5, 150, 105, 0.4);
}
body.dark-theme .valve-control-btn:not(:disabled):hover {
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  border-color: rgba(16, 185, 129, 0.4);
}
.valve-control-btn:not(:disabled):active { transform: translateY(0); }
.valve-control-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Close variant styling */
.valve-control-btn.close-action::before {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.06), rgba(217, 119, 6, 0.04));
}
body.dark-theme .valve-control-btn.close-action::before {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.12), rgba(245, 158, 11, 0.08));
}
.valve-control-btn.close-action:not(:disabled):hover {
  border-color: rgba(220, 38, 38, 0.4);
}
body.dark-theme .valve-control-btn.close-action:not(:disabled):hover {
  border-color: rgba(239, 68, 68, 0.4);
}

.valve-btn-inner {
  display: flex; align-items: center; gap: 16px;
  position: relative; z-index: 1;
}
.valve-btn-icon {
  width: 44px; height: 44px;
  background: rgba(5, 150, 105, 0.06);
  border: 1px solid rgba(5, 150, 105, 0.15);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--c-green);
  transition: all var(--transition);
}
body.dark-theme .valve-btn-icon {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.25);
  color: var(--c-green-light);
}
.valve-control-btn.close-action .valve-btn-icon {
  background: rgba(220, 38, 38, 0.06);
  border-color: rgba(220, 38, 38, 0.15);
  color: var(--c-red);
}
body.dark-theme .valve-control-btn.close-action .valve-btn-icon {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--c-red-light);
}

.valve-btn-icon svg { width: 22px; height: 22px; }
.valve-btn-labels { flex: 1; text-align: left; }
.valve-btn-action { display: block; font-size: 1rem; font-weight: 700; color: var(--c-text); }
.valve-btn-desc { display: block; font-size: 0.75rem; color: var(--c-text-muted); margin-top: 2px; }

.valve-btn-spinner { width: 36px; height: 36px; flex-shrink: 0; }
.valve-btn-spinner.hidden { display: none; }
.spinner-ring {
  width: 32px; height: 32px;
  border: 3px solid rgba(124, 58, 237, 0.15);
  border-top-color: var(--c-purple);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
body.dark-theme .spinner-ring {
  border-color: rgba(255,255,255,0.15);
  border-top-color: var(--c-purple-light);
}

/* --- Log Card --- */
.log-card { padding: 24px; }
.log-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.log-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.log-list::-webkit-scrollbar { width: 4px; }
.log-list::-webkit-scrollbar-track { background: transparent; }
.log-list::-webkit-scrollbar-thumb { background: var(--c-border-bright); border-radius: 2px; }

.log-empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 32px;
  color: var(--c-text-muted); font-size: 0.875rem;
}
.log-empty svg { width: 36px; height: 36px; opacity: 0.4; }

.log-entry {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 14px;
  background: rgba(148, 163, 184, 0.02);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  animation: slideIn 0.2s ease;
}
.log-time { color: var(--c-text-muted); flex-shrink: 0; font-size: 0.75rem; font-family: monospace; }
.log-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; }
.log-dot.success { background: var(--c-green-light); }
.log-dot.error { background: var(--c-red); }
.log-dot.info { background: var(--c-blue); }
.log-dot.warn { background: var(--c-yellow); }
.log-msg { color: var(--c-text-dim); line-height: 1.5; flex: 1; }

/* --- Timestamp Footer --- */
.timestamp-footer {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 0.75rem; color: var(--c-text-muted);
  padding: 12px 0 6px;
}
.footer-sep { color: var(--c-border-bright); }

/* ===================================================
   ANIMATIONS
   =================================================== */
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25), 0 0 10px rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.1), 0 0 20px rgba(16, 185, 129, 0.6); }
}

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

@keyframes refresh-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.refreshing #refresh-btn svg { animation: refresh-spin 0.8s linear; }

/* ===================================================
   RESPONSIVE LAYOUT
   =================================================== */
@media (max-width: 768px) {
  .cards-row { grid-template-columns: 1fr; }
  #control-screen { padding: 14px; }
  .control-header { padding: 14px 18px; }
  .control-header .header-device-id { display: none; }
  .header-status-badge { display: none; }
  .setup-card { padding: 32px 24px; }
}

@media (max-width: 480px) {
  .valve-visual-area { flex-direction: column; align-items: center; text-align: center; gap: 16px; }
  .valve-state-text { display: flex; flex-direction: column; align-items: center; }
  .valve-btn-labels { text-align: center; }
  .valve-btn-inner { flex-direction: column; text-align: center; gap: 8px; }
}

/* ===================================================
   CONFIGURATION QUICK LINKS SECTION
   =================================================== */
.config-links-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--c-border);
}
.config-links-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--c-text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  text-align: left;
}
.config-links-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.config-link-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(148, 163, 184, 0.04);
  border: 1px solid var(--c-border);
  text-decoration: none;
  color: var(--c-text);
  transition: all var(--transition);
  text-align: left;
}
.config-link-card:hover {
  background: rgba(124, 58, 237, 0.05);
  border-color: rgba(124, 58, 237, 0.3);
  transform: translateY(-1px);
}
body.dark-theme .config-link-card:hover {
  background: rgba(139, 92, 246, 0.08);
  border-color: rgba(139, 92, 246, 0.35);
  transform: translateY(-1px);
}
.config-link-card svg {
  width: 20px;
  height: 20px;
  color: var(--c-purple);
  flex-shrink: 0;
  transition: transform var(--transition);
}
.config-link-card:hover svg {
  transform: scale(1.08);
}
.config-link-text {
  display: flex;
  flex-direction: column;
}
.config-link-name {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--c-text);
}
.config-link-url {
  font-size: 0.6875rem;
  color: var(--c-text-muted);
  margin-top: 1px;
}

/* ===================================================
   TABS NAVIGATION
   =================================================== */
.tabs-nav {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}
.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--c-text-muted);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
}
.tab-btn svg {
  width: 18px;
  height: 18px;
  transition: transform var(--transition);
}
.tab-btn:hover {
  color: var(--c-text-dim);
  background: rgba(148, 163, 184, 0.05);
}
.tab-btn.active {
  background: var(--c-surface-hover);
  color: var(--c-purple);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}
body.dark-theme .tab-btn.active {
  color: var(--c-purple-light);
  background: rgba(255, 255, 255, 0.04);
}
.tab-btn.active svg {
  transform: scale(1.05);
}
.tab-content {
  display: none;
  animation: slideIn 0.25s ease;
}
.tab-content.active {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ===================================================
   SAFETY WARNING BANNER & DISABLE TOGGLE
   =================================================== */
.safety-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.2);
  color: var(--c-red);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.03);
  animation: slideIn 0.2s ease;
}
body.dark-theme .safety-banner {
  background: rgba(239, 68, 68, 0.12);
  color: var(--c-red-light);
  border-color: rgba(239, 68, 68, 0.25);
}
.safety-banner svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--c-red);
}
body.dark-theme .safety-banner svg {
  color: var(--c-red-light);
}
.safety-banner.hidden {
  display: none;
}

/* Header button to disable app */
.btn-disable-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  transition: all var(--transition);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-dim);
  cursor: pointer;
}
.btn-disable-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform var(--transition);
}
.btn-disable-toggle:hover {
  background: var(--c-surface-hover);
  color: var(--c-text);
  border-color: var(--c-border-bright);
}
/* When App is Disabled (Safety State) */
.btn-disable-toggle.active {
  background: var(--c-red);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);
}
.btn-disable-toggle.active:hover {
  background: var(--c-red-light);
}

/* ===================================================
   SCHEDULER & TIMER CARDS UI
   =================================================== */
.config-card {
  padding: 28px 24px;
}
.card-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-top: 1px solid var(--c-border);
  padding-top: 20px;
  margin-top: 8px;
}

/* Weekday selectors */
.weekday-selector {
  display: flex;
  gap: 6px;
  justify-content: space-between;
  margin-top: 6px;
}
.day-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--c-border);
  background: rgba(148, 163, 184, 0.04);
  color: var(--c-text-dim);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  outline: none;
}
.day-badge:hover {
  background: rgba(148, 163, 184, 0.1);
  color: var(--c-text);
  border-color: var(--c-border-bright);
}
.day-badge.active {
  background: var(--c-purple);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 10px rgba(124, 58, 237, 0.25);
}
body.dark-theme .day-badge.active {
  background: var(--c-purple-light);
  box-shadow: 0 4px 10px rgba(139, 92, 246, 0.3);
}

/* Time inputs and numeric inputs */
.time-inputs-row {
  display: flex;
  gap: 16px;
}
.flex-1 {
  flex: 1;
}
.time-input, .num-input {
  width: 100%;
  height: 44px;
  background: rgba(148, 163, 184, 0.06);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text);
  font-family: inherit;
  font-size: 0.9375rem;
  padding: 0 14px;
  outline: none;
  transition: all var(--transition);
}
.time-input:focus, .num-input:focus {
  border-color: var(--c-purple-light);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.08);
}
body.dark-theme .time-input:focus, body.dark-theme .num-input:focus {
  background: rgba(17, 24, 39, 0.8);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}
.duration-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.duration-input-wrapper .num-input {
  padding-right: 80px;
}
.unit-label {
  position: absolute;
  right: 14px;
  font-size: 0.8125rem;
  color: var(--c-text-muted);
  font-weight: 500;
  pointer-events: none;
}

/* Custom CSS Toggle Switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-switch label {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--c-border-bright);
  transition: var(--transition);
  border-radius: 24px;
}
.toggle-switch label::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: var(--transition);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.toggle-switch input:checked + label {
  background-color: var(--c-green);
}
.toggle-switch input:checked + label::before {
  transform: translateX(20px);
}

/* Summary Banners */
.schedule-status-banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(148, 163, 184, 0.05);
  border: 1px solid var(--c-border);
  font-size: 0.8125rem;
  color: var(--c-text-dim);
  text-align: center;
  transition: all var(--transition);
}
.schedule-status-banner.active {
  background: rgba(5, 150, 105, 0.04);
  border-color: rgba(5, 150, 105, 0.15);
  color: var(--c-green);
}
body.dark-theme .schedule-status-banner.active {
  background: rgba(16, 185, 129, 0.08);
  color: var(--c-green-light);
}

/* Countdown Badge on Valve visual card */
.timer-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.15);
  color: var(--c-blue);
  margin-left: 6px;
  animation: timer-pulse 2s infinite;
}
body.dark-theme .timer-badge {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.25);
  color: var(--c-blue-light);
}
.timer-icon-svg {
  width: 12px;
  height: 12px;
  stroke-width: 2.5px;
}
.timer-badge.hidden {
  display: none;
}
@keyframes timer-pulse {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 1; transform: scale(1.02); }
}

/* Invalid Input Style */
.time-input.invalid-input {
  border-color: var(--c-red) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12) !important;
  background-color: rgba(220, 38, 38, 0.02) !important;
}
body.dark-theme .time-input.invalid-input {
  background-color: rgba(239, 68, 68, 0.05) !important;
  border-color: var(--c-red-light) !important;
}

/* ===================================================
   HISTORY TABLE STYLING
   =================================================== */
.history-table-container {
  overflow-x: auto;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  background: rgba(148, 163, 184, 0.02);
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}
.history-table th {
  padding: 14px 16px;
  font-weight: 600;
  color: var(--c-text-muted);
  border-bottom: 1px solid var(--c-border-bright);
  background: rgba(148, 163, 184, 0.05);
}
.history-table td {
  padding: 14px 16px;
  color: var(--c-text-dim);
  border-bottom: 1px solid var(--c-border);
}
.history-table tr:last-child td {
  border-bottom: none;
}
.history-table tr:hover td {
  background: rgba(148, 163, 184, 0.04);
}
.history-status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}
.history-status-badge.success {
  background: rgba(5, 150, 105, 0.1);
  color: var(--c-green);
}
.history-status-badge.error {
  background: rgba(220, 38, 38, 0.1);
  color: var(--c-red);
}

