/* ============================================================
   IQInvest Professional Theme (theme-pro.css)
   Loaded AFTER inline page styles — refines the design system
   site-wide without rewriting the existing templates.
   ============================================================ */

/* ---------- 1. Foundations ---------- */
html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
    letter-spacing: -0.02em;
    line-height: 1.25;
    text-wrap: balance;
}

p { text-wrap: pretty; }

::selection {
    background: rgba(30, 90, 168, 0.25);
}

/* Financial figures should align vertically */
td, .metric-value, .stat-value, .price, .kpi-value {
    font-variant-numeric: tabular-nums;
}

/* ---------- 2. Accessibility: visible focus everywhere ---------- */
:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--primary, #1e5aa8);
    outline-offset: 2px;
    border-radius: 4px;
}

.skip-link {
    position: absolute;
    top: -48px;
    left: 12px;
    z-index: 10000;
    padding: 10px 18px;
    background: var(--primary, #1e5aa8);
    color: #fff;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    text-decoration: none;
    transition: top 0.15s ease;
}

.skip-link:focus {
    top: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@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;
    }
}

/* ---------- 3. Header polish ---------- */
.header {
    position: sticky;
    top: 0;
    z-index: 900;
    backdrop-filter: saturate(1.4) blur(12px);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    background: color-mix(in srgb, var(--bg-primary, #fff) 88%, transparent);
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    box-shadow: 0 1px 3px rgba(10, 25, 41, 0.06);
}

.nav-tab {
    position: relative;
    font-weight: 600;
    border-radius: 8px;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-tab:hover {
    background: var(--hover-bg, #f8fafc);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -2px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: var(--primary, #1e5aa8);
}

/* ---------- 4. Buttons: consistent, confident ---------- */
button, .btn-primary, .btn-secondary, .search-btn, .add-btn, .recovery-btn {
    font-family: inherit;
}

.btn-primary, .search-btn, .add-btn {
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: box-shadow 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.btn-primary:hover, .search-btn:hover, .add-btn:hover {
    box-shadow: 0 6px 16px rgba(30, 90, 168, 0.35);
    transform: translateY(-1px);
}

.btn-primary:active, .search-btn:active, .add-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(30, 90, 168, 0.3);
}

button:disabled, .btn-primary:disabled, .search-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ---------- 5. Inputs & forms ---------- */
.search-input, .form-input, .preference-select, .form-textarea {
    border-radius: 10px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus, .form-input:focus, .preference-select:focus, .form-textarea:focus {
    border-color: var(--primary, #1e5aa8);
    box-shadow: 0 0 0 4px rgba(30, 90, 168, 0.15);
}

.search-input::placeholder, .form-input::placeholder {
    color: var(--text-tertiary, #64748b);
    opacity: 0.8;
}

/* Required-field affordance */
.form-label[data-required]::after {
    content: ' *';
    color: var(--danger, #b42318);
}

/* ---------- 6. Cards ---------- */
.card, .feature-card, .comparison-chart-container, .expandable-section {
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 14px;
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.feature-card {
    cursor: pointer;
}

.feature-card:hover, .feature-card:focus-visible {
    transform: translateY(-3px);
    border-color: var(--primary, #1e5aa8);
    box-shadow: 0 12px 24px -8px rgba(10, 25, 41, 0.18);
}

/* ---------- 7. Tables ---------- */
table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

thead th {
    position: sticky;
    top: 0;
    background: var(--bg-secondary, #f8fafc);
    z-index: 1;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary, #475569);
}

tbody tr:hover {
    background: var(--hover-bg, #f8fafc);
}

td, th {
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

/* ---------- 8. Modals ---------- */
.modal {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    border-radius: 16px;
    border: 1px solid var(--border-color, #e2e8f0);
    box-shadow: 0 25px 60px -12px rgba(10, 25, 41, 0.4);
}

/* ---------- 9. Toasts ---------- */
.toast {
    border-radius: 12px;
    box-shadow: 0 10px 30px -6px rgba(10, 25, 41, 0.3);
    font-weight: 500;
}

/* ---------- 10. Scrollbars ---------- */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300, #cbd5e1);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--gray-400, #94a3b8);
}

/* ---------- 11. Site footer ---------- */
.site-footer {
    margin-top: 64px;
    background: var(--dark, #0a2540);
    color: #cbd5e1;
    padding: 48px 24px 32px;
    font-size: 14px;
    line-height: 1.7;
}

.site-footer .footer-grid {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 40px;
}

@media (max-width: 1024px) and (min-width: 769px) {
    .site-footer .footer-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.site-footer h4 {
    color: #fff;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 14px;
}

.site-footer a {
    color: #cbd5e1;
    text-decoration: none;
    display: inline-block;
    padding: 3px 0;
}

.site-footer a:hover {
    color: #3b7bc8;
    text-decoration: underline;
}

.site-footer .footer-disclaimer {
    max-width: 1200px;
    margin: 32px auto 0;
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 12px;
    color: #94a3b8;
}

@media (max-width: 768px) {
    .site-footer .footer-grid {
        grid-template-columns: 1fr;
        gap: 28px;
    }
}

/* ---------- 12. Back-to-top ---------- */
.back-to-top {
    position: fixed;
    right: 24px;
    bottom: 96px;
    z-index: 800;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border-color, #e2e8f0);
    background: var(--card-bg, #fff);
    color: var(--primary, #1e5aa8);
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(10, 25, 41, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ---------- 13. Skeleton loading ---------- */
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-tertiary, #f1f5f9) 25%,
        var(--bg-secondary, #f8fafc) 50%,
        var(--bg-tertiary, #f1f5f9) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
    border-radius: 8px;
    min-height: 14px;
}

@keyframes skeleton-shimmer {
    to { background-position: -200% 0; }
}

/* ---------- 14. Print ---------- */
@media print {
    .header, .site-footer, .hero, .chat-button-container, .back-to-top,
    .search-form, .preferences-grid, .toast-container, .loading-overlay {
        display: none !important;
    }
    body { background: #fff !important; color: #000 !important; }
    .results, .card { box-shadow: none !important; border: 1px solid #ddd; }
}

/* ---------- 15. Mobile refinements ---------- */
@media (max-width: 640px) {
    .hero-title { font-size: clamp(26px, 7vw, 34px) !important; }
    .hero-subtitle { font-size: 15px !important; }
    .search-btn, .btn-primary { min-height: 48px; } /* touch target */
    .nav-tab { min-height: 44px; }
    input, select, textarea { font-size: 16px !important; } /* prevent iOS zoom */
}

/* ============================================================
   INSTITUTIONAL REFINEMENTS (v2)
   ============================================================ */

/* Deep-navy hero — restrained, capital-markets tone */
.hero {
    background: linear-gradient(160deg, #081c33 0%, #0a2540 45%, #16437e 130%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.hero-title {
    font-weight: 700;
}

.hero-subtitle {
    color: rgba(237, 242, 248, 0.82);
}

/* Institutional light-mode surface tint */
body {
    background: var(--bg-secondary, #f6f8fb);
}

/* Autocomplete dropdown: cap height, allow scroll (mobile keyboards) */
.autocomplete-dropdown {
    max-height: 40vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 12px;
    box-shadow: 0 16px 40px -12px rgba(8, 28, 51, 0.28);
}

/* Horizontal-scroll wrapper injected around wide tables */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

/* Notched-phone safe areas */
.site-footer {
    padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
}

.back-to-top {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    right: calc(24px + env(safe-area-inset-right, 0px));
}

/* Chat modal: use dynamic viewport units on mobile (iOS toolbar fix) */
@supports (height: 100dvh) {
    @media (max-width: 768px) {
        .chat-modal {
            height: calc(100dvh - 120px) !important;
        }
    }
}

/* Keyboard-shortcuts button is meaningless on touch devices */
@media (pointer: coarse) {
    button[onclick^="showKeyboardShortcuts"] {
        display: none !important;
    }
}

/* Popular-stock chips: single-row scroll on phones instead of tall wrap */
@media (max-width: 640px) {
    .popular-stocks-chips, .recent-searches-chips {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        scroll-snap-type: x proximity;
    }
    .popular-stocks-chips > *, .recent-searches-chips > * {
        flex: 0 0 auto;
        scroll-snap-align: start;
    }
}

/* Legal / static pages (privacy, terms, about, 404) */
.legal-page {
    max-width: 820px;
    margin: 0 auto;
    padding: 48px 24px 80px;
    color: var(--text-primary, #16283c);
    font-size: 15px;
    line-height: 1.75;
}

.legal-page h1 {
    font-size: 32px;
    margin-bottom: 8px;
    color: var(--dark, #0a2540);
}

.legal-page .updated {
    color: var(--text-tertiary, #64748b);
    font-size: 13px;
    margin-bottom: 32px;
}

.legal-page h2 {
    font-size: 20px;
    margin: 32px 0 12px;
    color: var(--dark, #0a2540);
}

.legal-page p, .legal-page li {
    margin-bottom: 12px;
    color: var(--text-secondary, #45586e);
}

.legal-page ul {
    padding-left: 22px;
}

.legal-page a {
    color: var(--primary, #1e5aa8);
}

.legal-topbar {
    background: #0a2540;
    padding: 14px 24px;
}

.legal-topbar a {
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    font-size: 15px;
}
