/* ================================================================
   ExtremeTrades — application UI (dashboard, members + admin)
   ----------------------------------------------------------------
   Requires theme.css to be linked first (design tokens live there).

   Every class name here is load-bearing: app.js builds markup at
   runtime with these exact names, so selectors are preserved even
   where the styling changed. Grep app.js before renaming anything.
   ================================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--fs-md);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); }

/* Subtle depth behind the whole app — keeps large dark areas from
   reading as flat black on wide monitors. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(900px 500px at 82% -8%, rgba(79, 125, 249, 0.07), transparent 70%),
        radial-gradient(700px 420px at 10% 105%, rgba(34, 197, 94, 0.04), transparent 70%);
}

/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--t-slow);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: 0 var(--s-4);
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand-icon {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    background: linear-gradient(140deg, var(--accent), #7ea0ff);
    font-size: 0.9rem;
    box-shadow: 0 2px 10px rgba(79, 125, 249, 0.32);
    flex-shrink: 0;
}

.brand-text {
    font-size: var(--fs-lg);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    padding: var(--s-3) var(--s-2);
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: 9px var(--s-3);
    border-radius: var(--r-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--fs-md);
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--t-fast), color var(--t-fast);
}

.nav-link:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-soft);
    color: var(--text-primary);
    font-weight: 600;
}

/* Active rail marker */
.nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    border-radius: 0 var(--r-xs) var(--r-xs) 0;
    background: var(--accent);
}

.nav-icon {
    font-size: 0.95rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.9;
}

.sidebar-footer {
    padding: var(--s-4);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ================================================================
   MOBILE HEADER
   ================================================================ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: rgba(16, 19, 28, 0.9);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 var(--s-4);
    gap: var(--s-3);
    z-index: 90;
}

.hamburger {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast);
}

.hamburger:hover {
    background: var(--bg-elevated);
    border-color: var(--border);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 99;
}

.sidebar-overlay.active { display: block; }

/* ================================================================
   MAIN CONTENT + TOPBAR
   ================================================================ */
.main-content {
    position: relative;
    z-index: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 80;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--s-4);
    padding: 0 var(--s-8);
    min-height: var(--topbar-height);
    background: rgba(16, 19, 28, 0.82);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    min-width: 0;
}

.page-title {
    font-size: var(--fs-xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-name {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ================================================================
   PAGE SECTIONS
   ================================================================ */
.page-section {
    display: none;
    padding: var(--s-6) var(--s-8) var(--s-12);
    flex: 1;
    max-width: 1560px;
    width: 100%;
}

.page-section.active {
    display: block;
    animation: sectionIn 0.22s ease both;
}

@keyframes sectionIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}

/* ================================================================
   CARDS
   ================================================================ */
.card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s-5);
    margin-bottom: var(--s-5);
    box-shadow: var(--shadow-sm);
}

.card-compact { padding: var(--s-4) var(--s-5); }

.card-title {
    font-size: var(--fs-lg);
    font-weight: 650;
    letter-spacing: -0.01em;
    margin-bottom: var(--s-4);
    display: flex;
    align-items: center;
    gap: var(--s-2);
}

.card-title-meta {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    font-weight: 400;
}

.card h2 {
    font-size: var(--fs-lg);
    font-weight: 650;
    margin-bottom: var(--s-4);
    display: flex;
    align-items: center;
    gap: var(--s-2);
}

.card h3 { font-size: var(--fs-md); font-weight: 650; }

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--s-4);
    flex-wrap: wrap;
    gap: var(--s-3);
}

.card-header-row .card-title { margin-bottom: 0; }

/* Legacy shell, still used by the login/auth pages */
.container { max-width: 1200px; margin: 0 auto; padding: var(--s-5); }

header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: var(--s-4) 0;
    margin-bottom: var(--s-6);
}
header .container { display: flex; justify-content: space-between; align-items: center; }
.logo { font-size: 1.35rem; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; }
.logo span { color: var(--text-secondary); font-weight: 400; font-size: var(--fs-sm); margin-left: var(--s-2); }

/* ================================================================
   BADGES
   ================================================================ */
