/**
 * Fijate Tools - Estilos para Estimador de materiales y coste de vallado rústico
 * Conforme a estándares canónicos y lecciones de contención móvil.
 */

:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta agronómica rústica y moderna */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-inverse: #ffffff;

  --border-color: #e2e8f0;
  --border-focus: #16a34a;

  --accent-green: #16a34a;
  --accent-green-hover: #15803d;
  --accent-green-bg: #dcfce7;
  --accent-green-text: #14532d;

  --accent-blue: #0284c7;
  --accent-blue-bg: #e0f2fe;
  --accent-blue-text: #0369a1;

  --accent-amber: #d97706;
  --accent-amber-bg: #fef3c7;
  --accent-amber-text: #92400e;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #131b26;
  --bg-card-subtle: #1a2434;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --border-color: #243247;
  --border-focus: #22c55e;

  --accent-green: #22c55e;
  --accent-green-hover: #16a34a;
  --accent-green-bg: rgba(34, 197, 94, 0.16);
  --accent-green-text: #86efac;

  --accent-blue: #38bdf8;
  --accent-blue-bg: rgba(56, 189, 248, 0.16);
  --accent-blue-text: #7dd3fc;

  --accent-amber: #fbbf24;
  --accent-amber-bg: rgba(251, 191, 36, 0.16);
  --accent-amber-text: #fde68a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Base */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title {
  font-family: var(--font-heading);
  letter-spacing: -0.015em;
  margin-top: 0;
}

.mono, code {
  font-family: var(--font-mono);
}

/* Barra suite agrícola */
.suite-nav-strip {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  width: 100%;
  box-sizing: border-box;
}

.suite-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.suite-nav-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  flex-shrink: 0;
}

