/* ==========================================================================
   Calculadora de TAE y TIN - Hoja de estilos canónica
   Fijate Tools (fijate.com) • Estándares canónicos
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Variables de diseño y temas (Oscuro / Claro)
   -------------------------------------------------------------------------- */
:root {
  /* Modo oscuro por defecto */
  --bg-page: #0b0f19;
  --bg-card: rgba(17, 24, 39, 0.88);
  --bg-card-hover: rgba(24, 33, 54, 0.96);
  --bg-card-inner: rgba(15, 23, 42, 0.6);
  --bg-input: rgba(15, 23, 42, 0.85);
  --bg-pill: rgba(30, 41, 59, 0.7);
  --bg-pill-hover: rgba(51, 65, 85, 0.9);
  --bg-pill-active: #2563eb;
  
  --border-color: rgba(255, 255, 255, 0.09);
  --border-focus: #3b82f6;
  --border-subtle: rgba(255, 255, 255, 0.05);

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-emerald: #10b981;
  --accent-emerald-dark: #059669;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;

  --badge-bg-primary: rgba(59, 130, 246, 0.15);
  --badge-text-primary: #93c5fd;
  --badge-border-primary: rgba(59, 130, 246, 0.3);

  --badge-bg-success: rgba(16, 185, 129, 0.15);
  --badge-text-success: #6ee7b7;
  --badge-border-success: rgba(16, 185, 129, 0.3);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.55);

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

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

  --select-arrow: 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");
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-card-inner: #f8fafc;
  --bg-input: #ffffff;
  --bg-pill: #e2e8f0;
  --bg-pill-hover: #cbd5e1;
  --bg-pill-active: #2563eb;

  --border-color: #e2e8f0;
  --border-focus: #2563eb;
  --border-subtle: #f1f5f9;

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  --accent-blue: #2563eb;
  --accent-blue-hover: #1d4ed8;
  --accent-emerald: #059669;
  --accent-emerald-dark: #047857;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --accent-purple: #7c3aed;

  --badge-bg-primary: rgba(37, 99, 235, 0.1);
  --badge-text-primary: #1d4ed8;
  --badge-border-primary: rgba(37, 99, 235, 0.25);

  --badge-bg-success: rgba(5, 150, 105, 0.1);
  --badge-text-success: #047857;
  --badge-border-success: rgba(5, 150, 105, 0.25);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.12);

  --select-arrow: 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='%23475569' 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");
}

/* --------------------------------------------------------------------------
   2. Reset y contención general
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.55;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

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

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

.font-bold {
  font-weight: 700;
}

.text-muted {
  color: var(--text-muted);
}

.text-primary {
  color: var(--accent-blue);
}

.text-success {
  color: var(--accent-emerald);
}

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

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

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

/* --------------------------------------------------------------------------
   4. Tarjeta introductoria y héroe de la herramienta
   -------------------------------------------------------------------------- */
.tool-intro-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}

.tool-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--badge-bg-primary);
  color: var(--badge-text-primary);
  border: 1px solid var(--badge-border-primary);
}

.tool-intro-card h2 {
  font-size: clamp(1.4rem, 2.5vw, 1.85rem);
  margin-bottom: 0.5rem;
}

.tool-intro-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 900px;
}

/* --------------------------------------------------------------------------
   5. Presets de acceso rápido
   -------------------------------------------------------------------------- */
.quick-presets-section {
  margin-bottom: 1.25rem;
}

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

.quick-presets-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn-preset {
  background: var(--bg-pill);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-preset:hover {
  background: var(--bg-pill-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   6. Pestañas de navegación
   -------------------------------------------------------------------------- */
.tool-tabs-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.4rem;
}

.tool-tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 0.65rem 1.1rem;
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 42px;
}

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

.tool-tab-btn.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
  background: var(--badge-bg-primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* --------------------------------------------------------------------------
   7. Tarjetas y paneles de cálculo
   -------------------------------------------------------------------------- */
.calc-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}

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

.calc-card-header h3 {
  font-size: 1.25rem;
}

.calc-card-header p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 0.2rem;
}

/* --------------------------------------------------------------------------
   8. Formularios, inputs y selects accesibles
   -------------------------------------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

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

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

.form-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.input-with-suffix {
  display: flex;
  align-items: stretch;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-with-suffix:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.input-with-suffix input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  padding: 0 0.85rem;
  height: 44px;
  outline: none;
}

.input-suffix {
  background: var(--bg-card-inner);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 0.85rem;
  display: flex;
  align-items: center;
  border-left: 1px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
}

/* Desplegables accesibles con truncamiento y contraste garantizado */
select.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 40px 0 0.85rem;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

select.form-select option,
select.form-select optgroup {
  background-color: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 0.5rem;
}

/* Botones de acción */
.btn-primary {
  background: var(--accent-blue);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.7rem 1.4rem;
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-blue-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
  background: var(--bg-pill);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.7rem 1.2rem;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
}

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

