/* ==========================================================================
   SIMULATORE POMPA IDRAULICA - DESIGN SYSTEM & STYLES (Vanilla CSS)
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-subtle: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #38bdf8;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --primary: #0284c7;
  --primary-light: #e0f2fe;
  --primary-hover: #0369a1;
  --primary-glow: rgba(14, 165, 233, 0.35);
  
  --success: #059669;
  --success-light: #ecfdf5;
  --success-border: #a7f3d0;
  
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --danger-border: #fecaca;
  
  --warning-bg: #fffbeb;
  --warning-border: #fef3c7;
  --warning-text: #92400e;
  --warning-accent: #d97706;

  --water-blue: #0ea5e9;
  --water-cyan: #38bdf8;
  --water-dark: #0369a1;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Shadows & Radius */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.06);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 1280px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.header-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .header-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.65rem;
  font-weight: 800;
  color: #1e293b;
  letter-spacing: -0.025em;
}

.header-title-icon {
  width: 2rem;
  height: 2rem;
  color: var(--primary);
}

.header-subtitle {
  font-size: 0.925rem;
  color: var(--text-secondary);
  max-width: 680px;
}

.pump-master-control {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  background: var(--bg-card-subtle);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  align-self: flex-start;
}

@media (min-width: 768px) {
  .pump-master-control {
    align-self: center;
  }
}

.pump-status-info {
  display: flex;
  flex-direction: column;
}

.status-label {
  font-size: 0.725rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.status-value {
  font-size: 0.95rem;
  font-weight: 700;
  transition: color 0.25s ease;
}

.status-value.running {
  color: var(--water-blue);
  text-shadow: 0 0 10px rgba(14, 165, 233, 0.4);
}

.status-value.stopped {
  color: var(--text-muted);
}

/* Master Power Button */
.btn-power-master {
  width: 3.75rem;
  height: 3.75rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  outline: none;
  position: relative;
}

.btn-power-master svg {
  width: 1.85rem;
  height: 1.85rem;
  transition: transform 0.3s ease;
}

.btn-power-master.off {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
}

.btn-power-master.off:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4);
}

.btn-power-master.on {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: #ffffff;
  animation: pulse-pump-button 2s infinite;
}

.btn-power-master.on:hover {
  transform: scale(1.05);
}

@keyframes pulse-pump-button {
  0% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.6); }
  70% { box-shadow: 0 0 0 14px rgba(14, 165, 233, 0); }
  100% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0); }
}

/* ==========================================================================
   STATUS BANNER
   ========================================================================== */
.alert-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-md);
  color: var(--warning-text);
  box-shadow: var(--shadow-sm);
}

.alert-banner svg {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  color: var(--warning-accent);
}

.alert-content {
  font-size: 0.925rem;
  line-height: 1.45;
}

.alert-details {
  display: block;
  font-size: 0.85rem;
  margin-top: 0.25rem;
  color: #b45309;
}

.highlight-badge {
  background: rgba(217, 119, 6, 0.15);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ==========================================================================
   MAIN DASHBOARD GRID
   ========================================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

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

/* ==========================================================================
   LEFT COLUMN: SCHEMATIC & PARAMETERS
   ========================================================================== */
.sidebar-col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  margin-bottom: 1.25rem;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Tank & Pump Schematic */
.schematic-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0rem;
  padding: 1rem 0;
}

/* Water Tank Visual */
.tank-outer {
  position: relative;
  width: 150px;
  height: 200px;
  border: 4px solid #cbd5e1;
  border-top: none;
  border-radius: 0 0 24px 24px;
  background: #f8fafc;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.06);
}

.tank-cap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 14px;
  background: #e2e8f0;
  border-bottom: 2px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tank-water {
  width: 100%;
  height: 65%;
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  position: relative;
  transition: height 0.6s ease;
  opacity: 0.88;
}