.env-badge {
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: var(--fs-2xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    border: 1px solid transparent;
}
.env-demo { background: var(--warning-soft); color: var(--warning); border-color: rgba(245, 158, 11, 0.28); }
.env-live { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(239, 68, 68, 0.28); }

.status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--r-xs);
    font-size: var(--fs-2xs);
    font-weight: 650;
    letter-spacing: 0.02em;
    white-space: nowrap;
    border: 1px solid transparent;
}
.status-active,
.status-processed { background: var(--success-soft); color: var(--success); border-color: rgba(34, 197, 94, 0.26); }
.status-error,
.status-blocked   { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(239, 68, 68, 0.26); }
.status-received,
.status-pending   { background: var(--accent-soft);  color: var(--accent);  border-color: rgba(79, 125, 249, 0.26); }

/* ================================================================
   GRID
   ================================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
    padding: 8px var(--s-4);
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--fs-md);
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-outline {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
    border-color: var(--border-strong);
    color: var(--text-primary);
    background: #222839;
}

.btn-sm { padding: 5px 10px; font-size: var(--fs-xs); }

/* ================================================================
   FORMS
   ================================================================ */
.form-group { margin-bottom: var(--s-3); }

.form-group label {
    display: block;
    font-size: var(--fs-xs);
    font-weight: 550;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea,
.inline-form input,
.inline-form select {
    width: 100%;
    padding: 8px var(--s-3);
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--fs-md);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.form-group input::placeholder,
.inline-form input::placeholder { color: var(--text-tertiary); }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.inline-form input:focus,
.inline-form select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.form-group input:disabled,
.form-group select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.inline-form {
    display: flex;
    gap: var(--s-2);
    align-items: center;
    flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
    width: auto;
    padding: 6px var(--s-3);
    font-size: var(--fs-sm);
}

.form-actions {
    display: flex;
    gap: var(--s-2);
    align-items: center;
    margin-top: var(--s-3);
    flex-wrap: wrap;
}

.form-status {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.group-form {
    display: flex;
    gap: var(--s-2);
    align-items: flex-end;
    flex-wrap: wrap;
}

/* Range slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: var(--border-strong);
    border-radius: var(--r-full);
    outline: none;
    cursor: pointer;
    padding: 0;
    margin: 0;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-card);
}

/* Toggle switch */
.toggle-switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; display: inline-block; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-strong);
    border-radius: var(--r-full);
    transition: background var(--t-base);
    cursor: pointer;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: transform var(--t-base);
}
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle-switch input:focus-visible + .toggle-slider { box-shadow: 0 0 0 3px var(--accent-ring); }

/* ================================================================
   TABLES
   ================================================================ */
table { width: 100%; border-collapse: collapse; }

th, td {
    padding: 9px var(--s-3);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--fs-sm);
}

th {
    color: var(--text-tertiary);
    font-weight: 650;
    font-size: var(--fs-2xs);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-bottom-color: var(--border);
    white-space: nowrap;
}

tbody tr { transition: background var(--t-fast); }
tbody tr:hover { background: var(--accent-softer); }
tbody tr:last-child td { border-bottom: none; }

/* ================================================================
   WEBHOOK URL BOX
   ================================================================ */
.webhook-url {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 10px var(--s-3);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    word-break: break-all;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--s-2);
}
.webhook-url code { color: var(--accent); flex: 1; }

.copy-btn {
    cursor: pointer;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-xs);
    font-family: inherit;
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 4px 10px;
    white-space: nowrap;
    transition: color var(--t-fast), border-color var(--t-fast);
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ================================================================
   CONNECTION CARDS
   ================================================================ */
.connections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
    gap: var(--s-3);
}

.connection-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-4);
    cursor: pointer;
    transition: border-color var(--t-base), box-shadow var(--t-base), transform var(--t-fast);
}
.connection-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.connection-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 4px 18px rgba(79, 125, 249, 0.18);
}
.connection-card.unhealthy { border-color: var(--danger); }

.connection-card .conn-header { display: flex; flex-direction: column; gap: var(--s-2); }
.connection-card .conn-top { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); }
.connection-card .conn-name { font-size: var(--fs-md); font-weight: 700; word-break: break-word; letter-spacing: -0.01em; }
.connection-card .conn-meta { font-size: var(--fs-2xs); color: var(--text-tertiary); margin-top: 2px; }
.connection-card .conn-actions { display: flex; gap: var(--s-1); align-items: center; flex-wrap: wrap; }

