/**
 * Estilos específicos para el Simulador de Plazos y Prórrogas del Alquiler (LAU)
 * Cumple con los estándares canónicos de Fijate Tools:
 * - Tipografías: Inter, Outfit y JetBrains Mono
 * - Modo claro y oscuro reactivo
 * - Línea temporal interactiva y cronograma visual
 * - Tarjetas de KPI y semáforos jurídicos
 * - Modal accesible sin window.alert()
 */

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

  /* Paleta cromática en modo claro */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Acentos de estado */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --primary-border: #bfdbfe;

  --success: #16a34a;
  --success-subtle: #f0fdf4;
  --success-border: #bbf7d0;

  --warning: #d97706;
  --warning-subtle: #fffbeb;
  --warning-border: #fde68a;

  --danger: #dc2626;
  --danger-subtle: #fef2f2;
  --danger-border: #fecaca;

  --radius-sm: 8px;
  --radius-md: 12px;
  --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.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

/* Modo oscuro */
body.dark,
[data-theme="dark"] {
  --bg-page: #090d16;
  --bg-card: #0f172a;
  --bg-card-subtle: #1e293b;
  --border-color: #334155;
  --border-focus: #60a5fa;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-light: #64748b;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-subtle: #172554;
  --primary-border: #1e40af;

  --success: #22c55e;
  --success-subtle: #052e16;
  --success-border: #166534;

  --warning: #f59e0b;
  --warning-subtle: #451a03;
  --warning-border: #92400e;

  --danger: #ef4444;
  --danger-subtle: #450a0a;
  --danger-border: #991b1b;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --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 y layout */
body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

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

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

@media (max-width: 768px) {
  .card-main {
    padding: 1.25rem;
  }
}

/* Hero de la herramienta */
.tool-hero {
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.5rem;
}

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

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  background: var(--primary-subtle);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.hero-title {
  font-family: var(--font-heading);
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0.5rem 0 0.75rem;
  color: var(--text-main);
}

.hero-lead {
  font-size: 1rem;
  color: var(--text-muted);
  margin: 0;
  max-width: 850px;
}

/* Barra de ejemplos rápidos / presets */
.preset-bar-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.preset-bar-label {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.preset-buttons-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn-sample-preset {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}

.btn-sample-preset:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-sample-preset.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Formulario interactivo */
.sim-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

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

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

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

.form-input,
.form-select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.65rem 0.85rem;
  font-family: var(--font-main);
  font-size: 0.9375rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-main);
  min-height: 44px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-select {
  cursor: pointer;
  appearance: none;
  -webkit-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='%2364748b' 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;
  padding-right: 40px;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Radio buttons de rol (Soy inquilino / Soy propietario) */
.role-switch-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.role-radio-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
  min-height: 44px;
  box-sizing: border-box;
}

.role-radio-label:hover {
  border-color: var(--primary);
}

.role-radio-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 600;
}

.role-radio-input {
  accent-color: var(--primary);
  width: 18px;
  height: 18px;
  margin: 0;
}

/* Checkboxes especiales (Ley de Vivienda) */
.extra-options-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.extra-options-title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.checkbox-option-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
}

.checkbox-input {
  accent-color: var(--primary);
  width: 18px;
  height: 18px;
  margin-top: 2px;
  cursor: pointer;
}

.checkbox-label-text {
  font-size: 0.875rem;
  color: var(--text-main);
  line-height: 1.4;
}

