:root {
    color-scheme: dark;
    --bg: #0b0815;
    --panel: #151027;
    --panel-2: #1d1633;
    --border: #33274f;
    --text: #f7f3ff;
    --muted: #a99fba;
    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --yes: #22c55e;
    --no: #ef4444;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: 'Inter', system-ui, sans-serif;
}

button,
input { font: inherit; }

button,
.topbar a {
    border: 1px solid #6d4fd1;
    border-radius: 7px;
    color: #ffffff;
    background: #6d4fd1;
    cursor: pointer;
}

button:hover,
.topbar a:hover { background: var(--accent-hover); }

.topbar {
    height: 58px;
    padding: 0 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: #100c1e;
}

.topbar h1 { margin: 0; font-size: 22px; }
.topbar a { padding: 7px 12px; text-decoration: none; font-size: 13px; }

.page { padding: 18px; }

.watch-form,
.flow-card {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.watch-form { padding: 14px; margin-bottom: 14px; }
.watch-form > label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.watch-row { display: grid; grid-template-columns: minmax(220px, 1fr) 110px; gap: 8px; }

input {
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    outline: none;
    color: var(--text);
    background: #0f0b1c;
}

input:focus { border-color: var(--accent); }
.watch-row button { padding: 9px 14px; font-weight: 700; }
.error { min-height: 18px; margin: 6px 0 0; color: #fb7185; font-size: 13px; }

.flow-card { overflow: hidden; }
.flow-head { min-height: 66px; padding: 12px 15px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.flow-head h2 { margin: 0 0 4px; font-size: 18px; }
.flow-head p { margin: 0; color: var(--muted); font-size: 12px; }
.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #64748b; }
.status-dot.connected { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.status-dot.error { background: #ef4444; }

.controls {
    min-height: 48px;
    padding: 8px 15px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
}

.controls label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.controls input[type='number'] { width: 88px; }
.controls input[type='date'] { width: 145px; }
.controls input { padding: 6px 7px; }
.controls button { margin-left: auto; padding: 6px 10px; }
#trade-count { color: var(--muted); font-size: 12px; }

.chart-shell {
    position: relative;
    width: 100%;
    height: 680px;
    overflow: hidden;
    background: #0f0a1e;
}

#flow-canvas { display: block; width: 100%; height: 680px; cursor: default; }

.trade-tooltip {
    position: absolute;
    z-index: 5;
    max-width: 360px;
    padding: 9px 11px;
    border: 1px solid #7255a8;
    border-radius: 7px;
    color: #ffffff;
    background: #100b1ee8;
    box-shadow: 0 6px 24px #00000080;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-line;
}
.trade-tooltip a { color: #9f86ff; }

.legend { margin: 0; padding: 9px 15px; display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 12px; }
.yes-key { color: var(--yes); }
.no-key { color: var(--no); }

.login-page { display: grid; place-items: center; padding: 20px; }
.login-card { width: 330px; padding: 26px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); box-shadow: 0 12px 40px #00000066; }
.login-card h1 { margin: 0 0 22px; text-align: center; color: var(--accent-hover); }
.login-card label { display: block; margin-bottom: 13px; color: var(--muted); font-size: 13px; }
.login-card input { width: 100%; margin-top: 6px; }
.login-card button { width: 100%; padding: 10px; font-weight: 700; }
.login-error { margin: 12px 0 0; color: #fb7185; text-align: center; font-size: 13px; }

@media (max-width: 720px) {
    .page { padding: 8px; }
    .watch-row { grid-template-columns: 1fr; }
    .flow-head { align-items: flex-start; flex-direction: column; }
    .controls { align-items: flex-start; flex-wrap: wrap; }
    .controls button { margin-left: 0; }
    .chart-shell,
    #flow-canvas { height: 560px; }
}
