/* ==========================================================================
   Simulador del Impuesto sobre Sucesiones y Donaciones (ISD)
   Estándares canónicos fijate.com - Modo oscuro/claro y diseño responsive
   ========================================================================== */

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

  /* Tema oscuro por defecto */
  --bg-main: #0c111d;
  --bg-card: #151d2e;
  --bg-card-hover: #1c263c;
  --bg-input: #0e1626;
  --bg-subtle: #1f2a40;
  
  --border-color: #24324c;
  --border-focus: #3b82f6;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.12);

  --accent-gold: #f59e0b;
  --accent-green: #10b981;
  --accent-red: #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f8fafc;
  --bg-subtle: #e2e8f0;

  --border-color: #cbd5e1;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.08);

  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.06);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text-main);
}

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

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

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

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ==========================================================================
   Header Hero y tarjeta introductoria
   ========================================================================== */
.tool-intro-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.tool-intro-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.tool-intro-title {
  font-size: 1.6rem;
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.tool-intro-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ==========================================================================
   Contenedor Grid de 2 Columnas (Formulario + HUD de Resultados)
   ========================================================================== */
.isd-grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 900px) {
  .isd-grid-container {
    grid-template-columns: 1fr;
  }
}

.card-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

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

.card-box-title {
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Formularios y controles móviles al 100 % */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
}

.form-label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.form-control,
.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  padding: 0.5rem 0.875rem;
  font-size: 0.95rem;
  font-family: var(--font-sans);
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-select {
  appearance: none;
  background-image: 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='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.form-select option,
.form-select optgroup {
  background-color: var(--bg-card);
  color: var(--text-main);
}

.input-with-affix {
  display: flex;
  align-items: center;
  position: relative;
}

.input-with-affix .form-control {
  padding-right: 45px;
  font-family: var(--font-mono);
}

.input-affix-unit {
  position: absolute;
  right: 14px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
}

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

.range-slider {
  width: 100%;
  accent-color: var(--primary);
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 4px;
  cursor: pointer;
}

/* ==========================================================================
   HUD de Resultado Principal
   ========================================================================== */
.hero-result-card {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(16, 185, 129, 0.08));
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
}

.hero-result-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.hero-result-amount {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  margin-bottom: 0.5rem;
}

.hero-result-amount.is-zero {
  color: var(--accent-green);
}

.hero-effective-rate {
  font-size: 0.95rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
}

.region-notice-box {
  background: var(--bg-subtle);
  border-left: 4px solid var(--primary);
  padding: 0.875rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Desglose de importes */
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.summary-table tr {
  border-bottom: 1px solid var(--border-color);
}

.summary-table tr:last-child {
  border-bottom: none;
}

.summary-table td {
  padding: 0.6rem 0;
}

.summary-table td:last-child {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
}

.bonus-highlight {
  color: var(--accent-green);
}

/* ==========================================================================
   Sección Comparativa Multirregional (Las 17 CCAA)
   ========================================================================== */
.comparison-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.diff-badge {
  display: inline-block;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.diff-badge-positive {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.diff-badge-notice {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-gold);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.comparison-list-container {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.ccaa-compare-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ccaa-compare-item:hover {
  border-color: var(--primary);
  background: var(--bg-card-hover);
}

.ccaa-compare-item.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
  background: var(--bg-card);
}

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

.ccaa-rank-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.ccaa-rank-badge {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-subtle);
  min-width: 24px;
}

.ccaa-current-pill {
  font-size: 0.7rem;
  background: var(--primary);
  color: #fff;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  font-weight: 600;
}

.ccaa-tax-figures {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.ccaa-tax-val {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
}

.ccaa-tax-val.is-free {
  color: var(--accent-green);
}

.ccaa-rate-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.ccaa-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.ccaa-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent-gold));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.ccaa-bar-fill.bar-zero {
  background: var(--accent-green);
}

.ccaa-tax-note {
  font-size: 0.75rem;
  color: var(--text-subtle);
  line-height: 1.3;
}

/* ==========================================================================
   Acciones y Botones
   ========================================================================== */
.card-actions-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn-primary,
.btn-secondary {
  height: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  border: none;
  width: 100%;
}

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

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

.btn-secondary {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-card-hover);
}

/* ==========================================================================
   Modales Canónicos (sin window.alert)
   ========================================================================== */
.custom-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.custom-modal.is-active {
  display: flex;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ==========================================================================
   Bloque de Impresión Oficial A4 (@media print conforme a Lección 238)
   ========================================================================== */
#print-sheet {
  display: none;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10.5pt;
  }

  .app-header,
  .fijate-footer,
  .tools-ad-banner-section,
  .tool-ad-sidebar,
  .tool-intro-card,
  .isd-grid-container,
  .comparison-section,
  .seo-guide-section,
  .card-actions-row,
  .custom-modal {
    display: none !important;
  }

  #print-sheet {
    display: block !important;
    padding: 2cm 1.5cm;
    max-width: 100%;
    margin: 0 auto;
  }

  .print-header {
    border-bottom: 2px solid #000;
    padding-bottom: 12px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
  }

  .print-title {
    font-size: 16pt;
    font-weight: bold;
  }

  .print-subtitle {
    font-size: 9.5pt;
    color: #555;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #ccc;
    padding: 6px 10px;
    font-size: 10pt;
  }

  .print-table th {
    background-color: #f2f2f2;
    text-align: left;
  }

  .print-total-box {
    margin-top: 25px;
    padding: 15px;
    border: 2px solid #000;
    background-color: #fafafa;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .print-legal-footer {
    margin-top: 40px;
    font-size: 8pt;
    color: #777;
    border-top: 1px solid #ccc;
    padding-top: 10px;
  }
}