.checkbox-sub-desc {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* SECCIÓN DE RESULTADOS */
.results-wrapper {
  margin-top: 2.5rem;
  border-top: 2px dashed var(--border-color);
  padding-top: 2rem;
}

/* Tarjeta de estado y semáforo principal */
.status-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  margin-bottom: 2rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.5rem;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

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

.status-hero-left {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  font-size: 0.8125rem;
  font-weight: 700;
  border-radius: 9999px;
  width: fit-content;
}

.status-safe {
  background: var(--success-subtle);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.status-warning {
  background: var(--warning-subtle);
  color: var(--warning);
  border: 1px solid var(--warning-border);
}

.status-urgent,
.status-expired {
  background: var(--danger-subtle);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.status-finished {
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.status-hero-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
}

.status-hero-lead {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Contador numérico de días */
.countdown-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1.75rem;
  border-radius: var(--radius-md);
  text-align: center;
  min-width: 170px;
  box-sizing: border-box;
}

.countdown-safe {
  background: var(--success-subtle);
  border: 1px solid var(--success-border);
}

.countdown-warning {
  background: var(--warning-subtle);
  border: 1px solid var(--warning-border);
}

.countdown-urgent,
.countdown-expired {
  background: var(--danger-subtle);
  border: 1px solid var(--danger-border);
}

.countdown-finished {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
}

.countdown-number {
  font-family: var(--font-mono);
  font-size: 2.25rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text-main);
}

.countdown-safe .countdown-number { color: var(--success); }
.countdown-warning .countdown-number { color: var(--warning); }
.countdown-urgent .countdown-number,
.countdown-expired .countdown-number { color: var(--danger); }

.countdown-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.35rem;
  color: var(--text-main);
}

.countdown-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* KPIs principales */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

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

.kpi-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Barra de acciones (Descargar ICS, Burofax, Google Calendar) */
.actions-bar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 2.5rem;
}

.btn-primary,
.btn-secondary,
.btn-success {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
  text-decoration: none;
  box-sizing: border-box;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border: 1px solid var(--primary);
}

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

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

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

.btn-success {
  background: var(--success);
  color: #ffffff;
  border: 1px solid var(--success);
}

.btn-success:hover {
  filter: brightness(0.9);
}

/* Cronograma visual */
.timeline-section-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  margin-bottom: 2.5rem;
}

.section-subheading {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--text-main);
}

.section-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0 0 1.5rem;
}

.timeline-track {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-left: 2rem;
}

.timeline-track::before {
  content: '';
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 9px;
  width: 2px;
  background: var(--border-color);
}

.timeline-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.timeline-marker {
  position: absolute;
  left: -2rem;
  top: 4px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border-color);
  border: 2px solid var(--bg-card);
  z-index: 2;
  transition: all 0.2s ease;
}

.timeline-item.is-current-year .marker-dot {
  background: var(--primary);
  width: 14px;
  height: 14px;
}

.timeline-item.timeline-mandatory_end .marker-dot {
  background: var(--warning);
}

.timeline-item.timeline-tacit_step .marker-dot {
  background: #8b5cf6;
}

.current-pulse-ring {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.25);
  animation: pulse-ring 2s infinite ease-out;
  z-index: 1;
}

@keyframes pulse-ring {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

.timeline-content {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.15rem;
  transition: border-color 0.15s ease;
}

.timeline-item.is-current-year .timeline-content {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.timeline-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.timeline-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.current-label-pill {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: var(--primary);
  color: #ffffff;
}

.timeline-date {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: auto;
}

.timeline-item-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-main);
}

.timeline-item-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0;
  line-height: 1.45;
}

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

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

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

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

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

.row-current-year {
  background: var(--primary-subtle);
}

.badge-table-current {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--primary);
  color: #ffffff;
  margin-left: 0.25rem;
}

.text-nowrap {
  white-space: nowrap;
}

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

/* Guía legal y FAQ */
.legal-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem;
  margin-bottom: 2.5rem;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.guide-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
}

.guide-card-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--text-main);
}

.guide-card-p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Modales accesibles */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

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

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

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

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

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--bg-card-subtle);
}

.draft-textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  padding: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-main);
  resize: vertical;
}

.legal-notice-box {
  background: var(--primary-subtle);
  border: 1px solid var(--primary-border);
  color: var(--primary);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  line-height: 1.4;
}

/* Impresión */
@media print {
  .app-header,
  .fijate-footer,
  .tools-ad-banner-section,
  .tool-ad-sidebar,
  .preset-bar-box,
  .actions-bar-row,
  .sim-form-grid,
  .btn-sample-preset {
    display: none !important;
  }
  .card-main {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
}
