:root {
  --bg: #0d1014;
  --panel: #151a21;
  --panel2: #1b2129;
  --line: #262e38;
  --text: #e6e9ee;
  --muted: #8a94a3;
  --dim: #5d6673;
  --up: #2ebd85;
  --down: #f6465d;
  --accent: #4c8dff;
  --warn: #f0b90b;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num, td.n, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.err { color: var(--down); min-height: 1.4em; }
.ok { color: var(--up); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(340px, 100%); display: grid; gap: 12px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
input[type=password], input[type=text], input[type=date], select, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.btn, .login-box button {
  background: var(--accent); border: 0; border-radius: 8px; padding: 9px 14px; color: #fff; font-weight: 600;
}
.btn.ghost { background: var(--panel2); border: 1px solid var(--line); color: var(--text); font-weight: 500; }
.btn.danger { background: transparent; border: 1px solid var(--down); color: var(--down); }
.btn:disabled { opacity: .5; cursor: default; }

.top { display: flex; align-items: center; gap: 24px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { background: none; border: 0; padding: 7px 12px; border-radius: 7px; color: var(--muted); }
nav button.on { background: var(--panel2); color: var(--text); }
nav button:hover { color: var(--text); }
.sync { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.dot.ok { background: var(--up); }
.dot.busy { background: var(--warn); }
.dot.bad { background: var(--down); }

.filters { display: flex; gap: 10px; align-items: center; padding: 12px 20px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.filters label { color: var(--muted); display: flex; gap: 6px; align-items: center; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { background: none; border: 0; padding: 5px 10px; border-radius: 6px; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .v { font-family: var(--mono); font-size: 20px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--dim); font-size: 12px; margin-top: 2px; font-family: var(--mono); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 16px; }
.card h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } main { padding: 12px 16px; } .top, .filters { padding: 10px 16px; } }
.chart { width: 100%; display: block; }
.chart .axis { fill: var(--dim); font-size: 11px; font-family: var(--mono); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--dim); stroke-width: 1; stroke-dasharray: 3 3; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--panel); cursor: pointer; user-select: none; }
th.n, td.n { text-align: right; }
tbody tr:hover { background: var(--panel2); }
tr.clickable { cursor: pointer; }
tr.detail > td { background: var(--bg); padding: 14px; white-space: normal; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 12px; font-weight: 600; }
.tag.LONG { background: rgba(46,189,133,.15); color: var(--up); }
.tag.SHORT { background: rgba(246,70,93,.15); color: var(--down); }
.tag.open { background: rgba(240,185,11,.15); color: var(--warn); }
.tag.csv { background: var(--panel2); color: var(--muted); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 10px; color: var(--muted); }
textarea.note { width: 100%; min-height: 70px; resize: vertical; margin-top: 10px; }
.fills td { padding: 4px 8px; font-size: 12px; }

.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cal-head .title { font-size: 16px; font-weight: 600; min-width: 160px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr) 1.1fr; gap: 6px; }
.cal .wd { color: var(--muted); font-size: 12px; text-align: center; padding: 4px; }
.cal .day { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-height: 78px; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.cal .day.out { opacity: .3; }
.cal .day .d { color: var(--dim); font-size: 12px; }
.cal .day .p { font-family: var(--mono); font-size: 14px; margin-top: auto; }
.cal .day .c { color: var(--dim); font-size: 11px; }
.cal .day.pos { background: rgba(46,189,133,.10); border-color: rgba(46,189,133,.35); }
.cal .day.neg { background: rgba(246,70,93,.10); border-color: rgba(246,70,93,.35); }
.cal .week { background: var(--panel2); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; justify-content: center; font-family: var(--mono); }
.cal .week .c { color: var(--dim); font-size: 11px; font-family: system-ui, sans-serif; }

.form { display: grid; gap: 10px; max-width: 560px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form input[type=text], .form input[type=password] { width: 100%; }
.hint { color: var(--muted); font-size: 12px; }
.warnbox { border: 1px solid rgba(240,185,11,.4); background: rgba(240,185,11,.07); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv .k { color: var(--muted); }

.tip { position: fixed; pointer-events: none; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; z-index: 20; font-family: var(--mono); white-space: nowrap; }

.tchart { position: relative; margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tchart canvas { display: block; cursor: crosshair; touch-action: none; }
.tchart canvas.grab { cursor: grabbing; }
.tchart-tools { margin-top: 12px; }
.tchart-tools .seg button { padding: 4px 8px; font-size: 12px; font-family: var(--mono); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.tchart-shot { position: absolute; top: 6px; right: 80px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); border-radius: 7px; padding: 5px 7px; display: grid; place-items: center; }
.tchart-shot:hover { color: var(--text); }
.tchart-shot.done { color: var(--up); border-color: var(--up); }
.tchart-info { position: absolute; left: 8px; top: 6px; font-size: 12px; color: var(--muted); pointer-events: none; background: rgba(21,26,33,.8); padding: 2px 6px; border-radius: 5px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 10px; z-index: 30; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
#sync-btn { padding: 2px 8px; font-size: 14px; line-height: 1.2; }

/* таблица сделок: спокойнее, цвет только у плашки % и итога */
#tab-trades table { font-variant-numeric: tabular-nums; font-size: 13px; }
#tab-trades td { padding: 10px 12px; }
#tab-trades th { padding: 10px 12px; }
.sym { font-weight: 600; }
.side { font-size: 12px; font-weight: 600; letter-spacing: .3px; color: var(--muted); }
.side.LONG { color: #7fd3b0; }
.side.SHORT { color: #f08a98; }
.pill { display: inline-block; min-width: 58px; text-align: center; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 12px; color: #fff; }
.pill.up { background: #1f8a5c; }
.pill.down { background: #a8323f; }
.pill.zero { background: var(--panel2); color: var(--muted); }
.dim { color: var(--dim); }
#tab-trades td.n, #tab-trades td .mono { font-family: inherit; }
.tchart-info:empty { display: none; }
