:root {
  --bg: #f7f7f5; --surface: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --border: #e2e2df;
  --accent: #2f5fb3; --up: #1a7f45; --down: #c0392b; --warn-bg: #fff4d6; --warn-text: #6b4e00;
  --buy-bg: #dff3e6; --sell-bg: #fbe1de; --bar: #2f5fb3; --tip-bg: #26262b; --tip-text: #f4f4f6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416; --surface: #1d1d20; --text: #ececee; --muted: #9a9aa2; --border: #303036;
    --accent: #7aa6ff; --up: #45c97a; --down: #ff6b5c; --warn-bg: #3a3014; --warn-text: #f3d98b;
    --buy-bg: #173a26; --sell-bg: #45201c; --bar: #7aa6ff; --tip-bg: #f0f0f3; --tip-text: #1d1d1f;
  }
}
:root[data-theme="dark"] {
  --bg: #141416; --surface: #1d1d20; --text: #ececee; --muted: #9a9aa2; --border: #303036;
  --accent: #7aa6ff; --up: #45c97a; --down: #ff6b5c; --warn-bg: #3a3014; --warn-text: #f3d98b;
  --buy-bg: #173a26; --sell-bg: #45201c; --bar: #7aa6ff; --tip-bg: #f0f0f3; --tip-text: #1d1d1f;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 1.2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
code { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .85rem; }
.up { color: var(--up); }
.down { color: var(--down); }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 24px; min-height: 52px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
nav a.active, nav a:hover { color: var(--text); background: var(--bg); text-decoration: none; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: .8rem 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; }
.tile .label { color: var(--muted); font-size: .8rem; }
.tile .value { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: .6rem 0; }
.controls label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: 2px; }
.controls .grow { flex: 1 1 200px; }
select, input, button { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; max-width: 100%; }
button, .button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 14px; cursor: pointer; display: inline-block; }
.button:hover { text-decoration: none; opacity: .9; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: 5px 12px; color: var(--muted); border-right: 1px solid var(--border); }
.seg a:last-child { border-right: 0; }
.seg a.active { background: var(--accent); color: #fff; }
.toggle { padding: 5px 0; }

.notice { border-radius: 8px; padding: 10px 14px; margin: .6rem 0; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.two-col > * { min-width: 0; }
@media (max-width: 800px) { .two-col { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 600px) { .topbar-inner { gap: 4px 16px; padding-top: 6px; padding-bottom: 6px; } nav a { padding: 4px 8px; } .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
th a { color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.bar { display: inline-block; width: 60px; height: 6px; background: var(--border); border-radius: 3px; margin-right: 8px; vertical-align: middle; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--bar); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 10px; background: var(--bg); color: var(--muted); vertical-align: middle; }
.tag.buy { background: var(--buy-bg); color: var(--up); }
.tag.sell { background: var(--sell-bg); color: var(--down); }

details.full { margin: 1.2rem 0; }
details.full summary { cursor: pointer; color: var(--accent); margin-bottom: .5rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px 16px 12px; margin: 14px 0; }
.card table { border: 0; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px; margin: .6rem 0; min-width: 0; }
.card .chart { border: 0; padding: 0; }
.crumb { margin: 1rem 0 -.6rem; font-size: .85rem; }
.footer { color: var(--muted); font-size: .8rem; border-top: 1px solid var(--border); margin-top: 2.5rem; padding-top: .6rem; padding-bottom: 2rem; }
main { overflow-wrap: anywhere; }
.help { border-bottom: 1px dotted currentColor; cursor: help; outline-offset: 2px; }
.help:focus-visible { outline: 2px solid var(--accent); border-radius: 2px; }
#tip { position: fixed; z-index: 100; max-width: min(320px, calc(100vw - 16px)); padding: 8px 11px;
  background: var(--tip-bg); color: var(--tip-text); border-radius: 7px; font-size: .82rem;
  font-weight: normal; line-height: 1.45; text-align: left; white-space: normal;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); pointer-events: none; }
.user-nav { margin-left: auto; align-items: center; }
form.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; color: var(--muted); padding: 6px 10px; cursor: pointer; }
button.link:hover { color: var(--text); }
button.secondary, .button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--down); }
.button.small, button.small { padding: 4px 10px; font-size: .85rem; }
.notice.success { background: var(--buy-bg); color: var(--up); }
.notice.error { background: var(--sell-bg); color: var(--down); }
.form { max-width: 460px; }
.form.wide { max-width: 760px; }
.field { margin: 0 0 14px; display: flex; flex-direction: column; gap: 4px; }
.field > label { font-weight: 600; font-size: .9rem; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=number],
.field input[type=date], .field select, .field textarea { width: 100%; padding: 8px 10px; }
.field.check { flex-direction: row; align-items: flex-start; gap: 8px; }
.field.check > label { font-weight: normal; }
.field .hint { color: var(--muted); font-size: .8rem; }
.field .err, .errorlist { color: var(--down); font-size: .85rem; margin: 0; padding: 0; list-style: none; }
.field ul.radios, .field div.radios { display: flex; gap: 16px; list-style: none; margin: 0; padding: 0; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 14px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin: 12px 0; }
.models-mini { display: flex; gap: 3px; }
.models-mini span { width: 12px; height: 12px; border-radius: 3px; background: var(--border); display: inline-block; }
.models-mini span.buy { background: var(--up); }
.models-mini span.sell { background: var(--down); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .75rem; background: var(--warn-bg); color: var(--warn-text); }
.rank-num { font-size: 1.2rem; font-weight: 700; color: var(--muted); width: 2ch; }
td form.inline button { padding: 2px 8px; font-size: .8rem; }
.check-label { display: flex; gap: 8px; align-items: flex-start; font-weight: normal !important; }
.check-label input { margin-top: 4px; }
#id_side { display: flex; gap: 20px; }
#id_side label { display: flex; gap: 6px; align-items: center; font-weight: normal; }
.prose { max-width: 760px; }
.prose li { margin: 6px 0; }
.prose h2 { margin-top: 1.6rem; }

/* sortable table headers (base.html) */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text, inherit); text-decoration: underline dotted; }
.sort-ind { display: inline-block; min-width: 0.9em; margin-left: 0.2em; font-size: 0.75em; opacity: 0.7; }
