/**
 * Calculadora de deducción por alquiler en el IRPF por comunidad autónoma
 * Estilos canónicos - Fijate Tools
 */

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

  /* Tema oscuro por defecto (Midnight Slate) */
  --bg-body: #0b0f17;
  --bg-card: #111827;
  --bg-card-sub: #162032;
  --bg-input: #0f172a;
  --border-color: #243046;
  --border-focus: #10b981;
  --text-main: #f3f4f6;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --accent-emerald: #10b981;
  --accent-emerald-light: rgba(16, 185, 129, 0.15);
  --accent-blue: #38bdf8;
  --accent-blue-light: rgba(56, 189, 248, 0.15);
  --accent-amber: #f59e0b;
  --accent-amber-light: rgba(245, 158, 11, 0.15);
  --accent-rose: #f43f5e;
  --accent-rose-light: rgba(244, 63, 94, 0.15);

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px 0 rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.45);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
}

[data-theme="light"],
body.light-theme {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-sub: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-focus: #059669;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;

  --accent-emerald: #059669;
  --accent-emerald-light: rgba(5, 150, 105, 0.12);
  --accent-blue: #0284c7;
  --accent-blue-light: rgba(2, 132, 199, 0.12);
  --accent-amber: #d97706;
  --accent-amber-light: rgba(217, 119, 6, 0.12);
  --accent-rose: #e11d48;
  --accent-rose-light: rgba(225, 29, 72, 0.12);

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px 0 rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.12);
}

/* Reset y base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  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,
.hero-title {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}

.mono,
.stat-val,
.stat-price-val,
.casilla-badge,
code {
  font-family: var(--font-mono);
}

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

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

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

/* Cabecera de la herramienta (Hero introductorio) */
.tool-intro {
  margin-bottom: 1.5rem;
}

.tool-intro-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.tool-intro-desc {
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 820px;
}

/* Workspace en 2 columnas */
.workspace-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 1024px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

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

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

.panel-title {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-title svg {
  color: var(--accent-emerald);
}

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

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.label-hint {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-left: 0.35rem;
}

/* Inputs y Selects */
input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-height: 42px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 0.5rem 0.85rem;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-emerald-light);
}

/* Select canónico con SVG y ellipsis */
select {
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  padding-right: 40px;
  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%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  cursor: pointer;
}

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

/* Input wrappers con sufijo */
.input-addon-group {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.input-addon-group input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.input-addon {
  display: flex;
  align-items: center;
  padding: 0 0.85rem;
  background-color: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Switches y Casillas de Verificación */
.switches-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.switch-label {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  background-color: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.switch-label:hover {
  border-color: var(--text-subtle);
}

.switch-label input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  border: 2px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-input);
  cursor: pointer;
  display: grid;
  place-content: center;
  margin-top: 2px;
  transition: all 0.15s ease;
}

.switch-label input[type="checkbox"]:checked {
  background-color: var(--accent-emerald);
  border-color: var(--accent-emerald);
}

.switch-label input[type="checkbox"]:checked::before {
  content: "";
  width: 10px;
  height: 6px;
  border-left: 2px solid #ffffff;
  border-bottom: 2px solid #ffffff;
  transform: rotate(-45deg) translate(1px, -1px);
}

.switch-content {
  display: flex;
  flex-direction: column;
}

.switch-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.switch-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Columna de Resultados */
.result-hero {
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.result-hero.status-success {
  border-color: rgba(16, 185, 129, 0.4);
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(16, 185, 129, 0.05) 100%);
}

.result-hero.status-danger {
  border-color: rgba(244, 63, 94, 0.3);
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(244, 63, 94, 0.04) 100%);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}

.badge-success {
  background-color: var(--accent-emerald-light);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-danger {
  background-color: var(--accent-rose-light);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

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

.result-hero.status-success .result-hero-amount {
  color: var(--accent-emerald);
}

.result-hero-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.result-hero-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Métricas secundarias */
.stats-subgrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.stat-item {
  background-color: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.3rem;
}

.stat-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Ficha oficial de Casillas Renta Web */
.renta-casillas-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.renta-casillas-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.casilla-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background-color: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  gap: 0.75rem;
}

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

.casilla-name {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.casilla-badge {
  background-color: var(--accent-blue-light);
  color: var(--accent-blue);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* Advertencias y Fianza */
.advisory-box {
  background-color: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-md);
  padding: 1rem;
  color: var(--text-main);
}

.advisory-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--accent-amber);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.advisory-list {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Botones de acción */
.action-buttons-group {
  display: flex;
  gap: 0.75rem;
}

.btn-primary,
.btn-secondary {
  flex: 1 1 0%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  font-family: inherit;
  padding: 0.5rem 1rem;
}

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

.btn-primary:hover {
  background-color: #059669;
}

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

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

.btn-success-state {
  background-color: var(--accent-emerald) !important;
  color: #ffffff !important;
  border-color: var(--accent-emerald) !important;
}

/* Guía de comprobación y Checklist */
.guide-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.checklist-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

@media (max-width: 768px) {
  .checklist-grid {
    grid-template-columns: 1fr;
  }
}

.checklist-item {
  background-color: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  gap: 0.75rem;
}

.checklist-icon {
  color: var(--accent-emerald);
  min-width: 20px;
}

.checklist-text h5 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.checklist-text p {
  font-size: 0.775rem;
  color: var(--text-muted);
}

/* Tabla comparativa de CCAA */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

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

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

.ccaa-summary-table th {
  background-color: var(--bg-card-sub);
  font-weight: 700;
  color: var(--text-main);
}

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

.ccaa-summary-table tr:hover td {
  background-color: var(--accent-blue-light);
}

/* Sección FAQ */
.faq-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.faq-title {
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 1rem;
}

.faq-grid {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

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

.faq-question {
  width: 100%;
  padding: 1rem;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-family: inherit;
}

.faq-answer {
  padding: 0 1rem 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Modales canónicos */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: none;
  place-items: center;
  padding: 1rem;
}

.modal-overlay.is-active {
  display: grid;
}

.modal-container {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.modal-close-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-card-sub);
}

/* Vista Imprimible Oficial A4 (.print-sheet) */
.print-sheet {
  display: none;
}

@media print {
  /* Ocultar interfaz web interactiva */
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-header,
  .fijate-footer,
  .tools-ad-banner-section,
  .tool-ad-sidebar,
  .workspace-grid,
  .guide-section,
  .faq-section,
  .action-buttons-group,
  .tool-intro {
    display: none !important;
  }

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

  /* Mostrar hoja oficial A4 */
  .print-sheet {
    display: block !important;
    width: 100%;
    max-width: 210mm;
    margin: 0 auto;
    padding: 15mm 20mm;
    font-size: 11pt;
    font-family: var(--font-main);
    color: #111827;
  }

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

  .print-header h1 {
    font-size: 18pt;
    font-weight: 800;
  }

  .print-header p {
    font-size: 9pt;
    color: #4b5563;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #d1d5db;
    padding: 8px 12px;
    text-align: left;
    font-size: 10pt;
  }

  .print-table th {
    background-color: #f3f4f6;
    font-weight: 700;
  }

  .print-total-row {
    font-size: 12pt !important;
    font-weight: 800;
    background-color: #ecfdf5 !important;
  }

  .print-legal-notice {
    font-size: 8pt;
    color: #6b7280;
    line-height: 1.4;
    margin-top: 30px;
    border-top: 1px solid #e5e7eb;
    padding-top: 10px;
  }
}
