/* ==========================================================
   responsive.css — All media queries consolidated
                    (1024, 768, 640, 480, 360 breakpoints
                     + polished header + responsive polish
                     + touch targets)
   ========================================================== */

/* ================================================
   RESPONSIVE DESIGN — Mobile-First Enhancements
   ================================================ */

/* --- 1024px: Large Tablets --- */
@media (max-width: 1024px) {
    .main-content {
        padding: var(--spacing-lg);
    }
}

/* --- 768px: Tablets / Landscape Phones --- */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    /* Header — single row, compact */
    .header-container {
        padding: var(--spacing-sm) var(--spacing-md);
        gap: var(--spacing-sm);
    }

    .logo-icon {
        width: 30px;
        height: 30px;
    }

    .logo-text {
        font-size: 1.05rem;
    }

    .header-actions {
        gap: var(--spacing-sm);
    }

    .connection-status {
        display: none;
    }

    .portfolio-selector {
        min-width: 120px;
    }

    /* Main Content */
    .main-content {
        padding: var(--spacing-md);
    }

    /* Tabs */
    .tabs {
        padding: 0 var(--spacing-md);
    }

    .tab {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.82rem;
    }

    /* Cards with multiple actions wrap instead of overflow */
    .card-header {
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }

    .card-actions {
        flex-wrap: wrap;
        gap: var(--spacing-xs);
    }

    /* Holdings controls */
    .holdings-header {
        justify-content: flex-start;
    }

    .holdings-controls {
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }

    /* Chart rows */
    .chart-controls-row {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }

    .chart-stats-display {
        flex-wrap: wrap;
    }

    /* Diversification toggles */
    .div-toggles {
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }

    /* Growth comparison box */
    .comparison-box {
        flex-wrap: wrap;
        font-size: 0.82rem;
        margin: var(--spacing-sm) var(--spacing-md);
    }

    /* Chart heights */
    .chart-container-extra-wide {
        height: 300px;
    }

    .chart-container-wide {
        height: 280px;
    }

    .div-chart-container-growth {
        height: 240px;
    }

    /* Benchmarks bar */
    .benchmarks-bar {
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }

    .benchmarks-left {
        flex-wrap: wrap;
    }
}

