/* ============================================================
   COMPAT.CSS — Legacy Browser Support via @supports
   Fallbacks for browsers without modern CSS features
   ============================================================ */

/* ── Fallback: Sin backdrop-filter ─────────────────────────── */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .sidebar {
    background: rgba(10, 10, 30, 0.97);
  }
  .navbar {
    background: rgba(10, 10, 30, 0.97);
  }
  .card,
  .summary-card {
    background: rgba(15, 15, 42, 0.95);
  }
  .modal-overlay {
    background: rgba(0, 0, 0, 0.85);
  }
  .modal,
  .modal-card {
    background: rgba(15, 15, 42, 0.98);
  }
  .toast {
    background: rgba(15, 15, 42, 0.98);
  }
  .login-card {
    background: rgba(15, 15, 42, 0.95);
  }
}

/* ── Fallback: Sin CSS Custom Properties ───────────────────── */
@supports not (color: var(--test)) {
  body {
    background-color: #0a0a1a;
    color: #f1f5f9;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }
  .btn-primary {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #fff;
  }
  .btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: #f1f5f9;
    border: 1px solid rgba(255, 255, 255, 0.08);
  }
  .sidebar {
    background: rgba(10, 10, 30, 0.97);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }
  .navbar {
    background: rgba(10, 10, 30, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  .card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
  }
  .nav-link {
    color: #94a3b8;
  }
  .nav-link.active,
  .nav-link:hover {
    color: #f1f5f9;
  }
  a {
    color: #06b6d4;
  }
  .form-control,
  .form-control-login,
  .form-input,
  .form-select {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
    border-radius: 12px;
  }
  .text-secondary {
    color: #94a3b8;
  }
  .text-tertiary {
    color: #64748b;
  }
}

/* ── Fallback: Sin display: grid ───────────────────────────── */
@supports not (display: grid) {
  .summary-grid,
  .dashboard-grid,
  .budget-grid,
  .loans-grid,
  .budget-status-grid,
  .subs-grid,
  .settings-grid,
  .filters-grid,
  .auth-tabs,
  .form-row,
  .compact-form-row {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
  }
  .summary-grid > *,
  .budget-grid > * {
    -webkit-box-flex: 1;
    -ms-flex: 1 1 280px;
    flex: 1 1 280px;
    margin: 8px;
  }
  .dashboard-grid > * {
    -webkit-box-flex: 1;
    -ms-flex: 1 1 400px;
    flex: 1 1 400px;
    margin: 8px;
  }
  .auth-tabs > * {
    -webkit-box-flex: 1;
    -ms-flex: 1 1 auto;
    flex: 1 1 auto;
  }
  .form-row > *,
  .compact-form-row > * {
    -webkit-box-flex: 1;
    -ms-flex: 1 1 200px;
    flex: 1 1 200px;
    margin: 4px;
  }
}

/* ── Fallback: Sin position: sticky ────────────────────────── */
@supports not (position: sticky) {
  .navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
  }
  .main-content {
    padding-top: 88px; /* navbar-height + space */
  }
}

/* ── Fallback: Sin clamp() ─────────────────────────────────── */
@supports not (font-size: clamp(1rem, 2vw, 2rem)) {
  .summary-card-amount {
    font-size: 1.5rem;
  }
  .navbar-title {
    font-size: 1.1rem;
  }
}

/* ── Fallback: Sin inset shorthand ─────────────────────────── */
@supports not (inset: 0) {
  .sidebar-overlay,
  .modal-overlay {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
  body::before {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
}

/* ── Fallback: Sin gap en flexbox ──────────────────────────── */
@supports not (gap: 1px) {
  .navbar-left > * + *,
  .navbar-right > * + * {
    margin-left: 16px;
  }
  .sidebar-brand > * + * {
    margin-left: 16px;
  }
  .nav-link > * + * {
    margin-left: 16px;
  }
}

/* ── Accesibilidad: prefers-reduced-motion ─────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .progress-bar-fill::after {
    animation: none !important;
  }
  .summary-card {
    animation: none !important;
  }
  .login-logo {
    animation: none !important;
  }
  .login-card::before {
    animation: none !important;
  }
  .empty-state-icon {
    animation: none !important;
  }
}

/* ── Accesibilidad: prefers-contrast ───────────────────────── */
@media (prefers-contrast: high) {
  :root {
    --border: rgba(255, 255, 255, 0.25);
    --border-hover: rgba(255, 255, 255, 0.4);
    --text-secondary: #b8c5d6;
    --text-tertiary: #8899aa;
  }
  .card {
    border-width: 2px;
  }
  .btn {
    border: 2px solid currentColor;
  }
  .badge {
    border-width: 2px;
  }
}

/* ── Fallback: Sin color-scheme ────────────────────────────── */
@supports not (color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
  input,
  select,
  textarea {
    color-scheme: dark;
  }
}

/* ── Fallback: Sin aspect-ratio (for charts) ───────────────── */
@supports not (aspect-ratio: 1) {
  .chart-container {
    min-height: 280px;
    height: auto;
  }
}

/* ── Print styles ──────────────────────────────────────────── */
@media print {
  .sidebar,
  .navbar,
  .voice-fab,
  .voice-panel,
  .toast-container,
  .modal-overlay,
  .sidebar-overlay {
    display: none !important;
  }
  .main-wrapper {
    margin-left: 0 !important;
  }
  .card {
    break-inside: avoid;
    border: 1px solid #ccc;
    background: #fff;
    color: #000;
  }
  body {
    background: #fff;
    color: #000;
  }
}
