:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1b1f27;
    --muted: #697386;
    --line: #e3e6eb;
    --accent: #3b5bdb;
    --accent-soft: #e7ecfd;
    --pos: #1c8a4c;
    --pos-soft: #e3f4ea;
    --neg: #c8363d;
    --neg-soft: #fbe7e8;
    --warn: #a86400;
    --warn-soft: #fdf0dc;
    --l1: #d98e04;
    --l2: #7c4dcc;
    --l3: #0f9d9a;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 25, 40, .06);
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1218;
        --card: #171b23;
        --text: #e6e8ec;
        --muted: #8b93a3;
        --line: #272d38;
        --accent: #7c95ff;
        --accent-soft: #1d2440;
        --pos: #45c07a;
        --pos-soft: #13291d;
        --neg: #f06a70;
        --neg-soft: #33171a;
        --warn: #f0a93b;
        --warn-soft: #32250f;
        --shadow: none;
        --l1: #f5b83d;
        --l2: #b392f0;
        --l3: #3cc9c4;
        color-scheme: dark;
    }
}
* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

header.top {
    display: flex; align-items: center; gap: 24px;
    padding: 0 24px; height: 56px;
    background: var(--card); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); font-size: 16px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; margin-right: 4px; }
header nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
header nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
header nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
header nav a:hover { text-decoration: none; color: var(--text); }
.logout { margin: 0; }
.worker-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; }
.worker-pill:hover { text-decoration: none; color: var(--text); }
.worker-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.worker-pill.on .dot { background: var(--pos); box-shadow: 0 0 0 3px var(--pos-soft); }
.worker-pill.off .dot { background: var(--neg); }
.worker-pill.off { color: var(--neg); border-color: var(--neg-soft); }
[hidden] { display: none !important; }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
footer { max-width: 1240px; margin: 0 auto; padding: 8px 24px 32px; color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
tr.off td { opacity: .45; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.long, .badge.ok { background: var(--pos-soft); color: var(--pos); }
.badge.short, .badge.danger { background: var(--neg-soft); color: var(--neg); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

.score { position: relative; display: inline-flex; align-items: center; width: 90px; height: 18px; background: var(--bg); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.score span { position: absolute; left: 0; top: 0; bottom: 0; }
.score.hi span { background: var(--pos-soft); }
.score.mid span { background: var(--warn-soft); }
.score.lo span { background: var(--line); }
.score b { position: relative; margin-left: 6px; font-size: 12px; }

.regime { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.bull { background: var(--pos); }
.dot.bear { background: var(--neg); }
.dot.neutral { background: var(--warn); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--pos-soft); color: var(--pos); }
.flash.err { background: var(--neg-soft); color: var(--neg); }

form.inline { display: inline; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
    background: var(--card); color: var(--text); font: inherit;
}
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; }
.field { margin-bottom: 12px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; }
button, .btn {
    display: inline-block; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--accent);
    background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
button.secondary, .btn.secondary { background: var(--card); color: var(--accent); }
button.danger { background: var(--neg); border-color: var(--neg); }
button.link { background: none; border: 0; color: var(--muted); padding: 6px; font-weight: 500; }
.btn:hover { text-decoration: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { width: auto; }

.zones { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 14px; }
.zone { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.zone .k { font-size: 12px; color: var(--muted); }
.zone .p { font-size: 18px; font-weight: 650; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.list { margin: 0; padding-left: 18px; }
.list li { margin: 3px 0; }
.chart { height: 380px; margin: 0 -8px; }
.chart-rsi { height: 110px; margin: 0 -8px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.tf-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tf-toggle button { background: var(--card); color: var(--muted); border: 0; border-radius: 0; padding: 6px 12px; font-weight: 600; }
.tf-toggle button.on { background: var(--accent-soft); color: var(--accent); }
.legend { display: flex; gap: 6px; flex-wrap: wrap; }
.legend .lg { background: none; border: 1px solid var(--line); color: var(--text); padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.legend .lg i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .lg.off { opacity: .4; text-decoration: line-through; }
.sub-label { font-size: 12px; color: var(--muted); margin: 6px 0 2px; display: flex; justify-content: space-between; }
.explain { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; font-size: 13px; }
.explain p { margin: 0 0 6px; }
.explain p:last-child { margin: 0; }
.calc { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 14px; }
.calc-out { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 6px; }
.calc-out div { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.calc-out span { display: block; font-size: 12px; color: var(--muted); }
.calc-out b { font-size: 16px; }
.reason { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.reason:last-child { border: 0; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }
.event { padding: 8px 0; border-bottom: 1px solid var(--line); }
.event:last-child { border: 0; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 60px; }
.bars span { flex: 1; background: var(--accent-soft); border-top: 2px solid var(--accent); min-height: 2px; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }

@media (max-width: 900px) {
    .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span2 { grid-column: auto; }
    .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    header.top { padding: 0 12px; gap: 10px; height: auto; flex-wrap: wrap; padding-top: 8px; }
    header nav { order: 3; flex-basis: 100%; padding-bottom: 6px; }
    .worker-pill .txt { display: none; }
    main { padding: 16px; }
    footer { padding: 8px 16px 24px; }
    .g3, .g4 { grid-template-columns: 1fr 1fr; }
    .zones { grid-template-columns: 1fr; }
    .stat .value { font-size: 20px; }
}
