:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #171716;
  --surface-2: #1f1f1e;
  --surface-3: #2a2a28;
  --border: rgba(255, 255, 255, 0.10);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #8f8d86;
  --blue: #3987e5;
  --pos: #22b357;
  --pos-bg: rgba(34, 179, 87, 0.13);
  --neg: #e0524f;
  --neg-bg: rgba(224, 82, 79, 0.13);
  --warn: #fab219;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--blue); }
button, input { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.r { text-align: right; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--blue); display: grid; place-items: center; font-size: 13px; color: #fff; }
.top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.conn { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--pos); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--neg); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--text-2); cursor: pointer; }
.linkbtn:hover { color: var(--text); }

main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 60px; display: flex; flex-direction: column; gap: 16px; }
h2 { margin: 0; font-size: 16px; }

.btn { background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: rgba(255,255,255,.25); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.icon { padding: 4px 11px; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.banner { border: 1px solid var(--border); border-left: 3px solid var(--warn); background: rgba(250, 178, 25, 0.08); padding: 10px 14px; border-radius: 8px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile.today { border-color: rgba(57, 135, 229, .45); }
.t-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.t-val { font-size: 26px; font-weight: 700; margin: 4px 0 2px; }
.t-sub { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.cal-nav { display: flex; align-items: center; gap: 10px; }
.cal-nav h2 { min-width: 150px; text-align: center; }
.unit-form { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.in-money { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 0 8px; }
.in-money input { width: 80px; background: none; border: 0; padding: 5px 0; outline: none; }
.form-msg { font-size: 13px; color: var(--muted); }
.suggest { font-size: 13px; color: var(--text-2); margin-top: -4px; }
.suggest strong { color: var(--text); }
.form-msg.err { color: var(--neg); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.dow { color: var(--muted); font-size: 12px; text-align: center; padding-bottom: 2px; }
.day { min-height: 92px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); padding: 7px 8px; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; cursor: pointer; min-width: 0; }
.day.blank { background: none; border: 0; cursor: default; }
.day.none { cursor: default; opacity: .55; }
.day.pos { background: var(--pos-bg); border-color: rgba(34, 179, 87, .35); }
.day.neg { background: var(--neg-bg); border-color: rgba(224, 82, 79, .35); }
.day.today { outline: 2px solid var(--blue); outline-offset: -1px; }
.day.sel { box-shadow: 0 0 0 2px #fff inset; }
.d-num { font-size: 12px; color: var(--text-2); font-weight: 600; }
.d-units { font-size: 17px; font-weight: 700; margin-top: 4px; }
.day.pos .d-units, .day.pos .d-usd { color: var(--pos); }
.day.neg .d-units, .day.neg .d-usd { color: var(--neg); }
.d-usd { font-size: 12px; }
.d-n { font-size: 11px; color: var(--muted); margin-top: auto; }

/* trades */
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
table.trades { width: 100%; border-collapse: collapse; font-size: 13px; }
.trades th { color: var(--muted); font-weight: 500; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.trades th.r { text-align: right; }
.trades td { padding: 8px; border-bottom: 1px solid rgba(255,255,255,.05); white-space: nowrap; }
.side { font-weight: 600; font-size: 12px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; border-radius: 7px; padding: 5px 12px; cursor: pointer; color: var(--text-2); font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--surface-3); color: var(--text); }
.seg button span { color: var(--muted); font-weight: 500; margin-left: 4px; }
.empty { margin: 10px 8px 0; }
.side.up { color: var(--pos); } .side.down { color: var(--neg); }

.key-card form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.key-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.key-card input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; min-width: 220px; }
.foot { text-align: center; }
.linkbtn.u { text-decoration: underline; font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--surface-3); border: 1px solid var(--border); padding: 9px 16px; border-radius: 9px; z-index: 20; }

/* sign-in page */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 4px 0 0; font-size: 20px; }
.login label { display: flex; flex-direction: column; gap: 5px; color: var(--text-2); font-size: 13px; }
.login input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; }
.login .note { color: var(--muted); font-size: 12px; margin: 0; }
.form-msg.ok { color: var(--pos); }

@media (max-width: 760px) {
  .top { padding: 12px 16px; }
  main { padding: 16px 16px 48px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .t-val { font-size: 21px; }
  .cal { gap: 3px; }
  .day { min-height: 64px; padding: 4px; border-radius: 6px; }
  .d-usd, .d-n { display: none; }
  .d-units { font-size: 11px; letter-spacing: -.02em; max-width: 100%; overflow: hidden; }
  .brand { font-size: 14px; }
  .dow { font-size: 10px; }
  .conn #conn-txt { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
#tab-settled, #tab-open { max-height: 520px; overflow-y: auto; }
.cal-head .suggest { flex-basis: 100%; text-align: right; margin-top: -6px; }
@media (max-width: 760px) { .cal-head .suggest { text-align: left; } }