/* --- 640px: Portrait Tablets / Large Phones --- */
@media (max-width: 640px) {
    /* Recalculate sticky tabs position for smaller header */
    .tabs-container {
        top: 55px;
    }

    /* Show mobile menu toggle, hide desktop actions */
    .mobile-menu-toggle {
        display: flex;
    }

    /* CRITICAL: .header has `backdrop-filter: blur(10px)` which creates a
       containing block for descendant `position: fixed` elements. Strip it
       on mobile so the drawer's `position: fixed` is relative to the
       viewport again (otherwise the drawer is trapped inside the header's
       tiny box and only ~50px of content shows). */
    .header {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .header-actions {
        display: none;
        position: fixed;
        top: var(--header-height, 55px);
        left: 0;
        right: 0;
        bottom: 0;
        /* Solid, fully-opaque fill so nothing from the app below bleeds through. */
        background: #0f0f23;
        border-top: 1px solid var(--border-color);
        padding: var(--spacing-lg) var(--spacing-md) calc(var(--spacing-2xl) + env(safe-area-inset-bottom));
        flex-direction: column;
        gap: var(--spacing-md);
        /* High z-index — needs to sit above sticky portfolio header (~10)
           and the tabs container (~10). Modal is 1000; we stay below that
           so a modal can still open over the drawer if needed. */
        z-index: 500;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    /* Lock body scroll while drawer is open so swiping doesn't pan the
       app behind and leak visible content at the edges. */
    body:has(.header-actions.mobile-open) {
        overflow: hidden;
    }

    .header-actions.mobile-open {
        display: flex;
    }

    /* Status pill — show label + refresh timer in the opened mobile menu
       (they are hidden on small desktop widths to save space, but when
       the drawer is open we have room and the icon-only pill looks empty).
       Uses `.mobile-open` parent to beat the 1200px hide rule later in source. */
    .header-actions.mobile-open .status-pill {
        order: 0;
        align-self: flex-start;
        padding: 8px 14px;
        width: 100%;
    }
    .header-actions.mobile-open .status-pill-label,
    .header-actions.mobile-open .status-pill-divider,
    .header-actions.mobile-open .refresh-timer {
        display: inline !important;
    }

    /* Group label above selectors — makes the list readable */
    .selectors-group {
        order: 1;
        width: 100%;
    }
    .selectors-group::before {
        content: "Portfolio & Currency";
        display: block;
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-muted);
        margin-bottom: 6px;
        font-weight: 600;
    }

    .portfolio-selector {
        width: 100%;
        max-width: none;
        min-width: unset;
    }

    /* Selects — bigger touch targets */
    .selectors-group .portfolio-selector,
    .select-field .portfolio-selector {
        height: 44px;
        font-size: 0.92rem;
    }
    .select-field {
        width: 100%;
    }

    /* "New Portfolio" button — FULL width with label in mobile drawer.
       Uses `.header-actions.mobile-open` parent to beat the 900px
       icon-only rule that appears later in the source order. */
    .header-actions.mobile-open #btn-new-portfolio {
        order: 2;
        width: 100%;
        height: 46px;
        padding: 0 var(--spacing-md);
        justify-content: center;
        gap: 8px;
    }
    .header-actions.mobile-open #btn-new-portfolio .btn-label {
        display: inline;
    }
    /* Swap the "New" label for something more descriptive on mobile */
    .header-actions.mobile-open #btn-new-portfolio .btn-label::before {
        content: "Add ";
    }

    .user-menu {
        width: 100%;
        order: 3;
        margin-top: var(--spacing-sm);
        border-top: 1px solid var(--border-color);
        padding-top: var(--spacing-md);
    }

    .user-menu-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 10px 14px;
        min-height: 52px;
        gap: 12px;
    }
    .user-menu-btn .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    .user-menu-btn .user-name {
        max-width: none;
        flex: 1;
        font-weight: 600;
    }

    /* User dropdown — ALWAYS visible inline below the user button on mobile
       (no need to toggle — saves a tap and removes confusion). */
    .user-dropdown {
        position: static;
        margin-top: var(--spacing-sm);
        box-shadow: none;
        border: 1px solid var(--border-color);
        display: block !important;
        width: 100%;
    }
    .user-dropdown .dropdown-item {
        padding: 14px 16px;
        font-size: 0.95rem;
        min-height: 48px;
        display: flex;
        align-items: center;
    }

    /* Header layout */
    .header {
        position: sticky;
    }

    .header-container {
        position: relative;
    }

    .logo-text {
        font-size: 1rem;
    }

    .logo-icon {
        width: 28px;
        height: 28px;
    }

    /* Portfolio Header - mobile friendly */
    .portfolio-header-container {
        padding: var(--spacing-md);
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-md);
    }

    .portfolio-info {
        width: 100%;
        gap: var(--spacing-md);
    }

    .portfolio-avatar {
        width: 42px;
        height: 42px;
        flex-shrink: 0;
    }

    .portfolio-avatar svg {
        width: 22px;
        height: 22px;
    }

    .portfolio-title {
        font-size: 1.15rem;
    }

    .portfolio-author {
        font-size: 0.78rem;
        margin-bottom: 2px;
    }

    /* Stats in portfolio header - horizontal scroll on mobile */
    .portfolio-stats-summary {
        width: 100%;
        gap: 0;
        background: var(--bg-card);
        border-radius: var(--radius-md);
        border: 1px solid var(--border-color);
        overflow: hidden;
    }

    .portfolio-stats-summary .stat-item {
        flex: 1;
        text-align: center;
        padding: var(--spacing-sm) var(--spacing-xs);
        border-right: 1px solid var(--border-color);
    }

    .portfolio-stats-summary .stat-item:last-child {
        border-right: none;
    }

    .stat-label {
        font-size: 0.65rem;
        letter-spacing: 0.03em;
    }

    .stat-value {
        font-size: 0.9rem;
    }

    /* Main content */
    .main-content {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    /* Tabs - better touch targets */
    .tabs {
        padding: 0 var(--spacing-sm);
        gap: 0;
        -webkit-overflow-scrolling: touch;
    }

    .tab {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.8rem;
        flex-shrink: 0;
    }

    /* Holding name truncation */
    .holding-name {
        max-width: 120px;
    }

    /* Portfolio breakdown chart */
    .chart-container-donut {
        max-width: 220px;
        margin: 0 auto;
    }

    /* Diversification chart */
    .div-chart-container {
        width: 200px;
        height: 200px;
    }

    /* Stats grid — 2 columns */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Value sizes */
    .metric-value {
        font-size: 1.4rem;
    }

    .stat-card-value.large {
        font-size: 1.5rem;
    }

    /* Yearly stats table — tighter cells */
    .holdings-table th,
    .holdings-table td {
        padding: var(--spacing-sm);
    }

    /* Toast notifications */
    .toast-container {
        bottom: var(--spacing-md);
        right: var(--spacing-md);
        left: var(--spacing-md);
    }

    .toast {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.875rem;
    }

    /* Modal — bottom sheet on mobile */
    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content,
    .modal-content.modal-sm,
    .modal-content.modal-lg {
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-width: 100%;
        max-height: 92vh;
    }

    /* Footer */
    .footer-container {
        flex-direction: column;
        text-align: center;
        padding: var(--spacing-lg);
        gap: var(--spacing-sm);
    }

    .footer-right {
        justify-content: center;
    }
}

