/* ═══════════════════════════════════════════════════════
   Tradesfera Control — Mobile Trading Terminal
   ═══════════════════════════════════════════════════════ */

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

:root {
    --bg: #0a0c10;
    --bg-elevated: #111318;
    --surface: #161922;
    --surface-hover: #1c2030;
    --border: #1e2230;
    --border-light: #282d3e;

    --text: #e8eaed;
    --text-secondary: #8b8fa3;
    --text-tertiary: #555a6e;

    --profit: #00d68f;
    --profit-dim: rgba(0, 214, 143, 0.12);
    --loss: #ff4757;
    --loss-dim: rgba(255, 71, 87, 0.12);
    --accent: #6c5ce7;
    --accent-dim: rgba(108, 92, 231, 0.15);
    --warning: #ffa502;

    --font-ui: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

    --radius: 14px;
    --radius-sm: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

.mono { font-family: var(--font-mono); }
.screen { min-height: 100vh; min-height: 100dvh; }
.hidden { display: none !important; }

/* ── Login ───────────────────────────────────────────── */

#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(108, 92, 231, 0.08) 0%, transparent 60%),
        var(--bg);
}

.login-card {
    width: 88%;
    max-width: 380px;
    padding: 2.5rem 2rem;
    text-align: center;
}

.login-logo {
    width: 56px;
    height: 56px;
    margin: 0 auto 1.25rem;
    background: var(--accent);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.5rem;
    color: white;
    box-shadow: 0 8px 32px rgba(108, 92, 231, 0.3);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--text-tertiary);
    font-size: 0.875rem;
    margin-bottom: 2rem;
}

.login-fields {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    margin-bottom: 1rem;
}

.login-fields input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color 0.2s;
}

.login-fields input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.login-fields input::placeholder { color: var(--text-tertiary); }

.error-msg {
    color: var(--loss);
    font-size: 0.8125rem;
    margin-top: 0.75rem;
    min-height: 1.25rem;
}

/* ── Buttons ─────────────────────────────────────────── */

.btn-primary {
    width: 100%;
    padding: 0.875rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-family: var(--font-ui);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:active { transform: scale(0.98); opacity: 0.9; }
.btn-sm { padding: 0.625rem 1.25rem; font-size: 0.8125rem; }

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { background: var(--surface); color: var(--text); }

/* ── Top bar ─────────────────────────────────────────── */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    padding-top: calc(0.625rem + var(--safe-top));
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 0.625rem; }

.topbar-logo {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.875rem;
    color: white;
}

.topbar-title {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--profit);
    box-shadow: 0 0 6px var(--profit);
}

.status-dot.offline {
    background: var(--loss);
    box-shadow: 0 0 6px var(--loss);
    animation: pulse-offline 2s infinite;
}

@keyframes pulse-offline {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.topbar-right { display: flex; gap: 0.25rem; }

/* ── Portfolio summary ───────────────────────────────── */

.summary {
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}

.summary-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.summary-label {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

.summary-value {
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.summary-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
}

/* ── Flatten bar ─────────────────────────────────────── */

.flatten-bar {
    padding: 0.75rem 1rem;
    background: var(--bg);
}

.btn-flatten-all {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--loss);
    border-radius: var(--radius-sm);
    background: var(--loss-dim);
    color: var(--loss);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-flatten-all:active {
    background: var(--loss);
    color: white;
}

/* ── Settings drawer ─────────────────────────────────── */

.drawer {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    animation: slideDown 0.25s ease;
}

@keyframes slideDown {
    from { max-height: 0; opacity: 0; }
    to { max-height: 300px; opacity: 1; }
}

.drawer-content { padding: 1.25rem 1rem; }

.drawer-title {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 1rem;
}

.drawer-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.875rem;
}

.drawer-field label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.stepper {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.stepper-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--surface);
    color: var(--text);
    font-size: 1.125rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.stepper-btn:active { background: var(--surface-hover); }

.stepper input {
    width: 44px;
    height: 36px;
    border: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}

.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

.save-status {
    font-size: 0.75rem;
    color: var(--profit);
    margin-left: 0.75rem;
    font-weight: 500;
}

/* ── Accounts ────────────────────────────────────────── */

main { padding: 0.75rem 1rem; padding-bottom: calc(1.5rem + var(--safe-bottom)); }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

.empty-icon { margin-bottom: 1rem; }

/* ── Firm group ──────────────────────────────────────── */

.firm-group { margin-bottom: 1.25rem; }

.firm-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0 0.25rem;
}

.firm-badge {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 0.1875rem 0.5rem;
    border-radius: 5px;
}

.firm-count {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
}

/* ── Account card ────────────────────────────────────── */

.account-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    transition: border-color 0.2s;
}

.account-card.has-position { border-left: 3px solid var(--warning); }

.card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.card-identity { display: flex; flex-direction: column; gap: 0.125rem; flex: 1; min-width: 0; }

.account-name {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-balance {
    font-family: var(--font-mono);
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.card-pnl {
    text-align: right;
    flex-shrink: 0;
    margin-left: 0.75rem;
}

.pnl-label {
    font-size: 0.625rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.pnl-value {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
}

.pnl-value.positive { color: var(--profit); }
.pnl-value.negative { color: var(--loss); }
.pnl-value.zero { color: var(--text-tertiary); }

/* Position row */
.card-position {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.625rem;
    margin: 0.375rem 0;
    background: var(--bg);
    border-radius: 8px;
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

.pos-direction {
    font-weight: 700;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    letter-spacing: 0.02em;
}

.pos-direction.long { color: var(--profit); background: var(--profit-dim); }
.pos-direction.short { color: var(--loss); background: var(--loss-dim); }

.pos-detail { color: var(--text-secondary); }

.pos-pnl { font-weight: 600; }
.pos-pnl.positive { color: var(--profit); }
.pos-pnl.negative { color: var(--loss); }

.card-flat {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    padding: 0.25rem 0;
}

/* Flatten button */
.card-actions { margin-top: 0.5rem; }

.btn-flatten {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-flatten:active {
    background: var(--loss-dim);
    border-color: var(--loss);
    color: var(--loss);
}

/* ── Animations ──────────────────────────────────────── */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.first-load .account-card {
    animation: fadeIn 0.3s ease both;
}

.first-load .firm-group:nth-child(1) .account-card:nth-child(2) { animation-delay: 0.03s; }
.first-load .firm-group:nth-child(1) .account-card:nth-child(3) { animation-delay: 0.06s; }
.first-load .firm-group:nth-child(1) .account-card:nth-child(4) { animation-delay: 0.09s; }
.first-load .firm-group:nth-child(2) .account-card { animation-delay: 0.05s; }

/* ── Pulse on update ─────────────────────────────────── */

.pnl-flash {
    animation: flash 0.6s ease;
}

@keyframes flash {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}
