:root {
  --bg: #0b0f19;
  --card: #121827;
  --card2: #182033;
  --border: #22304a;
  --text: #e6ebf5;
  --muted: #8d9bb5;
  --gold: #f5b942;
  --gold2: #c98f1a;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #60a5fa;
  --amber: #fbbf24;
  --radius: 14px;
  --tabbar: 62px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
b { font-weight: 650; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono, .num { font-variant-numeric: tabular-nums; }
.spacer { height: 24px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: rgba(11,15,25,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand img { border-radius: 7px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.pill.ok { color: var(--green); border-color: rgba(34,197,94,.4); }
.pill.off { color: var(--amber); border-color: rgba(251,191,36,.4); }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px; }
.tab { display: none; }
.tab.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 10px; font-weight: 600; }

textarea, input[type=text], select {
  width: 100%; background: #0e1422; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none;
  transition: border-color .12s;
}
textarea { resize: vertical; min-height: 96px; }
textarea:focus, input:focus, select:focus { border-color: var(--gold2); }
input.invalid { border-color: var(--red); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 10px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.hint.warn { color: var(--amber); }
.hint.err { color: var(--red); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 6px 0; }
.check input { width: 18px; height: 18px; }

.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

.btn {
  background: var(--card2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; cursor: pointer;
  font-weight: 600; font-size: 15px; -webkit-tap-highlight-color: transparent; min-height: 44px; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--gold); color: #1a1200; border-color: var(--gold); }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 6px 10px; font-size: 13px; min-height: 34px; }
.btn.danger { color: var(--red); border-color: rgba(239,68,68,.4); }
.btn.good { color: var(--green); border-color: rgba(34,197,94,.5); }
.btn:disabled { opacity: .45; cursor: default; }
.link { background: none; border: none; color: var(--blue); padding: 6px 0; cursor: pointer; font-size: 14px; }

.seg { display: flex; background: #0e1422; border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: none; background: transparent; padding: 8px 6px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; min-height: 40px; }
.seg button.on { background: var(--card2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.seg button.seg-buy.on { color: var(--green); }
.seg button.seg-sell.on { color: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips.small { margin-top: 6px; }
.chip {
  border: 1px solid var(--border); background: #0e1422; border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.chips.small .chip { padding: 3px 9px; font-size: 12px; }
.chip.on { border-color: var(--gold); color: var(--gold); }
.chip.muted { color: var(--muted); }

.tplist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.tprow { display: flex; gap: 6px; align-items: center; }
.tprow .tplabel { width: 38px; font-size: 13px; color: var(--muted); }
.tprow input { flex: 1; }
.tprow .tpr { width: 64px; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tprow .x { background: none; border: none; color: var(--muted); font-size: 18px; padding: 4px 6px; cursor: pointer; }

.riskrow { display: flex; align-items: center; gap: 8px; }
.riskrow .cur { font-size: 22px; color: var(--muted); }
.big-input { font-size: 26px; font-weight: 700; padding: 8px 12px; max-width: 160px; font-variant-numeric: tabular-nums; }
.pct-input { max-width: 76px; text-align: right; font-variant-numeric: tabular-nums; }
.riskrow .eq { color: var(--muted); }

.result { border-color: rgba(245,185,66,.35); background: linear-gradient(180deg, #151c2e, #121827); }
.result .empty { color: var(--muted); text-align: center; padding: 14px 6px; }
.result .headline { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.result .big { font-size: 40px; font-weight: 800; letter-spacing: -.5px; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1.1; }
.result .unit { font-size: 18px; color: var(--gold); font-weight: 600; }
.result .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-top: 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; }
.kv.full { grid-template-columns: 1fr; }
table.tbl { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px 4px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 6px 4px; border-bottom: 1px solid rgba(34,48,74,.5); }
.tbl th:first-child, .tbl td:first-child { padding-left: 0; }
.tbl th:last-child, .tbl td:last-child { padding-right: 0; }
.tbl.plan { font-size: 13px; }
.tbl.plan .sub { display: block; font-size: 11px; color: var(--muted); }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tr.done td { color: var(--muted); text-decoration: line-through; }
.tbl tr.reached td { color: var(--green); }
.tbl tr.next td:first-child { color: var(--gold); }
.pos { color: var(--green); } .neg { color: var(--red); } .gold { color: var(--gold); } .warn { color: var(--amber); }
.alert { border-radius: 10px; padding: 9px 12px; font-size: 14px; margin-top: 10px; border: 1px solid; }
.alert.err { border-color: rgba(239,68,68,.5); background: rgba(239,68,68,.08); color: #fca5a5; }
.alert.warn { border-color: rgba(251,191,36,.5); background: rgba(251,191,36,.08); color: #fde68a; }
.alert.info { border-color: rgba(96,165,250,.5); background: rgba(96,165,250,.08); color: #bfdbfe; }
.alert.ok { border-color: rgba(34,197,94,.5); background: rgba(34,197,94,.08); color: #bbf7d0; }

.flags { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.flag { font-size: 13px; padding: 5px 9px; border-radius: 8px; background: rgba(251,191,36,.08); color: #fde68a; border: 1px solid rgba(251,191,36,.25); }
.flag.err { background: rgba(239,68,68,.08); color: #fca5a5; border-color: rgba(239,68,68,.3); }
.flag.info { background: rgba(96,165,250,.08); color: #bfdbfe; border-color: rgba(96,165,250,.3); }

.picker { margin-top: 10px; }
.picker .ptitle { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.picker .chips { margin-top: 0; }

.imgbox { display: flex; gap: 10px; margin-top: 10px; align-items: flex-start; }
.imgbox img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: #000; }
.imgmeta { flex: 1; display: flex; flex-direction: column; gap: 6px; }
progress { width: 100%; height: 6px; accent-color: var(--gold); }
.ocrtext { white-space: pre-wrap; font-size: 12px; color: var(--muted); max-height: 160px; overflow: auto; background: #0e1422; padding: 8px; border-radius: 8px; }

/* Manage */
.tradecard { cursor: pointer; }
.tradecard:active { background: var(--card2); }
.thead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--gold); color: #1a1200; margin-left: 4px; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.tag.buy { background: rgba(34,197,94,.15); color: var(--green); }
.tag.sell { background: rgba(239,68,68,.15); color: var(--red); }
.tag.grey { background: rgba(141,155,181,.15); color: var(--muted); }
.tsym { font-weight: 800; font-size: 17px; }
.tline { font-size: 13px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.status { font-size: 22px; font-weight: 800; }
.action { border-color: rgba(34,197,94,.45); background: linear-gradient(180deg, #13251c, #121827); }
.action.stop { border-color: rgba(239,68,68,.45); background: linear-gradient(180deg, #2a1616, #121827); }
.action.hold { border-color: var(--border); background: var(--card); }
.action .atitle { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.action .aline { font-size: 20px; font-weight: 800; margin: 4px 0; }
.action .aline .big { font-size: 26px; color: var(--gold); }
.action .areason { color: var(--muted); font-size: 14px; }
.alts { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.alt { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.alt .l { color: var(--text); }
.alt .m { color: var(--muted); font-size: 12px; }
.section-title { font-size: 13px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; }
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(11,15,25,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar) + env(safe-area-inset-bottom));
}
.tabbar button { flex: 1; background: none; border: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tabbar button .ico { font-size: 20px; }
.tabbar button.active { color: var(--gold); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + 14px + env(safe-area-inset-bottom)); z-index: 40;
  background: #1f2937; color: var(--text); padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); font-size: 14px; max-width: 92vw; box-shadow: 0 6px 24px rgba(0,0,0,.5); cursor: pointer; }
.toast.action { border-color: var(--gold); }

@media (max-width: 380px) {
  .grid3 { grid-template-columns: 1fr; }
  .result .big { font-size: 34px; }
}
@media (min-width: 720px) {
  main { padding-top: 20px; }
}

/* Live prices */
.live { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.live.is-live .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.live.is-connecting .dot { background: var(--amber); }
.live.is-offline .dot, .live.is-unavailable .dot { background: var(--muted); }
.live .lp { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.live .chip { padding: 2px 9px; font-size: 12px; }
.livestatus { margin-top: 6px; }
.tline .lp { color: var(--text); font-weight: 600; }
