:root {
    --bg: #0a0e15;
    --panel: #131a25;
    --panel-2: #1b2433;
    --line: #2b3648;
    --text: #eef2f8;
    --muted: #a3b1c4;
    --accent: #4c9dff;
    --accent-ink: #06121f;
    --good: #3ddc84;
    --warn: #f0b429;
    --bad: #ff6b63;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 16px 20px 32px;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

h1 { margin: 0; font-size: 18px; font-weight: 600; }
code { font-family: Consolas, monospace; }
.muted { color: var(--muted); font-size: 12px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.top-right { display: flex; align-items: center; gap: 12px; }
.top-right form { margin: 0; }

.pill { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-ok { color: var(--good); background: rgba(63, 185, 80, .14); }
.pill-bad { color: var(--bad); background: rgba(248, 81, 73, .14); }

.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.link:hover { text-decoration: underline; }

.notice {
    margin: 14px 0;
    padding: 10px 12px;
    background: rgba(210, 153, 34, .1);
    border: 1px solid rgba(210, 153, 34, .4);
    border-radius: 6px;
}

.exchanges { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.ex { padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.ex-down { border-color: var(--bad); }
.ex-degraded { border-color: var(--warn); }
.ex-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2px; }
.dot { font-size: 12px; font-weight: 600; }
.dot-ok { color: var(--good); }
.dot-degraded, .dot-starting { color: var(--warn); }
.dot-down { color: var(--bad); }

.ref-ok, .ref-warn, .ref-bad { font-size: 12px; }
.ref-ok { color: var(--good); }
.ref-warn { color: var(--warn); }
.ref-bad { color: var(--bad); }

.funnel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}
.step { display: flex; flex-direction: column; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.step-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.step-good { border-color: var(--good); }
.step-good .step-value { color: var(--good); }

.reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.reasons[hidden] { display: none; }
.chip { padding: 2px 10px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }

.paper { margin-top: 10px; }
.paper-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px; border-radius: 6px; border: 1px solid var(--line); }
.paper-running { background: rgba(63, 185, 80, .1); border-color: rgba(63, 185, 80, .4); }
.paper-stopped { background: rgba(248, 81, 73, .12); border-color: var(--bad); }
.paper-sizing { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.btn-small { padding: 4px 12px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font: inherit; }
.btn-small:hover { border-color: var(--accent); }
.btn-small[hidden] { display: none; }
.section-title { margin: 18px 0 6px; font-size: 14px; font-weight: 600; }
.paper .table-wrap { margin-top: 0; }

.live-on { background: rgba(248, 81, 73, .08); border-color: rgba(248, 81, 73, .5); }
.btn-trade { padding: 3px 12px; color: #fff; background: #238636; border: 0; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 600; }
.btn-trade:hover { background: #2ea043; }
.btn-danger { padding: 6px 14px; color: #fff; background: #b62324; border: 0; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 600; }
.btn-danger:hover { background: #da3633; }
.btn-danger:disabled { opacity: .5; cursor: wait; }
.btn-danger[hidden], [data-tab][hidden] { display: none; }
.trade-dialog { width: min(520px, calc(100% - 32px)); color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.trade-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.trade-dialog h2 { margin: 0 0 10px; font-size: 16px; }
.trade-line { display: flex; justify-content: space-between; gap: 12px; margin: 5px 0; font-variant-numeric: tabular-nums; }
.trade-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.tuning { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin: 12px 0 0; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.tuning label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
.tuning input { width: 130px; }

.note-cell { min-width: 220px; max-width: 340px; white-space: normal; overflow-wrap: anywhere; font-size: 12px; }

.ex-name { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.ex-name input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.ex-off { opacity: .55; border-style: dashed; }
.dot-off { color: var(--muted); }

.auto-panel { margin: 12px 0; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.auto-panel[hidden] { display: none; }
.auto-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.auto-state { color: var(--muted); font-weight: 600; }
.auto-state.auto-on { color: var(--good); }
.auto-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.auto-controls label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; }
.auto-controls input { width: 140px; }
.btn-run { padding: 7px 22px; color: #fff; background: #238636; border: 0; border-radius: 7px; cursor: pointer; font: inherit; font-weight: 700; }
.btn-run:hover { background: #2ea043; }
.btn-run:disabled, .btn-danger:disabled { opacity: .45; cursor: not-allowed; }
td.nowrap { white-space: nowrap; }
.btn-bl { margin-left: 6px; padding: 2px 6px; background: transparent; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font: inherit; line-height: 1.2; }
.btn-bl:hover { border-color: var(--bad); }
.bl-actions { flex-wrap: wrap; }
.flow-steps { margin-top: 4px; }
.flow-steps summary { cursor: pointer; color: var(--muted); }
.flow-steps ol { margin: 4px 0 0; padding-left: 18px; font-size: 12px; line-height: 1.55; word-break: break-all; }
.auto-banned { margin: 8px 0 0; color: var(--bad); font-size: 12.5px; line-height: 1.6; }
.auto-events { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }

.expandable { cursor: pointer; }
.detail td { background: var(--panel-2); white-space: normal; }
.breakdown { display: grid; grid-template-columns: max-content 1fr; gap: 3px 16px; margin: 0; font-size: 13px; }
.breakdown dt { color: var(--muted); }
.breakdown dd { margin: 0; font-variant-numeric: tabular-nums; }
.net-good { color: var(--good); font-weight: 600; }
.net-bad { color: var(--bad); }
.warn { color: var(--warn); }

.controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 14px 0 8px; flex-wrap: wrap; }
.stats { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.search { display: flex; align-items: center; gap: 8px; color: var(--muted); }

input {
    padding: 6px 10px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab {
    padding: 8px 12px;
    color: var(--muted);
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.suspect-note { margin: 8px 0 0; color: var(--warn); font-size: 13px; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 600; background: var(--panel-2); }
tbody tr:hover { background: var(--panel-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sym { font-weight: 600; }
.buy { color: var(--good); }
.sell { color: var(--bad); }
.net { font-weight: 600; }
.empty { padding: 24px; margin: 0; color: var(--muted); text-align: center; background: var(--panel); }

.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(340px, 100%);
    padding: 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}
.login-box h1 { margin-bottom: 10px; }
.hint { margin: 0 0 6px; color: var(--muted); font-size: 12px; }
.login-error { margin: 0 0 6px; color: var(--bad); font-size: 13px; }
.login-box button {
    padding: 8px;
    color: #fff;
    background: #238636;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
}
.login-box button:hover { background: #2ea043; }


/* Design layer */
body { padding: 18px 24px 40px; font-size: 14px; }
h1 { font-size: 21px; font-weight: 700; letter-spacing: .2px; }
.top { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.muted { color: var(--muted); }
.section-title { margin: 22px 0 8px; font-size: 15px; font-weight: 700; }

.notice { padding: 12px 14px; border-radius: var(--radius); line-height: 1.5; }

.ex, .step, .tuning { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.ex { padding: 10px 12px; }
.ex-head strong, .ex-head { font-weight: 600; }
.step { padding: 12px 14px; }
.step-value { font-size: 22px; font-weight: 700; line-height: 1.25; }
.step .muted { margin-top: 2px; }
.step-good { border-color: var(--good); background: rgba(61, 220, 132, .07); }
.tuning { padding: 12px 14px; gap: 14px; }
.tuning label { color: var(--text); font-weight: 600; }

input { background: var(--panel-2); border-radius: 7px; padding: 7px 10px; }
input:focus { border-color: var(--accent); outline: none; }

.btn-small { padding: 6px 14px; background: var(--panel-2); border-radius: 7px; font-weight: 600; }
.btn-small:hover { background: #243044; }
.btn-trade { padding: 4px 16px; border-radius: 7px; }

.tabs {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.tab {
    padding: 9px 16px;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 600;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.tab:hover { color: #fff; background: #26344a; border-color: var(--accent); }
.tab.active, .tab.active:hover { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 700; }
.tab[data-tab="live"] { border-color: rgba(255, 107, 99, .65); }
.tab[data-tab="live"].active, .tab[data-tab="live"].active:hover { color: #fff; background: #d6413a; border-color: #d6413a; }
.tab[data-tab="balances"].active, .tab[data-tab="balances"].active:hover { color: #06121f; background: var(--good); border-color: var(--good); }

.table-wrap { margin-top: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { background: transparent; }
th {
    position: sticky;
    top: 0;
    color: var(--text);
    background: var(--panel-2);
    font-size: 12.5px;
    font-weight: 700;
    border-bottom: 2px solid var(--line);
}
td { border-bottom: 1px solid rgba(43, 54, 72, .7); }
tbody tr:nth-child(even) { background: rgba(255, 255, 255, .018); }
tbody tr:hover { background: rgba(76, 157, 255, .1); }
tbody tr:last-child td { border-bottom: 0; }
.empty { background: transparent; }

.paper-banner { padding: 10px 14px; border-radius: var(--radius); }
.chip { color: var(--text); background: var(--panel-2); }
.net-good { color: var(--good); }
.trade-dialog { padding: 18px; border-radius: var(--radius); }

@media (max-width: 720px) {
    body { padding: 12px 12px 28px; }
    .tab { padding: 8px 11px; font-size: 13px; }
    .tuning input { width: 100%; }
    .tuning label { flex: 1 1 42%; }
}
