/* Trading System Dashboard — Mobile-First */

:root {
    --bg: #0f1419;
    --bg-card: #1a2332;
    --bg-raised: #1e2d3d;
    --border: #2d3f50;
    --text: #e1e8ed;
    --text-dim: #8899a6;
    --text-muted: #657786;
    --green: #17bf63;
    --red: #e0245e;
    --yellow: #ffad1f;
    --blue: #1da1f2;
    --radius: 10px;
    --nav-height: 60px;
    --topbar-height: 48px;
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    min-height: 100vh;
    padding-top: var(--topbar-height);
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

/* ── Top Bar ────────────────────────────────── */

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-name {
    font-weight: 700;
    font-size: 16px;
}

.mode-pill {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    border-radius: 10px;
}

.mode-pill.dry { background: var(--yellow); color: #000; }
.mode-pill.live { background: var(--green); color: #000; }

.service-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.service-dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.service-dot.off { background: var(--red); box-shadow: 0 0 6px var(--red); }

.topbar-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
}

/* ── Bottom Navigation ──────────────────────── */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 11px;
    padding: 6px 12px;
    border-radius: 8px;
    min-width: 60px;
    transition: color 0.15s;
}

.nav-item.active { color: var(--blue); }
.nav-item:active { opacity: 0.7; }

.nav-icon {
    width: 22px;
    height: 22px;
}

/* ── Main Content ───────────────────────────── */

.main {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
}

/* ── Emergency Controls ─────────────────────── */

.controls-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.control-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.control-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.switch-btn {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 700;
    border: 2px solid;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.switch-btn.on {
    background: rgba(23, 191, 99, 0.15);
    border-color: var(--green);
    color: var(--green);
}

.switch-btn.off {
    background: rgba(224, 36, 94, 0.15);
    border-color: var(--red);
    color: var(--red);
}

.switch-btn.live {
    background: rgba(23, 191, 99, 0.15);
    border-color: var(--green);
    color: var(--green);
}

.switch-btn.dry {
    background: rgba(255, 173, 31, 0.15);
    border-color: var(--yellow);
    color: var(--yellow);
}

.switch-btn:active { transform: scale(0.97); }
.switch-btn:disabled { opacity: 0.5; cursor: wait; }

/* ── Status Grid ────────────────────────────── */

.status-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
}

/* ── Cards ──────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 12px;
}

.card-link {
    font-size: 12px;
    color: var(--blue);
    text-decoration: none;
    text-transform: none;
    font-weight: 400;
}

/* ── Market Card ────────────────────────────── */

.market-card { border-left: 4px solid var(--border); }
.market-card.confirmed_uptrend { border-left-color: var(--green); }
.market-card.uptrend_under_pressure { border-left-color: var(--yellow); }
.market-card.rally_attempt { border-left-color: var(--yellow); }
.market-card.downtrend { border-left-color: var(--red); }

.market-state {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 6px;
}

.market-meta {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.6;
}

/* ── Mini Grid (for stats rows) ─────────────── */

.mini-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    text-align: center;
}

.mini-stat { display: flex; flex-direction: column; gap: 2px; }
.mini-value { font-size: 18px; font-weight: 700; }
.mini-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }

.equity-line {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-dim);
    text-align: center;
}

/* ── Position Rows ──────────────────────────── */

.position-row {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.position-row:last-child { border-bottom: none; }

.pos-ticker {
    font-weight: 700;
    color: var(--blue);
    width: 60px;
    font-size: 14px;
}

.pos-details {
    flex: 1;
    font-size: 12px;
    color: var(--text-dim);
}

.pos-value {
    font-size: 13px;
    font-weight: 600;
    text-align: right;
}

/* ── Colors ─────────────────────────────────── */

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-blue { color: var(--blue); }

/* ── Refresh Note ───────────────────────────── */

.refresh-note {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 16px;
    padding-bottom: 8px;
}

/* ── Tables (watchlist, trades) ─────────────── */

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 0 14px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.data-table th {
    text-align: left;
    padding: 8px 10px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.data-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr:active { background: var(--bg-raised); }
.data-table .ticker { font-weight: 700; color: var(--blue); }

.winner-row td:first-child { border-left: 3px solid var(--green); }
.loser-row td:first-child { border-left: 3px solid var(--red); }

/* ── Tabs (watchlist filter) ────────────────── */

.tab-bar {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    margin-bottom: 14px;
}

.tab {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    text-decoration: none;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}

.tab:active { opacity: 0.7; }
.tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ── Logs ───────────────────────────────────── */

.log-filters {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.log-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.log-output {
    padding: 12px;
    font-family: 'SF Mono', 'Menlo', 'Fira Code', monospace;
    font-size: 11px;
    line-height: 1.7;
    max-height: 65vh;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-dim);
    -webkit-overflow-scrolling: touch;
}

/* ── Page Headers ───────────────────────────── */

.page-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 14px;
}

.result-count {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ── Empty State ────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ── Buttons (filter pills) ─────────────────── */

.btn-pill {
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-raised);
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-pill:active { opacity: 0.7; }
.btn-pill.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-pill.danger { background: rgba(224, 36, 94, 0.15); color: var(--red); border-color: var(--red); }

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

.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.login-box h1 { font-size: 20px; margin-bottom: 6px; }

.login-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 16px; /* prevents iOS zoom */
    margin-bottom: 14px;
}

.login-input:focus { outline: none; border-color: var(--blue); }

.login-btn {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius);
    border: none;
    background: var(--blue);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.login-btn:active { opacity: 0.85; }

.alert-error {
    background: rgba(224, 36, 94, 0.12);
    color: var(--red);
    border: 1px solid var(--red);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* ── Desktop enhancement (>600px) ───────────── */

@media (min-width: 601px) {
    .main {
        max-width: 700px;
        padding: 24px;
    }

    .status-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .bottom-nav {
        max-width: 500px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 16px 16px 0 0;
    }
}
