/* ==========================================================================
   Smart Personal Finance PWA - Epsilon 3 Visual System
   Design Tokens, Arctic Blue (Default) & Mint Themes, Dark/Light & System Modes
   WCAG AA Contrast Compliant
   ========================================================================== */

/* Offline-first font stack (no external Google Fonts CDN or CSP violations) */
:root {
    --font-fa: 'Vazirmatn', 'Tahoma', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --font-en: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --transition-speed: 0.2s;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
}

/* Base Typography & Direction */
html[dir="rtl"] {
    font-family: var(--font-fa);
}

html[dir="ltr"] {
    font-family: var(--font-en);
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: var(--bg);
    color: var(--text);
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 100vh;
}

/* ==========================================================================
   UI COMPONENTS & CONTRAST ADJUSTMENTS
   ========================================================================== */

/* Glass Cards mapped to Epsilon tokens */
.glass-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card, 0 4px 18px -2px rgba(0, 0, 0, 0.1));
    color: var(--text);
    transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

.glass-card:hover {
    border-color: var(--accent);
}

.glass-panel {
    background-color: var(--panel);
    border-color: var(--border);
}

/* Inputs & Forms */
input, select, textarea {
    background-color: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--text) !important;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary) !important;
    outline: 2px solid var(--primary-soft) !important;
    outline-offset: 1px;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Tab panes */
.tab-pane {
    animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modal Content & Backdrop */
.modal-backdrop {
    background-color: rgba(3, 10, 18, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.light .modal-backdrop {
    background-color: rgba(18, 38, 63, 0.45);
}

.modal-content {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.4);
    color: var(--text);
}

/* Tabular nums for clean financial figure alignment */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

/* Mobile Safe Areas & 320px-412px Overflow Protection */
html, body {
    max-width: 100%;
    overflow-x: clip;
}

button,
[role="button"] {
    min-width: 44px;
    min-height: 44px;
}

select,
.nav-link,
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
textarea {
    min-height: 44px;
}

.mobile-bottom-nav .nav-link,
.modal-close-btn {
    min-width: 44px;
    min-height: 44px;
}

@media (max-width: 420px) {
    .app-topbar {
        padding-left: 0.625rem;
        padding-right: 0.625rem;
        flex-wrap: wrap;
        row-gap: 0.375rem;
    }

    main {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .glass-card {
        padding: 0.875rem;
    }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-bottom-nav {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    }
}

/* Focus Indicators (Accessibility) */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Reduced motion preference */
@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;
    }
}