.suite-links {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.suite-link-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  background: var(--bg-card-subtle);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.suite-link-item:hover {
  background: var(--border-color);
  color: var(--text-main);
}

.suite-link-item.active {
  background: var(--accent-green-bg);
  color: var(--accent-green-text);
  font-weight: 700;
}

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

.tool-with-sidebar {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

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

/* Barra de presets rápidos */
.presets-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.presets-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.presets-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.btn-preset {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-preset:hover {
  background: var(--accent-green-bg);
  color: var(--accent-green-text);
  border-color: var(--accent-green);
}

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

.split-tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr);
  gap: 1.75rem;
  align-items: start;
}

@media (max-width: 991px) {
  .split-tool-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Columna de configuración (Formulario) */
.form-config-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-section-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.form-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-color);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Inputs, selects y controles táctiles */
.input-with-unit {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.input-with-unit input[type="number"],
.input-with-unit input[type="text"] {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--border-color);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding: 0 0.75rem;
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.95rem;
}

.input-with-unit .input-unit-label {
  height: 42px;
  display: flex;
  align-items: center;
  padding: 0 0.85rem;
  background: var(--border-color);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.input-slider {
  width: 100%;
  accent-color: var(--accent-green);
  cursor: pointer;
  margin-top: 0.3rem;
}

/* Selects */
.select-custom {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 2.25rem 0 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.75rem center;
  background-size: 16px;
  color: var(--text-main);
  font-size: 0.88rem;
  font-family: inherit;
  appearance: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.select-custom:focus,
.input-with-unit input:focus {
  outline: 2px solid var(--border-focus);
  outline-offset: -1px;
}

/* Grid de campos 2 columnas */
.field-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

/* Checkbox estilizados */
.checkbox-card {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.checkbox-card:hover {
  border-color: var(--accent-green);
}

.checkbox-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-green);
  margin-top: 0.15rem;
  cursor: pointer;
}

.checkbox-card-info {
  display: flex;
  flex-direction: column;
}

.checkbox-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.checkbox-card-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Columna de visualización y resultados */
.results-preview-col {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Croquis técnico interactivo */
.croquis-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: var(--radius-md);
  padding: 0.85rem;
  overflow: hidden;
}

.croquis-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #1e293b;
}

.croquis-badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.15);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.croquis-svg-wrapper {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.croquis-svg {
  width: 100%;
  height: auto;
  display: block;
}

/* KPIs destacados */
.kpi-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.kpi-stat-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-stat-card.featured {
  background: var(--accent-green-bg);
  border-color: var(--accent-green);
}

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

.kpi-stat-card.featured .kpi-label {
  color: var(--accent-green-text);
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.kpi-stat-card.featured .kpi-value {
  color: var(--accent-green-text);
}

.kpi-subtext {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Tabla de despiece de materiales */
.table-despiece-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}

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

.tabla-despiece th {
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  font-weight: 700;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.tabla-despiece td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.fila-despiece:hover {
  background: var(--bg-card-subtle);
}

.col-concepto .concepto-title {
  font-weight: 600;
  color: var(--text-main);
}

.col-concepto .concepto-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.col-cant {
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
}

.col-unidad {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

.input-precio-wrap {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.input-precio-editable {
  width: 70px;
  height: 32px;
  padding: 0 0.35rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  color: var(--text-main);
  text-align: right;
  font-size: 0.85rem;
}

.input-precio-editable:focus {
  outline: 2px solid var(--border-focus);
}

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

.col-subtotal {
  text-align: right;
  white-space: nowrap;
}

/* Totales del presupuesto */
.resumen-totales-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.linea-total-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.linea-total-item.gran-total {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  padding-top: 0.5rem;
  border-top: 2px dashed var(--border-color);
}

/* Botones de acción */
.actions-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn-action-primary {
  flex: 1 1 0%;
  min-width: 180px;
  height: 44px;
  background: var(--accent-green);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action-primary:hover {
  background: var(--accent-green-hover);
}

.btn-action-secondary {
  flex: 1 1 0%;
  min-width: 180px;
  height: 44px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action-secondary:hover {
  background: var(--bg-card-subtle);
  border-color: var(--text-muted);
}

.btn-action-reset {
  height: 44px;
  padding: 0 1rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action-reset:hover {
  color: var(--text-main);
  background: var(--bg-card-subtle);
}

/* Artículos informativos y FAQ */
.info-section-wrapper {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

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

.guide-article h2 {
  font-size: 1.4rem;
  color: var(--text-main);
  margin-bottom: 1rem;
}

.guide-article h3 {
  font-size: 1.1rem;
  color: var(--text-main);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.guide-article p,
.guide-article li {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.guide-article ul,
.guide-article ol {
  padding-left: 1.25rem;
}

/* Cajas de llamada técnica */
.callout-box {
  background: var(--accent-blue-bg);
  border-left: 4px solid var(--accent-blue);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 0.85rem 1.15rem;
  margin: 1rem 0;
}

.callout-box p {
  color: var(--accent-blue-text);
  margin: 0;
  font-size: 0.88rem;
  font-weight: 500;
}

/* Acordeón FAQ */
.faq-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.faq-item {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.faq-question {
  padding: 0.9rem 1.15rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: '+';
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.faq-item[open] .faq-question::after {
  content: '−';
}

.faq-answer {
  padding: 0.25rem 1.15rem 1rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
}

/* Modal accesible canónico */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

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

.modal-body {
  padding: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  background: var(--bg-card-subtle);
}

.modal-btn-confirm {
  background: var(--accent-green);
  color: #fff;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}

/* =========================================================================
   AISLAMIENTO ESTRICTO PARA IMPRESIÓN Y EXPORTACIÓN A4 (@media print)
   Conforme a la Lección 296: Cero desbordamientos, ocultación de formularios
   y cabeceras, y página de presupuesto limpia y contrastada.
   ========================================================================= */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 15mm;
  }

  body {
    background: #ffffff !important;
    color: #0f172a !important;
    font-size: 10pt;
  }

  .app-header,
  .suite-nav-strip,
  .tools-ad-banner-section,
  .tool-ad-sidebar,
  .presets-banner,
  .form-config-panel,
  .actions-toolbar,
  .croquis-card,
  .guide-article,
  .faq-section,
  .fijate-footer,
  .modal-overlay,
  .btn-action-reset,
  .input-precio-wrap span,
  .moneda-sufijo {
    display: none !important;
  }

  .tool-layout {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  .split-tool-grid {
    display: block !important;
  }

  .results-preview-col {
    display: block !important;
    width: 100% !important;
  }

  .card-main {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .table-despiece-wrapper {
    border: 1px solid #cbd5e1 !important;
    box-shadow: none !important;
    margin-top: 15px;
  }

  .tabla-despiece th {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-bottom: 2px solid #94a3b8 !important;
  }

  .tabla-despiece td {
    border-bottom: 1px solid #e2e8f0 !important;
    color: #0f172a !important;
    padding: 6px 8px !important;
  }

  .input-precio-editable {
    border: none !important;
    background: transparent !important;
    color: #0f172a !important;
    font-weight: 700;
    text-align: right;
    width: auto !important;
  }

  .print-header-sheet {
    display: block !important;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 10px;
    margin-bottom: 15px;
  }

  .print-header-sheet h1 {
    font-size: 16pt;
    margin: 0 0 4px 0;
    color: #0f172a;
  }

  .print-header-sheet p {
    margin: 0;
    font-size: 9pt;
    color: #475569;
  }

  .resumen-totales-box {
    background: #f8fafc !important;
    border: 1px solid #cbd5e1 !important;
    margin-top: 15px;
    page-break-inside: avoid;
  }

  .kpi-metrics-grid {
    margin-bottom: 15px;
  }

  .kpi-stat-card {
    border: 1px solid #cbd5e1 !important;
    background: #f8fafc !important;
  }
}

/* Ocultar cabecera de impresión en pantalla */
.print-header-sheet {
  display: none;
}