/* --- 480px: Small Phones --- */
@media (max-width: 480px) {
    .tabs-container {
        top: 50px;
    }

    /* Header */
    .logo-text {
        font-size: 0.9rem;
    }

    .logo-icon {
        width: 26px;
        height: 26px;
    }

    .header-container {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    /* Auth screen */
    .auth-card {
        padding: 28px 20px;
        margin: 0 var(--spacing-sm);
    }

    .auth-logo .logo-mark svg {
        width: 48px;
        height: 48px;
    }

    .auth-logo h1 {
        font-size: 1.3rem;
    }

    /* Portfolio Header */
    .portfolio-header-container {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .portfolio-avatar {
        width: 36px;
        height: 36px;
    }

    .portfolio-avatar svg {
        width: 18px;
        height: 18px;
    }

    .portfolio-title {
        font-size: 1rem;
    }

    .portfolio-title-row {
        gap: var(--spacing-sm);
    }

    .portfolio-actions .btn-icon {
        width: 28px;
        height: 28px;
        padding: 4px;
    }

    .portfolio-actions .btn-icon svg {
        width: 14px;
        height: 14px;
    }

    /* Tabs */
    .tab {
        padding: var(--spacing-sm) 10px;
        font-size: 0.75rem;
    }

    /* Main content */
    .main-content {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    /* Search box narrower */
    .search-box input {
        width: 100px;
    }

    /* Charts */
    .chart-container-extra-wide {
        height: 220px;
    }

    .chart-container-wide {
        height: 220px;
    }

    .div-chart-container-growth {
        height: 200px;
    }

    /* Stats grid — single column */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Card actions — tighter buttons */
    .card-actions .btn-sm {
        padding: 4px var(--spacing-sm);
        font-size: 0.75rem;
    }

    .card-actions .btn-sm svg {
        width: 12px;
        height: 12px;
    }

    /* Div-tabs wrap tighter */
    .div-tab {
        padding: 4px var(--spacing-sm);
        font-size: 0.8rem;
    }

    /* Pagination — compact */
    .pagination-controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--spacing-sm);
    }

    #pagination-info {
        width: 100%;
        text-align: center;
    }

    /* Portfolio breakdown stacked at small sizes */
    .portfolio-breakdown {
        grid-template-columns: 1fr;
    }

    /* Cards - less padding on mobile */
    .card {
        border-radius: var(--radius-md);
    }

    .card-header {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* --- 360px: Very Small Phones --- */
@media (max-width: 360px) {
    .tab {
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .portfolio-title {
        font-size: 0.9rem;
    }

    .portfolio-stats-summary .stat-item {
        padding: var(--spacing-xs) var(--spacing-xs);
    }

    .stat-value {
        font-size: 0.8rem;
    }

    .stat-label {
        font-size: 0.6rem;
    }

    .div-chart-container {
        width: 160px;
        height: 160px;
    }
}

/* Responsive — stack chips with smaller font on narrow screens */
@media (max-width: 720px) {
    .stat-currency-breakdown,
    .stats-card-currency-breakdown {
        font-size: 11px;
        gap: 4px 6px;
    }
    .ccy-item { padding: 1px 7px 1px 3px; }
    .ccy-code { font-size: 10px; padding: 2px 5px; }
    .currency-selector {
        min-width: 0;
        width: 100%;
        margin-left: 0;
        margin-top: 6px;
    }
}
@media (max-width: 480px) {
    .stat-currency-breakdown,
    .stats-card-currency-breakdown { gap: 3px 4px; }
}

/* ── Polished header — v2 ───────────────────────────────────────────── */

/* Status pill (connection dot + refresh countdown) */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    height: 36px;
    border-radius: 999px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.status-pill:hover { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.14); }
.status-pill .connection-dot { flex-shrink: 0; }
.status-pill-label { font-weight: 600; color: var(--text-primary, #e2e8f0); }
.status-pill-divider { opacity: 0.4; margin: 0 1px; }
.status-pill svg { opacity: 0.7; }
.status-pill .refresh-timer {
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    min-width: 28px;
    text-align: left;
}
.status-pill .refresh-timer.refreshing { color: #a5b4fc; }

/* Selectors group — portfolio + currency side by side */
.selectors-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px;
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
}

.select-field {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.select-field .select-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-secondary, #94a3b8);
    opacity: 0.8;
}

/* Override the old selector chrome to fit the grouped look */
.selectors-group .portfolio-selector {
    padding: 8px 30px 8px 30px;
    height: 34px;
    font-size: 13px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.07);
    background: rgba(15,23,42,0.6);
    min-width: 170px;
    max-width: 220px;
    text-overflow: ellipsis;
    appearance: none;
    cursor: pointer;
}
.selectors-group .portfolio-selector:hover {
    border-color: rgba(99,102,241,0.4);
}
.selectors-group .portfolio-selector:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.selectors-group .currency-selector { min-width: 160px; max-width: 200px; }

/* View-as-user selector — highlight when viewing another user */
.view-as-field.viewing-other .portfolio-selector {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.08);
    color: #f59e0b;
}
.view-as-field.viewing-other .select-icon {
    color: #f59e0b;
}

/* Allow full user-name display (no truncation when possible) */

.user-menu-btn .user-name {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* "New" button — compact with icon */
#btn-new-portfolio {
    height: 36px;
    padding: 0 14px;
    gap: 6px;
    font-size: 13px;
    white-space: nowrap;
}
#btn-new-portfolio .btn-label { font-weight: 600; }

/* Responsive tweaks */
@media (max-width: 1200px) {
    .selectors-group .portfolio-selector { min-width: 140px; max-width: 180px; }
    .status-pill-label { display: none; }
    .status-pill-divider { display: none; }
}
@media (max-width: 900px) {
    .selectors-group {
        flex-direction: column;
        background: transparent;
        border: none;
        padding: 0;
        gap: 4px;
        width: 100%;
    }
    .selectors-group .portfolio-selector {
        width: 100%;
        min-width: 0;
        max-width: none;
    }
    .status-pill { padding: 6px 10px; }
    #btn-new-portfolio .btn-label { display: none; }
    #btn-new-portfolio { padding: 0 10px; width: 36px; }
}

/* ── Universal responsive polish ────────────────────────────────────── */

/* Desktop: keep the original horizontal flex layout.
   We only switch to a grid on tablet/phone so the items wrap nicely. */
.portfolio-stats-summary .stat-item {
    min-width: 0; /* allow text to ellipsis instead of overflowing */
}
.portfolio-stats-summary .stat-value {
    font-variant-numeric: tabular-nums;
    word-break: keep-all;
    overflow-wrap: anywhere;
}

/* Tablet: switch the flex row to a grid so items wrap cleanly */
@media (max-width: 900px) {
    .portfolio-stats-summary {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 14px;
    }
    .portfolio-stats-summary .stat-item { text-align: left; }
    .portfolio-title { font-size: 20px; }
    .stats-card-value { font-size: 20px; }
}

/* Small tablet / large phone */
@media (max-width: 640px) {
    .portfolio-stats-summary { gap: 10px 12px; }
    .portfolio-stats-summary .stat-value { font-size: 15px; }
    .portfolio-stats-summary .stat-label { font-size: 10px; letter-spacing: 0.05em; }
    .portfolio-header-container { padding: 10px 12px !important; }
    .header-container { padding: 8px 12px !important; }
}

/* Phones */
@media (max-width: 520px) {
    .portfolio-stats-summary { grid-template-columns: 1fr 1fr; gap: 8px 10px; }
    .portfolio-stats-summary .stat-item {
        padding: 8px 10px;
        background: rgba(255,255,255,0.02);
        border: 1px solid rgba(255,255,255,0.05);
        border-radius: 10px;
    }
    .stats-card {
        padding: 14px !important;
    }
    .stats-card-value { font-size: 18px !important; }
    .tabs-container { padding: 0 6px !important; }
    .tab {
        font-size: 12px !important;
        padding: 8px 10px !important;
    }
    .card { padding: 14px !important; }
    /* Tighter currency chips on phones */
    .ccy-item { padding: 1px 6px 1px 3px; gap: 4px; }
    .ccy-code { font-size: 8.5px; padding: 2px 5px; }
    .stat-currency-breakdown, .stats-card-currency-breakdown {
        font-size: 10.5px;
        gap: 3px 4px;
    }
}

/* Very small phones (iPhone SE, etc.) */
@media (max-width: 380px) {
    .portfolio-stats-summary { grid-template-columns: 1fr; }
    .portfolio-stats-summary .stat-item { padding: 10px 12px; }
    .logo-text { font-size: 14px !important; }
    .tab { padding: 7px 8px !important; }
}

/* Touch-friendly hit targets on any pointer: coarse (touch) device */
@media (pointer: coarse) {
    .btn, .btn-icon, .tab, .nav-link, select, .user-menu-btn {
        min-height: 40px;
    }
    .ccy-item { padding-block: 3px; }
}

/* Tables: let them scroll horizontally on narrow screens without breaking layout */
.main-content table,
.card table {
    max-width: 100%;
}
@media (max-width: 900px) {
    .table-wrapper,
    .card-body > .card,
    .breakdown-table-card,
    .tx-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Modals: full-screen feel on phones so forms are usable */
@media (max-width: 520px) {
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100%;
        max-height: 100%;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    .modal-body { padding: 14px !important; }
}

/* Charts keep their aspect ratio without overflow */
.chart-container, .chart-container-donut {
    max-width: 100%;
}
canvas {
    max-width: 100% !important;
}

/* Prevent horizontal overflow anywhere on small viewports */
@media (max-width: 520px) {
    html, body { overflow-x: hidden; }
    main, section { max-width: 100vw; }
}

/* ── Sticky, single-line table headers everywhere ──────────────── */
/* Solid background is REQUIRED — otherwise rows show through while scrolling. */
table thead,
table thead tr,
table thead th {
    background: #1a1a2e !important;
    background-color: #1a1a2e !important;
}
table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    white-space: nowrap;        /* keep headers on one line */
    box-shadow: 0 2px 0 rgba(0,0,0,0.4), 0 1px 0 rgba(255,255,255,0.06);
}
/* Extra safety: the thead's ::before covers any sub-pixel gap some browsers
   leave between the sticky header and the first row when scrolling. */
table thead th::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -1px;
    height: 1px;
    background: #1a1a2e;
}

/* Scroll container fills most of the viewport so rows have room to scroll
   while column headers stay visible. `overscroll-behavior: contain` keeps
   the scroll inside the table until it reaches top/bottom — then the page
   continues to the next section naturally. */
.breakdown-scroll-wrapper,
.table-wrapper,
.holdings-scroll-wrapper,
.tx-table-wrapper,
.table-container {
    max-height: calc(100vh - 220px);
    min-height: 320px;
    overflow: auto;
    /* `auto` (default) chains the scroll to the page once the rows are
       fully scrolled — first scroll the rows, then advance to next section. */
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    scrollbar-width: thin;
}
@media (max-width: 900px) {
    .breakdown-scroll-wrapper,
    .table-wrapper,
    .holdings-scroll-wrapper,
    .tx-table-wrapper,
    .table-container { max-height: calc(100vh - 180px); min-height: 280px; }
}
@media (max-width: 520px) {
    .breakdown-scroll-wrapper,
    .table-wrapper,
    .holdings-scroll-wrapper,
    .tx-table-wrapper,
    .table-container { max-height: calc(100vh - 160px); min-height: 240px; }
}

/* Generic pagination controls (used by every table) */
.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px 4px;
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
}
.pager-info { margin-right: auto; }
.pager button {
    min-width: 32px;
    height: 30px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.03);
    color: var(--text-primary, #e2e8f0);
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.pager button:hover:not(:disabled) {
    background: rgba(99,102,241,0.12);
    border-color: rgba(99,102,241,0.4);
}
.pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.pager select {
    height: 30px;
    padding: 0 8px;
    border-radius: 8px;
    background: rgba(15,23,42,0.6);
    color: var(--text-primary, #e2e8f0);
    border: 1px solid rgba(255,255,255,0.08);
    font-size: 12px;
    cursor: pointer;
}

/* ── Natural in-table scrolling (no global snap) ────────────────────── */
/* CSS scroll-snap on <html> fights with sticky thead + sticky app header
   and makes the column headers disappear. Instead we do the simpler, more
   reliable thing: give each scrollable table wrapper a near-viewport height
   plus `overscroll-behavior: contain`, so scrolling rows is trapped inside
   the table until it reaches its top or bottom; only then does the page
   continue scrolling to the next section. */
.tab-content > .card,
.tab-content > .stats-cards-grid,
.tab-content > .portfolio-breakdown,
.tab-content > section,
.tab-content > .stats-grid,
.tab-content > .holdings-card,
.tab-content > .breakdown-table-card {
    scroll-margin-top: 100px; /* offset for sticky header + tabs on jumps */
}

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

/* (No overscroll-behavior here — let the browser chain scroll once the
   table reaches its top/bottom, so the page advances to the next section.) */

/* Per-row multi-currency chips inside the portfolio breakdown table */
.breakdown-row-ccy {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 6px;
    margin-top: 6px;
    justify-content: flex-end;
}
.breakdown-row-ccy .ccy-item {
    font-size: 11px;
    padding: 1px 7px 1px 3px;
}
.breakdown-row-ccy .ccy-code {
    font-size: 9px;
    padding: 2px 5px;
}

/* ── Desktop: polished portfolio stats summary ──────────────────── */
@media (min-width: 901px) {
    .portfolio-stats-summary {
        display: flex;
        align-items: flex-start;
        gap: 14px;
        flex-wrap: wrap;
        padding: 4px 0;
    }
    .portfolio-stats-summary .stat-item {
        flex: 1 1 180px;
        min-width: 180px;
        max-width: 260px;
        text-align: right;
        padding: 10px 16px;
        border-radius: 10px;
        background: rgba(255,255,255,0.02);
        border: 1px solid rgba(255,255,255,0.05);
        transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    }
    .portfolio-stats-summary .stat-item:hover {
        background: rgba(99,102,241,0.06);
        border-color: rgba(99,102,241,0.25);
    }
    .portfolio-stats-summary .stat-label {
        display: block;
        font-size: 11px;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--text-muted, #94a3b8);
        margin-bottom: 6px;
        white-space: nowrap;
    }
    .portfolio-stats-summary .stat-value {
        display: block;
        font-size: 18px;
        font-weight: 600;
        line-height: 1.25;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        text-align: left;
    }
    .portfolio-stats-summary .stat-currency-breakdown {
        margin-top: 8px;
        justify-content: flex-end;
        gap: 4px 6px;
    }
    .portfolio-stats-summary .ccy-item {
        font-size: 11px;
        padding: 2px 7px 2px 3px;
    }
    .portfolio-stats-summary .ccy-code {
        font-size: 9px;
        padding: 2px 5px;
    }
}

/* Wider screens — spread out a bit more */
@media (min-width: 1280px) {
    .portfolio-stats-summary {
        gap: 10px;
        width: 100%;
    }
    .portfolio-stats-summary .stat-item {
        padding: 12px 18px;
    }
}

/* ── Sticky tabs nav — guaranteed across all devices ─────────── */
.tabs-container {
    position: sticky !important;
    position: -webkit-sticky !important;
    top: 75px;
    z-index: 45;
    background: var(--bg-primary, #0f0f23);
    background-color: var(--bg-primary, #0f0f23);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.25);
}

/* Ancestors must not clip or create new scroll contexts, or sticky breaks.
   overflow-x:hidden on <html>/<body> was killing sticky on phones — replace
   with contain so horizontal overflow is still prevented without breaking
   sticky. */
@media (max-width: 520px) {
    html, body {
        overflow-x: clip !important;
    }
}
main, .main-content, section.tab-content {
    overflow: visible !important;
}

/* Align the sticky top value to the actual header height at each breakpoint */
@media (max-width: 640px) {
    .tabs-container { top: 55px; }
}
@media (max-width: 480px) {
    .tabs-container { top: 50px; }
}

/* Equal-height stat cards + secondary amount line */
.portfolio-stats-summary .stat-item {
    align-self: stretch;           /* fill the row height */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
}
.portfolio-stats-summary .stat-subvalue {
    display: block;
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Percent sub-line under a stat amount (Daily Change, Total Gain, Unrealized G/L, …) */
.portfolio-stats-summary .stat-pct-sub {
    font-size: 14px;
    font-weight: 600;
    margin-top: 2px;
    white-space: nowrap;
}
.portfolio-stats-summary .stat-pct-sub.positive { color: var(--success, #10b981); }
.portfolio-stats-summary .stat-pct-sub.negative { color: var(--danger, #ef4444); }

/* Keep primary amounts on one line */
.portfolio-stats-summary .stat-value { white-space: nowrap; }
/* The wrapping issue: large numbers like "+$15,500.13 (+18.77%)" were
   overflowing the card because `white-space: nowrap` forced a single line
   that couldn't shrink. Let long values wrap to 2 lines gracefully. */
@media (min-width: 901px) {
    .portfolio-stats-summary .stat-value {
        white-space: normal;
        line-height: 1.2;
    }
}