.tank-wave {
  position: absolute;
  top: -8px;
  left: 0;
  width: 200%;
  height: 12px;
  background: radial-gradient(circle at 50% 100%, transparent 60%, #38bdf8 61%);
  background-size: 24px 12px;
  opacity: 0.7;
}

.pump-active .tank-wave {
  animation: wave-motion 1.8s linear infinite;
}

@keyframes wave-motion {
  from { transform: translateX(0); }
  to { transform: translateX(-48px); }
}

.tank-level-badge {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  pointer-events: none;
}

/* Pipe segment */
.pipe-vertical {
  width: 24px;
  height: 34px;
  background: #e2e8f0;
  border-left: 4px solid #cbd5e1;
  border-right: 4px solid #cbd5e1;
  position: relative;
  overflow: hidden;
  transition: background 0.3s;
}

.pump-active .pipe-vertical {
  background: #0ea5e9;
}

.pump-active .pipe-vertical::after {
  content: '';
  position: absolute;
  top: -100%;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  animation: pipe-flow 0.8s linear infinite;
}

@keyframes pipe-flow {
  0% { transform: translateY(0); }
  100% { transform: translateY(200%); }
}

/* Centrifugal Pump Visual */
.pump-container {
  position: relative;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: 5px solid #cbd5e1;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.pump-active .pump-container {
  border-color: #38bdf8;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.4);
}

.pump-impeller {
  width: 58px;
  height: 58px;
  color: #94a3b8;
  transition: color 0.3s;
}

.pump-active .pump-impeller {
  color: var(--primary);
  animation: spin-impeller 0.6s linear infinite;
}

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

.pump-out-badge {
  position: absolute;
  right: -24px;
  top: 50%;
  transform: translateY(-50%);
  background: #1e293b;
  color: #f8fafc;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

/* Parameters Form */
.param-group {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.param-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.param-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.param-unit {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.param-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.param-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: all 0.2s ease;
  outline: none;
}

.param-input:focus {
  border-color: var(--border-focus);
  background: #ffffff;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.param-slider {
  margin-top: 0.35rem;
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Live Total Overview in Sidebar */
.metric-summary-card {
  margin-top: 1rem;
  background: #0f172a;
  color: #f8fafc;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  border: 1px solid #1e293b;
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.metric-item-label {
  font-size: 0.725rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.metric-item-value {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 800;
  color: #38bdf8;
}

/* ==========================================================================
   RIGHT COLUMN: VALVE MANAGEMENT
   ========================================================================== */
.valves-col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.valve-groups-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .valve-groups-container {
    grid-template-columns: 1fr 1fr;
  }
}

.valve-group-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.valve-group-card.excess-group {
  grid-column: 1 / -1;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.group-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.group-tag {
  font-size: 0.725rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.03em;
}

.group-tag.manual {
  background: #f1f5f9;
  color: #475569;
}

.group-tag.auto {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

/* Valves Grid */
.valves-grid-2x2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

@media (max-width: 480px) {
  .valves-grid-2x2 {
    grid-template-columns: 1fr;
  }
}

.valves-grid-4x1 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
}

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

/* ==========================================================================
   INDIVIDUAL VALVE CONTROL COMPONENT
   ========================================================================== */
.valve-card {
  position: relative;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 1rem;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.valve-card:hover {
  border-color: #cbd5e1;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* Open Valve State */
.valve-card.is-open {
  background: #f0f9ff;
  border-color: #bae6fd;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.12);
}

/* Liquid Flow Animated Overlay */
.valve-flow-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(56, 189, 248, 0.25), transparent 75%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.valve-card.is-flowing .valve-flow-overlay {
  opacity: 1;
  animation: flow-pulse 2.2s ease-in-out infinite;
}

@keyframes flow-pulse {
  0%, 100% { opacity: 0.15; transform: scale(0.98); }
  50% { opacity: 0.45; transform: scale(1.02); }
}

.valve-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
}

.valve-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: #334155;
}

.valve-icon-wrap {
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  transition: color 0.25s;
}

.valve-card.is-open .valve-icon-wrap {
  color: #38bdf8;
}

.valve-card.is-flowing .valve-icon-wrap {
  color: #0284c7;
  animation: drop-bounce 1.5s infinite;
}

@keyframes drop-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.valve-middle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  position: relative;
  z-index: 2;
}

.valve-badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  transition: all 0.2s;
}

.valve-badge.open {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.valve-badge.closed {
  background: #f1f5f9;
  color: #64748b;
}

/* Individual Valve Toggle Button */
.btn-valve-toggle {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  outline: none;
}

.btn-valve-toggle svg {
  width: 1.1rem;
  height: 1.1rem;
}

.btn-valve-toggle.action-open {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.btn-valve-toggle.action-open:hover:not(:disabled) {
  background: #d1fae5;
  transform: scale(1.05);
}

.btn-valve-toggle.action-close {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.btn-valve-toggle.action-close:hover:not(:disabled) {
  background: #fee2e2;
  transform: scale(1.05);
}

.btn-valve-toggle:disabled {
  background: #f1f5f9;
  color: #cbd5e1;
  border: 1px solid #e2e8f0;
  cursor: not-allowed;
  opacity: 0.65;
  transform: none !important;
}

/* Metrics Section at bottom of card */
.valve-metrics {
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(226, 232, 240, 0.8);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-size: 0.725rem;
  position: relative;
  z-index: 2;
}

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

.metric-label {
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
}

.metric-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #0369a1;
  font-size: 0.825rem;
}

/* ==========================================================================
   CIRCUIT SCHEMATIC DIAGRAM (SVG PIPELINES)
   ========================================================================== */
.circuit-schematic-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: var(--radius-xl);
  padding: 1.25rem 1.5rem;
  color: #f8fafc;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.circuit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.circuit-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.circuit-svg {
  width: 100%;
  height: 90px;
}

.pipe-bg {
  stroke: #334155;
  stroke-width: 6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pipe-flow {
  stroke: #38bdf8;
  stroke-width: 4;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  stroke-dasharray: 8 6;
  transition: opacity 0.3s;
}

.pump-active .pipe-flow {
  opacity: 1;
  animation: flow-dash 1s linear infinite;
}

@keyframes flow-dash {
  from { stroke-dashoffset: 28; }
  to { stroke-dashoffset: 0; }
}

/* ==========================================================================
   FOOTER & QUICK ACTIONS
   ========================================================================== */
.footer-bar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

@media (min-width: 640px) {
  .footer-bar {
    flex-direction: row;
  }
}

.quick-actions {
  display: flex;
  gap: 0.75rem;
}

.btn-secondary {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-secondary);
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: #ffffff;
  color: var(--text-primary);
  border-color: #cbd5e1;
}

/* Icons */
.icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-block;
  vertical-align: middle;
}