.connection-card .conn-balance {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--s-2);
    margin-top: var(--s-3);
    padding-top: var(--s-3);
    border-top: 1px solid var(--border);
}
.connection-card .conn-bal-item .label {
    font-size: var(--fs-2xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.connection-card .conn-bal-item .value { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -0.01em; }
.connection-card .conn-bal-item .value.positive { color: var(--success); }
.connection-card .conn-bal-item .value.negative { color: var(--danger); }

/* Legacy list row — still used by groups */
.connection-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    margin-bottom: var(--s-2);
}
.connection-info h3 { font-size: var(--fs-md); font-weight: 650; }
.connection-info p { font-size: var(--fs-xs); color: var(--text-secondary); }

/* ================================================================
   BALANCES
   ================================================================ */
.balance-display { display: flex; gap: var(--s-3); flex-wrap: wrap; }

.balance-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-3) var(--s-4);
    min-width: 138px;
    flex: 1;
}
.balance-item .label {
    font-size: var(--fs-2xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 650;
}
.balance-item .value {
    font-size: var(--fs-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-top: 3px;
}
.balance-item .value.positive { color: var(--success); }
.balance-item .value.negative { color: var(--danger); }

/* ================================================================
   POSITIONS
   ================================================================ */
.position-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    margin-bottom: var(--s-2);
    transition: border-color var(--t-fast);
}
.position-row:hover { border-color: var(--border-strong); }

.position-info { display: flex; gap: var(--s-6); align-items: center; flex-wrap: wrap; }
.position-symbol { font-weight: 700; font-size: var(--fs-lg); min-width: 96px; letter-spacing: -0.01em; }
.position-detail { font-size: var(--fs-sm); color: var(--text-secondary); }
.position-detail span { color: var(--text-primary); font-weight: 650; }
.position-pnl { font-weight: 700; font-size: var(--fs-lg); min-width: 84px; text-align: right; letter-spacing: -0.01em; }
.position-pnl.positive { color: var(--success); }
.position-pnl.negative { color: var(--danger); }

.btn-close-pos {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 6px var(--s-3);
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: 650;
    cursor: pointer;
    margin-left: var(--s-4);
    white-space: nowrap;
    transition: background var(--t-fast), color var(--t-fast);
}
.btn-close-pos:hover { background: var(--danger); color: #fff; }

/* ================================================================
   COLLAPSIBLES
   ================================================================ */
.collapsible { cursor: pointer; user-select: none; }
.collapsible:hover { color: var(--accent); }

.collapse-icon {
    font-size: var(--fs-xs);
    margin-left: 6px;
    transition: transform var(--t-base);
    display: inline-block;
    color: var(--text-tertiary);
}
.collapse-icon.collapsed { transform: rotate(-90deg); }

.collapsible-content {
    overflow: hidden;
    transition: max-height var(--t-slow), opacity var(--t-base);
    max-height: 4000px;
    opacity: 1;
}
.collapsible-content.hidden { max-height: 0; opacity: 0; }

/* ================================================================
   BANNERS + EMPTY STATES
   ================================================================ */
.risk-lock-banner {
    background: var(--danger-soft);
    border: 1px solid rgba(239, 68, 68, 0.35);
    border-left: 3px solid var(--danger);
    border-radius: var(--r-sm);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: var(--fs-md);
}

.empty {
    text-align: center;
    padding: var(--s-8) var(--s-5);
    color: var(--text-tertiary);
    font-size: var(--fs-md);
    border: 1px dashed var(--border);
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, 0.012);
}

/* ================================================================
   CODE + HELP TEXT
   ================================================================ */
pre.json-sample {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: var(--s-3) var(--s-4);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: 1.65;
    overflow-x: auto;
    color: var(--text-secondary);
}

.section-desc {
    font-size: var(--fs-md);
    color: var(--text-secondary);
    margin-bottom: var(--s-3);
    max-width: 78ch;
}

.sample-label {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--s-2);
}

