:root {
    --bg: #0e1117;
    --bg-2: #161b22;
    --bg-3: #1f2630;
    --line: #2d333b;
    --fg: #e6edf3;
    --fg-dim: #9ba3ad;
    --accent: #2f81f7;
    --bid: #2ea043;
    --ask: #f85149;
    --bid-bg: rgba(46,160,67,0.18);
    --ask-bg: rgba(248,81,73,0.18);
    --ok: #2ea043;
    --warn: #d29922;
    --err: #f85149;
}

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: ui-sans-serif, -apple-system, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
    font-size: 13px;
}

.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.muted { color: var(--fg-dim); }
.error { color: var(--err); margin-top: 6px; min-height: 14px; }

button { cursor: pointer; }
input, select, button {
    background: var(--bg-3);
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 13px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.btn { background: var(--bg-3); border: 1px solid var(--line); padding: 5px 10px; }
.btn:hover { background: #2a313a; }
.btn:disabled, button:disabled, select:disabled {
    cursor: wait;
    opacity: 0.55;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 12px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--line);
    height: 44px;
    box-sizing: border-box;
}
.brand { font-weight: 600; font-size: 14px; }
.status-line { display: flex; gap: 8px; }
.badge {
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
}
.badge.ok    { color: var(--ok);   border-color: var(--ok); }
.badge.down  { color: var(--err);  border-color: var(--err); }
.badge.maint { color: var(--warn); border-color: var(--warn); }
.topbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.layout {
    display: grid;
    grid-template-columns: 320px 1fr 360px;
    gap: 8px;
    padding: 8px;
    height: calc(100vh - 44px);
    box-sizing: border-box;
    overflow: hidden;
}
.col { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow: auto; }
.col-mid { overflow: hidden; }

.card {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
}
.card h3 { margin: 0 0 8px 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-dim); }

.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.kv { display: flex; justify-content: space-between; padding: 2px 0; }
.kv span { color: var(--fg-dim); font-size: 11px; text-transform: uppercase; }
.kv b { font-family: ui-monospace, monospace; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; font-family: ui-monospace, monospace; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--fg-dim); font-weight: 500; font-size: 10px; text-transform: uppercase; }
.table-compact td { padding: 2px 6px; font-size: 12px; }
.pl-pos { color: var(--ok); }
.pl-neg { color: var(--err); }

.symbol-strip {
    display: flex; align-items: center; gap: 12px; padding: 4px 0 4px 4px;
}
.symbol-strip label { display: flex; gap: 6px; align-items: center; }

.chart-card { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chart-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.indicator-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--fg-dim);
    font-size: 11px;
}
.indicator-controls label {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.indicator-controls input { margin: 0; }
.chart-pane { flex: 1; min-height: 200px; position: relative; }
.chart-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(22, 27, 34, 0.72);
    color: var(--fg-dim);
    font-family: ui-monospace, monospace;
    z-index: 2;
    pointer-events: none;
}
.chart-loading[hidden] { display: none; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--fg-dim); }
.span-2 { grid-column: span 2; }
.ck { display: flex !important; flex-direction: row !important; gap: 6px; align-items: center; }

.seg { display: flex; gap: 0; }
.seg-btn {
    flex: 1; border: 1px solid var(--line); background: var(--bg-3);
    color: var(--fg); padding: 5px 8px;
}
.seg-btn:first-child { border-radius: 4px 0 0 4px; border-right: 0; }
.seg-btn:last-child  { border-radius: 0 4px 4px 0; }
.seg-btn.active.bid { background: var(--bid); border-color: var(--bid); color: #fff; }
.seg-btn.active.ask { background: var(--ask); border-color: var(--ask); color: #fff; }
.seg-btn.active     { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Ladder ---- */
.dom-windows { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.dom-card { padding: 8px; }
.dom-card.active { border-color: var(--accent); }
.ladder-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.ladder-header h3 { margin-right: 2px; }
.ladder-symbol {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dom-close {
    margin-left: auto;
    width: 22px;
    height: 22px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
}
.ladder { font-family: ui-monospace, monospace; font-size: 12px; user-select: none; }
.lad-row {
    display: grid;
    grid-template-columns: 56px minmax(34px, 1fr) 76px minmax(34px, 1fr) 56px;
    gap: 0;
    align-items: stretch;
    height: 22px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    position: relative;
    cursor: pointer;
}
.lad-row > div { display: flex; align-items: center; justify-content: flex-end; padding: 0 6px; position: relative; z-index: 1; }
.lad-row > .lad-bid-q,
.lad-row > .lad-ask-q { min-width: 0; overflow: hidden; }
.lad-row > .lad-price { justify-content: center; font-weight: 600; }
.lad-row > .lad-bid-q { color: var(--bid); }
.lad-row > .lad-ask-q { color: var(--ask); }
.lad-row > .lad-bid-bar, .lad-row > .lad-ask-bar { padding: 0; }
.lad-bar-fill {
    position: absolute; top: 1px; bottom: 1px; height: auto;
    pointer-events: none;
}
.lad-bid-bar .lad-bar-fill { right: 0; background: var(--bid-bg); }
.lad-ask-bar .lad-bar-fill { left: 0;  background: var(--ask-bg); }

.lad-row.last-trade { background: rgba(47,129,247,0.10); }
.lad-row:hover { background: rgba(255,255,255,0.04); }

.lad-row .pulse { animation: pulseBg 0.5s ease-out; }
@keyframes pulseBg { from { background: rgba(47,129,247,0.4); } to { background: transparent; } }

#orders-table button.cancel-btn {
    background: transparent;
    border: 1px solid var(--err);
    color: var(--err);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
}
#orders-table button.cancel-btn:hover { background: rgba(248,81,73,0.18); }

/* ---- Login overlay ---- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(8, 11, 16, 0.92);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-card {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    width: 380px;
    display: flex; flex-direction: column; gap: 12px;
}
.modal-card h1 { margin: 0; font-size: 18px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--fg-dim); }
.modal-card .btn-primary { margin-top: 8px; }

/* ---- Toasts ---- */
#toast-host {
    position: fixed; right: 12px; bottom: 12px;
    display: flex; flex-direction: column; gap: 6px;
    z-index: 1100;
    pointer-events: none;
}
.toast {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 12px;
    max-width: 320px;
    pointer-events: auto;
}
.toast.warn  { border-color: var(--warn); }
.toast.error { border-color: var(--err);  }
