:root {
    color-scheme: dark;
    --bg: #080c12;
    --surface: #111821;
    --surface-2: #17212d;
    --border: #273545;
    --text: #f3f7fb;
    --muted: #91a2b4;
    --green: #21c77a;
    --red: #ff6470;
    --orange: #f5a623;
    --blue: #4da3ff;
    --radius: 16px;
    --shadow: 0 12px 32px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 50% -20%, #172c42 0, var(--bg) 42%);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button, .button, input, select, summary { min-height: 44px; }
button, .button {
    border: 0;
    border-radius: 12px;
    padding: 10px 15px;
    background: var(--surface-2);
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}
button:hover, .button:hover { filter: brightness(1.12); }
button:focus-visible, input:focus-visible, summary:focus-visible, .button:focus-visible {
    outline: 3px solid rgba(77, 163, 255, .45);
    outline-offset: 2px;
}
button:disabled { opacity: .55; cursor: wait; }
.button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.primary { background: var(--blue); color: #04111f; }
.success { background: var(--green); color: #04170e; }
.danger { background: var(--red); color: #250306; }
.warning { background: var(--orange); color: #221300; }
.ghost { background: transparent; border: 1px solid var(--border); }
.small { min-height: 38px; padding: 7px 11px; font-size: 13px; }

input, select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    background: #0d141d;
    color: var(--text);
    font-size: 16px;
}
label { display: block; color: var(--muted); font-size: 13px; font-weight: 650; }
label > input { margin-top: 6px; }
.field-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid .wide { grid-column: 1 / -1; }

.shell { width: min(1160px, 100%); margin: 0 auto; padding: 18px 18px 98px; }
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.app-header h1 { margin: 0; font-size: clamp(21px, 4vw, 28px); letter-spacing: -.02em; }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.subtle { color: var(--muted); }
.card {
    border: 1px solid var(--border);
    background: rgba(17, 24, 33, .94);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.card + .card, .section + .section { margin-top: 14px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; }
.section-title h2, .section-title h3 { margin: 0; font-size: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--border); background: #0d141d; border-radius: 13px; padding: 12px; min-width: 0; }
.stat-label { display: block; color: var(--muted); font-size: 12px; }
.stat-value { display: block; margin-top: 3px; font-size: clamp(17px, 3vw, 22px); font-weight: 800; overflow-wrap: anywhere; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.account-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.account-card { min-width: 0; }
.account-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.account-head h3 { margin: 0; overflow-wrap: anywhere; }
.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric { background: #0d141d; border-radius: 10px; padding: 9px; min-width: 0; }
.metric span { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin-top: 2px; overflow-wrap: anywhere; }
.list { display: grid; gap: 7px; margin-top: 10px; }
.list-item { background: #0d141d; border-radius: 10px; padding: 9px 10px; overflow-wrap: anywhere; }
details { margin-top: 10px; border-top: 1px solid var(--border); }
summary { display: flex; align-items: center; cursor: pointer; padding-top: 10px; color: #cdd8e4; }
.error-box { border-color: rgba(255, 100, 112, .55); }
.error-text { color: #ff9aa2; overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 26px 12px; }
.status-pill { display: inline-flex; min-height: 26px; align-items: center; border-radius: 999px; padding: 3px 8px; background: #263443; color: #dbe7f4; font-size: 11px; font-weight: 800; }
.status-pill.ok { background: rgba(33, 199, 122, .16); color: #67e3a9; }

.bottom-nav {
    position: fixed;
    z-index: 50;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 9px max(12px, env(safe-area-inset-right)) calc(9px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    border-top: 1px solid var(--border);
    background: rgba(8, 12, 18, .94);
    backdrop-filter: blur(16px);
}
.bottom-nav .button { width: min(220px, 40vw); }
.bottom-nav .active { background: var(--blue); color: #04111f; }

dialog {
    width: min(480px, calc(100vw - 24px));
    max-height: calc(100vh - 32px);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 0;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .75); backdrop-filter: blur(3px); }
.dialog-body { padding: 18px; overflow: auto; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.dialog-actions > * { flex: 1; }

.toast-region { position: fixed; z-index: 100; top: 12px; left: 50%; width: min(420px, calc(100% - 24px)); transform: translateX(-50%); }
.toast { margin-bottom: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; background: #182330; box-shadow: var(--shadow); }
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }
.busy { position: relative; }
.busy::after { content: ""; display: inline-block; width: 13px; height: 13px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-page { display: grid; place-items: center; padding: 18px; }
.login-card { width: min(410px, 100%); padding: 24px; }
.login-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 15px; background: rgba(77, 163, 255, .18); color: var(--blue); font-size: 25px; }
.login-card h1 { margin: 16px 0 4px; font-size: 25px; }
.login-card form { margin-top: 22px; }
.code-input { text-align: center; letter-spacing: .28em; font-size: 23px; font-weight: 750; }
.full { width: 100%; }
.form-message { min-height: 24px; margin-top: 10px; color: var(--muted); text-align: center; }

.trade-shell { padding-bottom: 178px; }
.symbol-row { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(120px, .7fr); gap: 10px; }
.account-select { display: flex; align-items: flex-start; gap: 11px; cursor: pointer; }
.account-select input { width: 22px; min-height: 22px; margin: 2px 0 0; accent-color: var(--blue); flex: 0 0 auto; }
.account-select-main { flex: 1; min-width: 0; }
.trade-dock {
    position: fixed;
    z-index: 45;
    left: 0;
    right: 0;
    bottom: calc(63px + env(safe-area-inset-bottom));
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: rgba(13, 20, 29, .97);
}
.trade-dock-inner { width: min(900px, 100%); margin: auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.trade-dock button { padding: 8px 5px; font-size: 13px; }
.trade-dock small { display: block; font-size: 10px; opacity: .75; }
.percent-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin: 12px 0; }
.percent-options button.selected { background: var(--blue); color: #04111f; }
.range-row { display: flex; gap: 12px; align-items: center; }
.range-row input { padding: 0; }
.range-value { min-width: 48px; font-weight: 800; text-align: right; }
.confirm-summary { display: grid; gap: 7px; border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: #0d141d; }
.confirm-summary div { display: flex; justify-content: space-between; gap: 12px; }
.log-button { position: fixed; z-index: 44; right: 14px; bottom: calc(170px + env(safe-area-inset-bottom)); border-radius: 999px; width: 48px; padding: 0; box-shadow: var(--shadow); }
.log-list { height: min(55vh, 500px); overflow: auto; display: grid; align-content: start; gap: 6px; margin-top: 10px; }
.log-line { border-left: 3px solid var(--border); background: #0d141d; padding: 8px 10px; border-radius: 6px; font-size: 12px; overflow-wrap: anywhere; }
.log-line.error { border-color: var(--red); }
.log-line.success { border-color: var(--green); }
.log-line.warn { border-color: var(--orange); }

@media (max-width: 720px) {
    .shell { padding: 12px 12px 94px; }
    .trade-shell { padding-bottom: 174px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .account-grid { grid-template-columns: 1fr; }
    .field-grid, .symbol-row { grid-template-columns: 1fr; }
    .metric-row { gap: 6px; }
    .metric { padding: 8px 7px; }
    .app-header { align-items: flex-start; }
    .desktop-label { display: none; }
    .small { min-height: 44px; }
}

@media (max-width: 390px) {
    .card { padding: 13px; }
    .trade-dock { padding-inline: 6px; }
    .trade-dock-inner { gap: 4px; }
    .trade-dock button { font-size: 12px; }
}