.alert-reference {
    margin-top: var(--s-4);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

/* ================================================================
   TOAST
   ================================================================ */
.toast {
    position: fixed;
    bottom: var(--s-6);
    right: var(--s-6);
    padding: var(--s-3) var(--s-5);
    border-radius: var(--r-md);
    color: #fff;
    font-size: var(--fs-md);
    font-weight: 550;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
@keyframes slideIn {
    from { transform: translateX(110%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

/* ================================================================
   STATISTICS
   ================================================================ */
.stats-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--s-3);
    margin-bottom: var(--s-4);
}
@media (max-width: 1200px) { .stats-summary-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px)  { .stats-summary-grid { grid-template-columns: 1fr; } }

.stats-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-4) var(--s-5);
    display: flex;
    flex-direction: column;
    gap: 5px;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--t-base), transform var(--t-fast);
}
.stats-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }

.stats-card-label {
    font-size: var(--fs-2xs);
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-tertiary);
}

.stats-card-value {
    font-size: var(--fs-2xl);
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}
.stats-card-value.positive { color: var(--success); }
.stats-card-value.negative { color: var(--danger); }
.stats-card-value.neutral  { color: var(--accent); }

.stats-chart-container {
    position: relative;
    width: 100%;
    height: 320px;
}
.stats-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.stats-range-btn {
    min-width: 42px;
    text-align: center;
    justify-content: center;
    font-weight: 650;
    font-size: var(--fs-xs);
}
.stats-range-btn.active {
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}

/* ================================================================
   TRADING JOURNAL
   ================================================================ */
.journal-nav { display: flex; align-items: center; gap: var(--s-3); }

.journal-nav-label {
    font-size: var(--fs-lg);
    font-weight: 700;
    min-width: 148px;
    text-align: center;
    letter-spacing: -0.01em;
}

.journal-calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-bottom: 6px;
}

.journal-weekday {
    text-align: center;
    font-size: var(--fs-2xs);
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    padding: var(--s-2) 0;
}

.journal-calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.journal-day {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: var(--s-2) var(--s-2) var(--s-3);
    min-height: 100px;
    cursor: pointer;
    transition: background var(--t-base), border-color var(--t-base), box-shadow var(--t-base), transform var(--t-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}
.journal-day:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(79, 125, 249, 0.14);
    transform: translateY(-1px);
}

.journal-day.profit { background: rgba(34, 197, 94, 0.10);  border-color: rgba(34, 197, 94, 0.28); }
.journal-day.loss   { background: rgba(239, 68, 68, 0.10);  border-color: rgba(239, 68, 68, 0.28); }

/* Today gets a ring rather than a colour swap, so it reads on top of
   a profit/loss tint without fighting it. */
.journal-day.today,
.journal-day.profit.today,
.journal-day.loss.today {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-ring);
}

.journal-day.weekend { background: rgba(255, 255, 255, 0.015); }
.journal-day.weekend.profit { background: rgba(34, 197, 94, 0.07); }
.journal-day.weekend.loss   { background: rgba(239, 68, 68, 0.07); }

.journal-day.empty-day {
    background: transparent;
    border-color: transparent;
    cursor: default;
    min-height: 0;
}
.journal-day.empty-day:hover {
    border-color: transparent;
    box-shadow: none;
    transform: none;
}

.journal-day-number {
    font-size: var(--fs-xs);
    font-weight: 650;
    color: var(--text-tertiary);
    align-self: flex-start;
    margin-bottom: var(--s-1);
}
.journal-day.today .journal-day-number { color: var(--accent); font-weight: 700; }

.journal-day-pnl {
    font-size: var(--fs-md);
    font-weight: 700;
    text-align: center;
    margin: auto 0 2px;
    letter-spacing: -0.01em;
}
.journal-day-pnl.positive { color: var(--success); }
.journal-day-pnl.negative { color: var(--danger); }

.journal-day-winrate {
    font-size: var(--fs-2xs);
    font-weight: 500;
    color: var(--text-tertiary);
    text-align: center;
    margin-bottom: 2px;
}

.journal-day-note {
    position: absolute;
    bottom: 5px;
    right: 7px;
    font-size: var(--fs-2xs);
    color: var(--accent);
    opacity: 0.85;
}

/* Journal modal */
.journal-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--s-4);
    animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.journal-modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    padding: var(--s-6);
    width: 100%;
    max-width: 520px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}

