:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --positive: #15803d;
    --negative: #b91c1c;
    --positive-bg: #dcfce7;
    --negative-bg: #fee2e2;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; margin-top: 16px; }
h2.inline { display: inline; }
code, .code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
pre { white-space: pre-wrap; margin: 0; }

/* Frame */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    background: #111827;
    color: #e5e7eb;
    min-height: 52px;
    flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.main-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.main-nav a { color: #cbd5e1; padding: 6px 12px; border-radius: 6px; }
.main-nav a:hover { background: #1f2937; text-decoration: none; }
.main-nav a[aria-current="page"] { background: #374151; color: #fff; }
.data-state { margin-left: auto; font-size: 13px; color: #9ca3af; }
.data-state a { color: #cbd5e1; }

main { max-width: 1280px; margin: 0 auto; padding: 24px 16px; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 32px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    overflow-x: auto;
}
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.columns { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .columns { grid-template-columns: 1fr; } }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card .kpis { margin: 16px 0; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi-note { color: var(--muted); font-size: 12px; }
.kpi-actions { justify-content: center; gap: 8px; }
.kpi-actions .button { width: 100%; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 2px solid var(--border); white-space: nowrap; }
.table td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: #f9fafb; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { white-space: nowrap; text-align: right; }
.table tr.inactive td { opacity: .5; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-buy { background: var(--positive-bg); color: var(--positive); }
.badge-sell { background: var(--negative-bg); color: var(--negative); }
.badge-neutral { background: #e5e7eb; color: #374151; }

/* Buttons */
.button {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 7px 14px; border: 1px solid #d1d5db; border-radius: 6px;
    background: #fff; color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.button:hover { background: #f3f4f6; text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); }
.button.danger { color: var(--negative); }
.button.small { padding: 3px 10px; font-size: 13px; }
.button.active { background: #111827; border-color: #111827; color: #fff; }
.button:disabled { opacity: .6; cursor: wait; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-button { background: none; border: 0; padding: 0 4px; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }
.link-button.danger { color: var(--negative); }
.toggle { min-width: 44px; padding: 2px 10px; border-radius: 999px; border: 1px solid #d1d5db; background: #f3f4f6; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
.toggle.on { background: var(--positive-bg); border-color: #86efac; color: var(--positive); font-weight: 600; }

/* Forms */
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: var(--text); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #374151; }
textarea.code { width: 100%; font-size: 13px; line-height: 1.45; }
.hint { color: var(--muted); font-size: 12px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-row, .filter { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px 16px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.inline-form label { flex-direction: row; align-items: center; gap: 8px; }
details summary { cursor: pointer; }

/* Messages */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.flash-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash details { margin-top: 6px; color: var(--text); }
.flash pre { font-size: 12px; max-height: 300px; overflow: auto; background: #fff; padding: 8px; border-radius: 6px; margin-top: 6px; }

/* Charts */
.chart-toolbar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 12px 0 8px; }
.range-buttons { display: flex; gap: 4px; }
.legend { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-left: 8px; }
.chart { width: 100%; }
.chart-large { height: 460px; }
.chart-medium { height: 360px; }
.chart-small { height: 140px; }
.chart-caption { color: var(--muted); font-size: 12px; margin: 8px 0 2px; }
.price-box { text-align: right; display: flex; flex-direction: column; }
.price { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

.help ul { padding-left: 18px; margin: 0; }
.help li { margin-bottom: 4px; }
.help pre { background: #f3f4f6; padding: 8px 10px; border-radius: 6px; }

/* Login */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 340px; max-width: 100%; display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 640px) {
    .topbar { padding: 8px 16px; gap: 8px; }
    .data-state { margin-left: 0; width: 100%; }
    main { padding: 16px 12px; }
    .card { padding: 14px; }
    .chart-large { height: 340px; }
}
