/* ==========================================================================
   Calculadora de Fontanería, Calefacción y ACS - Estilos Oficiales
   Estándar Canónico de Fijate Tools
   ========================================================================== */

:root {
  --font-base: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-title: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Modo oscuro por defecto */
  --bg-app: #0d1117;
  --bg-card: #161b22;
  --bg-card-hover: #1c2128;
  --bg-input: #0e1217;
  --bg-subtle: #21262d;
  
  --border-color: #30363d;
  --border-focus: #388bfd;
  
  --text-primary: #f0f6fc;
  --text-secondary: #c9d1d9;
  --text-muted: #8b949e;
  
  --color-primary: #0284c7;
  --color-primary-hover: #0369a1;
  --color-primary-glow: rgba(2, 132, 199, 0.25);
  
  --color-copper: #d97706;
  --color-multicapa: #0284c7;
  --color-pex: #10b981;
  --color-accent: #f59e0b;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-input: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg-app: #f4f6f8;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #ffffff;
  --bg-subtle: #e2e8f0;
  
  --border-color: #cbd5e1;
  --border-focus: #0284c7;
  
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  
  --color-primary: #0284c7;
  --color-primary-hover: #0369a1;
  --color-primary-glow: rgba(2, 132, 199, 0.15);
  
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-input: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: var(--font-base);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Layout principal */
.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  flex: 1;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Sidebar de publicidad en desktop grande */
.tool-ad-sidebar {
  display: none;
  width: 300px;
  flex-shrink: 0;
}

@media (min-width: 1536px) {
  .tool-ad-sidebar {
    display: block;
  }
}

.ad-sticky-box {
  position: sticky;
  top: 80px;
}

/* Navegación por pestañas */
.tool-nav-tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-card);
  padding: 0.4rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.75rem 1.25rem;
  min-height: 42px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex: 1;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-subtle);
}

.tab-btn.active {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--color-primary-glow);
}

.tab-btn svg {
  flex-shrink: 0;
}

/* Paneles de contenido */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeInTab 0.25s ease-out;
}

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

/* Tarjeta principal */
.card-main {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
}

.section-header {
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.section-header h2 {
  font-family: var(--font-title);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.section-header .subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Cuadrícula de aparatos de fontanería */
.fixtures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.fixture-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: border-color 0.2s;
}

.fixture-item:hover {
  border-color: var(--border-focus);
}

.fixture-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.fixture-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fixture-flow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Control de pasos +/- */
.counter-control {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.btn-step {
  width: 36px;
  height: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: bold;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.count-value {
  display: inline-block;
  min-width: 28px;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
}

/* Formularios y campos */
.form-row-2col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

.form-select,
.form-input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 42px;
  min-height: 42px;
  padding: 0 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-base);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

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

.input-field-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  height: 42px;
  min-height: 42px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-field-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

.input-field-wrap .form-input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  border: none;
  background: transparent;
  height: 100%;
  box-shadow: none;
}

.unit-suffix {
  padding: 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  background: var(--bg-subtle);
  height: 100%;
  display: flex;
  align-items: center;
  border-left: 1px solid var(--border-color);
  white-space: nowrap;
}

/* Banner de resultados */
.results-banner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.75rem;
}

.result-tile {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.result-tile.highlight {
  border-color: var(--color-accent);
  background: rgba(245, 158, 11, 0.06);
}

.result-tile.primary {
  border-color: var(--color-primary);
  background: rgba(2, 132, 199, 0.08);
}

.result-tile-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  text-transform: none;
}

.result-tile-val {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.result-tile.primary .result-tile-val {
  color: #38bdf8;
}

.result-tile.highlight .result-tile-val {
  color: #fbbf24;
}

.result-tile-sub {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

/* Tarjeta de recomendación de tuberías */
.recommendation-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.recommendation-card h3 {
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: var(--text-primary);
}

.rec-intro {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.pipe-materials-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.pipe-material-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  position: relative;
  overflow: hidden;
}

.material-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  text-transform: none;
}

.badge-copper {
  background: rgba(217, 119, 6, 0.18);
  color: #f59e0b;
  border: 1px solid rgba(217, 119, 6, 0.35);
}

.badge-multicapa {
  background: rgba(2, 132, 199, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(2, 132, 199, 0.35);
}

.badge-pex {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.pipe-dim-main {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-top: 0.2rem;
}

.pipe-dim-detail {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.pipe-dim-detail span {
  font-family: var(--font-mono);
  font-weight: 600;
}

.pipe-dim-status {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #34d399;
  margin-top: 0.2rem;
}

/* Guía de ramales */
.branch-guide-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem;
}

.branch-guide-box h4 {
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-subtle);
}

.data-table td {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.data-table td:first-child {
  font-family: var(--font-base);
  font-weight: 500;
  color: var(--text-primary);
}

/* Módulo ACS */
.form-grid-acs,
.form-grid-heating {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.acs-results-card,
.heat-results-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.acs-recom-box,
.heat-elements-box {
  text-align: center;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
}

.acs-badge,
.heat-badge {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-sm);
  background: rgba(2, 132, 199, 0.15);
  color: #38bdf8;
  margin-bottom: 0.5rem;
}

.heat-badge {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.acs-vol-highlight,
.heat-el-highlight {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: 0.35rem;
}

.acs-model-note,
.heat-distrib-text {
  font-size: 0.92rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.acs-metrics-grid,
.heat-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}

.metric-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-sub {
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

/* Consejos prácticos */
.tips-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.tips-box h4 {
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--text-primary);
}

.tips-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tips-list li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  position: relative;
  padding-left: 1.25rem;
}

.tips-list li::before {
  content: "•";
  position: absolute;
  left: 0.35rem;
  color: var(--color-primary);
  font-weight: bold;
}

/* Botón de acción principal */
.action-bar {
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  min-height: 44px;
  padding: 0 1.5rem;
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-primary:active {
  transform: scale(0.99);
}

/* Modal personalizado */
.custom-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.custom-modal-overlay.active {
  display: flex;
  animation: fadeInModal 0.2s ease-out;
}

@keyframes fadeInModal {
  from { opacity: 0; }
  to { opacity: 1; }
}

.custom-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

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

.custom-modal-title {
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.btn-modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.custom-modal-body {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.5rem;
  white-space: pre-line;
}

.custom-modal-footer {
  display: flex;
  justify-content: flex-end;
}

.btn-modal-action {
  min-height: 40px;
  width: 100%;
  padding: 0 1.25rem;
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

/* ==========================================================================
   Adaptabilidad Móvil Estricta
   ========================================================================== */
@media (max-width: 900px) {
  .results-banner,
  .pipe-materials-grid,
  .acs-metrics-grid,
  .heat-metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .tool-layout {
    padding: 0 0.75rem;
    margin: 1rem auto 2rem;
  }

  .card-main {
    padding: 1.25rem 1rem;
    border-radius: var(--radius-lg);
  }

  .tool-nav-tabs {
    flex-wrap: nowrap;
  }

  .tab-btn {
    font-size: 0.85rem;
    padding: 0.6rem 0.9rem;
  }

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

  .form-row-2col,
  .form-grid-acs,
  .form-grid-heating {
    grid-template-columns: 1fr;
  }

  .results-banner,
  .pipe-materials-grid,
  .acs-metrics-grid,
  .heat-metrics-grid {
    grid-template-columns: 1fr;
  }

  .acs-vol-highlight,
  .heat-el-highlight {
    font-size: 2.2rem;
  }
}