.journal-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--s-3);
    margin-bottom: var(--s-3);
}
.journal-modal-header h3 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.02em; }

.journal-modal-pnl {
    font-size: var(--fs-2xl);
    font-weight: 700;
    margin-bottom: var(--s-4);
    letter-spacing: -0.02em;
}
.journal-modal-pnl.positive { color: var(--success); }
.journal-modal-pnl.negative { color: var(--danger); }
.journal-modal-pnl.neutral  { color: var(--text-secondary); }

.journal-modal-textarea {
    width: 100%;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: var(--s-3);
    color: var(--text-primary);
    font-size: var(--fs-md);
    font-family: inherit;
    resize: vertical;
    line-height: 1.6;
    margin-bottom: var(--s-4);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.journal-modal-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.journal-modal-actions {
    display: flex;
    gap: var(--s-2);
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ================================================================
   PROXY POOL (admin)
   ================================================================ */
.proxy-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.proxy-table thead tr { background: var(--bg-inset); }
.proxy-table th,
.proxy-table td {
    padding: 9px var(--s-3);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}
.proxy-table th {
    font-size: var(--fs-2xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    text-align: left;
}
.proxy-table td:last-child { white-space: nowrap; }
.proxy-table td:last-child .btn { margin-left: 6px; }

.proxy-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--r-xs);
    font-size: var(--fs-2xs);
    font-weight: 650;
    letter-spacing: 0.03em;
    margin-left: 6px;
    border: 1px solid transparent;
}
.proxy-badge.proxy-ok       { background: var(--success-soft); color: var(--success); border-color: rgba(34, 197, 94, 0.38); }
.proxy-badge.proxy-bad      { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(239, 68, 68, 0.38); }
.proxy-badge.proxy-untested { background: var(--warning-soft); color: var(--warning); border-color: rgba(245, 158, 11, 0.38); }
.proxy-badge.proxy-missing  { background: rgba(239, 68, 68, 0.2); color: var(--danger); border-color: var(--danger); font-weight: 700; }

/* ================================================================
   LOGIN / AUTH CARD
   ================================================================ */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: var(--s-5);
    position: relative;
    z-index: 1;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--s-10) var(--s-8);
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    font-size: var(--fs-3xl);
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: var(--s-2);
}

.login-card p {
    color: var(--text-secondary);
    font-size: var(--fs-md);
    margin-bottom: var(--s-8);
}

/* ================================================================
   SCROLLBARS
   ================================================================ */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--r-full);
    border: 2px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); background-clip: content-box; }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .mobile-header { display: flex; }
    .main-content { margin-left: 0; padding-top: var(--topbar-height); }
    .topbar { top: var(--topbar-height); }
    .page-section { padding: var(--s-5) var(--s-5) var(--s-10); }
    .topbar { padding: 0 var(--s-5); }
}

@media (max-width: 768px) {
    .page-section { padding: var(--s-4) var(--s-4) var(--s-8); }
    .topbar { padding: 0 var(--s-4); }
    .card { padding: var(--s-4); border-radius: var(--r-md); }
    .card-header-row { flex-direction: column; align-items: flex-start; }

    .inline-form { width: 100%; }
    .inline-form input,
    .inline-form select { flex: 1; min-width: 0; }

    .position-row { flex-direction: column; gap: var(--s-2); align-items: flex-start; }
    .position-info { flex-direction: column; gap: var(--s-1); align-items: flex-start; }
    .position-pnl { text-align: left; }
    .btn-close-pos { margin-left: 0; }

    .balance-display { flex-direction: column; }
    .balance-item { min-width: auto; }

    .grid-2 { grid-template-columns: 1fr; }
    .group-form { flex-direction: column; align-items: stretch; }

    .journal-day { min-height: 72px; padding: 5px 4px 7px; }
    .journal-day-pnl { font-size: var(--fs-xs); }
    .journal-day-winrate { font-size: 0.6rem; }
    .journal-day-number { font-size: 0.65rem; }
    .journal-day-note { font-size: 0.6rem; bottom: 3px; right: 4px; }
    .journal-nav-label { font-size: var(--fs-md); min-width: 112px; }
    .journal-modal-card { padding: var(--s-5); }

    .toast { left: var(--s-4); right: var(--s-4); bottom: var(--s-4); }
}