/* --------------------------------------------------------------------------
   9. Tarjetas métricas KPI
   -------------------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card-inner);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.kpi-card:hover {
  border-color: var(--border-focus);
  transform: translateY(-2px);
}

.kpi-card-highlight {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(16, 185, 129, 0.08));
  border-color: rgba(59, 130, 246, 0.3);
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: clamp(1.4rem, 2.5vw, 1.8rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.15;
}

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

/* --------------------------------------------------------------------------
   10. Canvas de gráficos interactivos
   -------------------------------------------------------------------------- */
.chart-container {
  background: var(--bg-card-inner);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.chart-header h4 {
  font-size: 0.95rem;
}

canvas.interactive-canvas {
  width: 100%;
  height: 280px;
  display: block;
}

/* --------------------------------------------------------------------------
   11. Tablas de datos comparativas
   -------------------------------------------------------------------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  background: var(--bg-card-inner);
}

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

table.data-table th {
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

table.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  white-space: nowrap;
}

table.data-table tr:hover {
  background: var(--bg-pill);
}

table.data-table tr.row-selected {
  background: var(--badge-bg-primary);
  border-left: 3px solid var(--accent-blue);
}

.badge-active {
  display: inline-block;
  background: var(--accent-blue);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  margin-left: 0.4rem;
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   12. Bloques de código Excel
   -------------------------------------------------------------------------- */
.excel-box {
  background: var(--bg-card-inner);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.excel-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.excel-box-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
}

.excel-code-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  gap: 0.75rem;
}

.excel-code {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--accent-emerald);
  flex: 1 1 0%;
  word-break: break-all;
}

.btn-copy {
  background: var(--bg-pill);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-copy:hover {
  background: var(--accent-blue);
  color: #ffffff;
  border-color: var(--accent-blue);
}

.excel-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  line-height: 1.45;
}

/* --------------------------------------------------------------------------
   13. Desglose fiscal IRPF
   -------------------------------------------------------------------------- */
.tax-breakdown-box {
  background: var(--bg-card-inner);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.tax-breakdown-box h4 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

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

li.tax-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

li.tax-item-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.5rem 0;
}

/* --------------------------------------------------------------------------
   14. Historial de cálculos en LocalStorage
   -------------------------------------------------------------------------- */
.history-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: border-color 0.15s ease;
}

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

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

.history-tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.tag-conversion { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.tag-deposit { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.tag-loan { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.tag-excel { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }

.history-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.history-details {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.history-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
}

.btn-history-restore {
  background: var(--badge-bg-primary);
  color: var(--badge-text-primary);
  border: 1px solid var(--badge-border-primary);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-history-delete {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.3rem;
}

.btn-history-delete:hover {
  color: var(--accent-rose);
}

.history-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  background: var(--bg-card-inner);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   15. Guía didáctica y normativa Banco de España
   -------------------------------------------------------------------------- */
.educational-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem 1.75rem;
  margin-top: 2rem;
  box-shadow: var(--shadow-sm);
}

.educational-guide-section h2 {
  font-size: 1.45rem;
  margin-bottom: 1.25rem;
}

.educational-guide-section h3 {
  font-size: 1.15rem;
  margin: 1.5rem 0 0.6rem;
  color: var(--accent-blue);
}

.educational-guide-section p {
  color: var(--text-secondary);
  font-size: 0.93rem;
  margin-bottom: 0.85rem;
  line-height: 1.6;
}

.educational-guide-section ul {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.educational-guide-section li {
  margin-bottom: 0.4rem;
}

.formula-highlight-box {
  background: var(--bg-card-inner);
  border-left: 4px solid var(--accent-blue);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   16. Modales nativos (sin window.alert)
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalPop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

.modal-header h3 {
  font-size: 1.15rem;
}

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

.btn-close-modal:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* --------------------------------------------------------------------------
   17. Notificación Toast flotante
   -------------------------------------------------------------------------- */
.toast-notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #3b82f6;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 500;
  z-index: 10000;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-notification.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* --------------------------------------------------------------------------
   18. Responsividad móvil
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .tool-layout {
    padding: 0 0.75rem;
    margin-top: 1rem;
  }

  .calc-card,
  .tool-intro-card,
  .educational-guide-section {
    padding: 1.25rem 1rem;
  }

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

  .tool-tab-btn {
    flex: 1 1 calc(50% - 0.4rem);
    justify-content: center;
    font-size: 0.88rem;
    padding: 0.6rem 0.5rem;
  }

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

  .excel-code-wrapper {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-copy {
    width: 100%;
    text-align: center;
  }
}

/* --------------------------------------------------------------------------
   19. Reglas de impresión (@media print)
   -------------------------------------------------------------------------- */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-header,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .fijate-footer,
  .quick-presets-section,
  .tool-tabs-container,
  .btn-preset,
  .btn-primary,
  .btn-secondary,
  .btn-copy,
  .history-actions,
  .toast-notification,
  .modal-backdrop {
    display: none !important;
  }

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

  .calc-card,
  .educational-guide-section {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  .tab-panel {
    display: block !important;
    margin-bottom: 2rem;
  }
}
