/* ==========================================================================
   Calculadora de Pladur y Falsos Techos - 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 */
  --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-pladur: #0284c7;
  --color-metal: #94a3b8;
  --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%;
}

.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;
}

/* Selector visual de sistema constructivo */
.system-selector-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.system-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.system-card:hover {
  border-color: var(--border-focus);
  background: var(--bg-card-hover);
}

.system-card.active {
  border-color: var(--color-primary);
  background: rgba(2, 132, 199, 0.08);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.system-icon-wrap {
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-primary);
  transition: all 0.2s;
}

.system-card.active .system-icon-wrap {
  background: var(--color-primary);
  color: #ffffff;
}

.system-texts {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.system-title {
  font-family: var(--font-title);
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.system-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* 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;
}

/* Formulario */
.pladur-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.15rem;
  margin-bottom: 1.75rem;
}

.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;
}

/* Resumen métrico principal */
.pladur-summary-banner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.75rem;
}

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

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

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

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

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

.sum-tile.highlight .sum-val {
  color: #38bdf8;
}

.sum-tile.primary .sum-val {
  color: #fbbf24;
}

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

/* Despiece de la lista de la compra */
.materials-shopping-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.75rem;
}

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

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

.shopping-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-sm);
}

.materials-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.25rem;
}

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

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

.materials-table th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
}

.materials-table td {
  color: var(--text-secondary);
}

.materials-table td:first-child {
  font-weight: 600;
  color: var(--text-primary);
}

.materials-table td:nth-child(3),
.materials-table td:nth-child(4) {
  font-family: var(--font-mono);
  font-weight: 600;
}

.materials-table td:nth-child(4) {
  color: #38bdf8;
}

.action-bar-pladur {
  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);
}

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

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

.installer-steps {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.installer-steps li {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.installer-steps strong {
  color: var(--text-primary);
}

/* 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) {
  .system-selector-grid {
    grid-template-columns: 1fr;
  }

  .pladur-summary-banner {
    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);
  }

  .pladur-form-grid {
    grid-template-columns: 1fr;
  }

  .pladur-summary-banner {
    grid-template-columns: 1fr;
  }
}
