/* Trading Desk — iOS-style, quiet surfaces, one warm accent. */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card2: #f5f5f8;
  --label: #0b0b0c;
  --label2: rgba(60, 60, 67, .62);
  --label3: rgba(60, 60, 67, .32);
  --sep: rgba(60, 60, 67, .14);
  --fill: rgba(118, 118, 128, .12);
  --accent: #ffdd2d;
  --accent-ink: #1b1b1b;
  --tint: #0a84ff;
  --green: #1f9d4c;
  --green-bg: rgba(52, 199, 89, .14);
  --red: #e5342a;
  --red-bg: rgba(255, 59, 48, .12);
  --orange: #c76a00;
  --orange-bg: rgba(255, 149, 0, .14);
  --ai: #8a4fd8;
  --ai-bg: rgba(175, 82, 222, .10);
  --switch-on: #34c759;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .04);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #1c1c1e; --card2: #2c2c2e; --label: #f5f5f7;
    --label2: rgba(235, 235, 245, .6); --label3: rgba(235, 235, 245, .3); --sep: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24); --green: #30d158; --green-bg: rgba(48, 209, 88, .16);
    --red: #ff453a; --red-bg: rgba(255, 69, 58, .16); --orange: #ff9f0a; --orange-bg: rgba(255, 159, 10, .16);
    --ai: #bf8cff; --ai-bg: rgba(191, 140, 255, .12); --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #1c1c1e; --card2: #2c2c2e; --label: #f5f5f7;
  --label2: rgba(235, 235, 245, .6); --label3: rgba(235, 235, 245, .3); --sep: rgba(84, 84, 88, .55);
  --fill: rgba(118, 118, 128, .24); --green: #30d158; --green-bg: rgba(48, 209, 88, .16);
  --red: #ff453a; --red-bg: rgba(255, 69, 58, .16); --orange: #ff9f0a; --orange-bg: rgba(255, 159, 10, .16);
  --ai: #bf8cff; --ai-bg: rgba(191, 140, 255, .12); --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--label); font-family: var(--font);
  font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
.num, .mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--tint); text-decoration: none; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { display: none; }
main { flex: 1; min-width: 0; padding: 12px 16px 110px; max-width: 1180px; margin: 0 auto; width: 100%; }
.tab { display: none; }
.tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--card) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep); }
.tabbar button, .sidebar button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px;
  color: var(--label2); padding: 4px 10px; min-width: 60px; position: relative; }
.tabbar button svg, .sidebar button svg { width: 25px; height: 25px; }
.tabbar button.active, .sidebar button.active { color: var(--label); }
.tabbar button.active svg { color: var(--label); }
.badge { position: absolute; top: 0; right: 12px; min-width: 17px; height: 17px; border-radius: 9px; background: var(--red);
  color: #fff; font-size: 11px; font-weight: 600; display: none; align-items: center; justify-content: center; padding: 0 4px; }
.badge.on { display: flex; }

@media (min-width: 1000px) {
  .tabbar { display: none; }
  .sidebar { display: flex; flex-direction: column; gap: 4px; width: 230px; padding: 22px 12px; position: sticky; top: 0;
    height: 100vh; border-right: .5px solid var(--sep); background: var(--card); }
  .sidebar .brand { font-weight: 700; font-size: 19px; padding: 4px 12px 18px; letter-spacing: -.2px; }
  .sidebar .brand small { display: block; font-weight: 500; font-size: 12px; color: var(--label2); }
  .sidebar button { flex-direction: row; gap: 12px; font-size: 15px; padding: 10px 12px; border-radius: 10px;
    min-width: 0; justify-content: flex-start; color: var(--label); }
  .sidebar button svg { width: 22px; height: 22px; color: var(--label2); }
  .sidebar button.active { background: var(--fill); font-weight: 600; }
  .sidebar button .badge { position: static; margin-left: auto; }
  main { padding: 28px 36px 60px; }
  .grid2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 24px; align-items: start; }
}

/* ---------- typography ---------- */
.large-title { font-size: 32px; font-weight: 700; letter-spacing: -.5px; margin: 6px 4px 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; font-size: 20px; font-weight: 700;
  letter-spacing: -.3px; margin: 26px 4px 10px; }
.section-title small { font-size: 14px; font-weight: 500; color: var(--label2); letter-spacing: 0; }
.caption { font-size: 13px; color: var(--label2); }
.foot { font-size: 12.5px; color: var(--label2); margin: 8px 16px 0; line-height: 1.45; }
.up { color: var(--green); } .down { color: var(--red); } .muted { color: var(--label2); }
.ai-text { color: var(--label); background: var(--ai-bg); border-left: 3px solid var(--ai); border-radius: 4px 12px 12px 4px;
  padding: 10px 12px; font-size: 14.5px; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card.pad { padding: 16px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cell { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px; position: relative; width: 100%;
  text-align: left; }
.cell + .cell::before { content: ""; position: absolute; top: 0; right: 0; left: 64px; border-top: .5px solid var(--sep); }
.list.plain .cell + .cell::before { left: 16px; }
button.cell:active, .cell.tap:active { background: var(--fill); }
.cell .main { flex: 1; min-width: 0; }
.cell .title { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.cell .sub { font-size: 13.5px; color: var(--label2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .right { text-align: right; flex-shrink: 0; }
.cell .right .v { font-weight: 600; font-size: 16px; }
.chev { color: var(--label3); width: 9px; flex-shrink: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0; letter-spacing: -.3px; }
.empty { padding: 28px 16px; text-align: center; color: var(--label2); font-size: 14.5px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--fill); color: var(--label2); white-space: nowrap; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.orange { background: var(--orange-bg); color: var(--orange); }
.pill.ai { background: var(--ai-bg); color: var(--ai); }
.pill.dark { background: var(--label); color: var(--card); }
.pill.yellow { background: var(--accent); color: var(--accent-ink); }

/* ---------- hero ---------- */
.hero { padding: 6px 4px 2px; }
.hero .label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--label2); font-weight: 500; }
.hero .big { font-size: 44px; font-weight: 700; letter-spacing: -1.2px; line-height: 1.1; margin-top: 4px; }
.hero .big .cents { font-size: 30px; color: var(--label2); }
.hero .delta { font-size: 15.5px; font-weight: 600; margin-top: 2px; }
.hero .delta span { color: var(--label2); font-weight: 500; }

.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { flex: 1; padding: 6px 10px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--label); }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
:root[data-theme="dark"] .seg button.on { background: #636366; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg button.on { background: #636366; } }

.chart { position: relative; height: 190px; margin: 10px 0 12px; touch-action: pan-y; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .tip { position: absolute; top: -4px; transform: translateX(-50%); background: var(--card); box-shadow: var(--shadow);
  border-radius: 8px; padding: 3px 8px; font-size: 12px; font-weight: 600; pointer-events: none; white-space: nowrap;
  border: .5px solid var(--sep); }
.chart .nodata { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--label2);
  font-size: 14px; }

/* ---------- control card ---------- */
.controls { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; }
.controls .t { font-weight: 600; font-size: 16px; }
.controls .s { font-size: 13px; color: var(--label2); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px; border-radius: 12px;
  font-weight: 600; font-size: 15px; background: var(--fill); color: var(--label); }
.btn:active { opacity: .7; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn.dark { background: var(--label); color: var(--card); }
.btn.block { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.row-btns { display: flex; gap: 10px; }
.row-btns .btn { flex: 1; }

.switch { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; background: var(--fill); border-radius: 999px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: transform .2s; }
.switch input:checked + span { background: var(--switch-on); }
.switch input:checked + span::after { transform: translateX(20px); }

.progress { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 14px; }
.progress .pill.run::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- banners ---------- */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--radius); margin: 10px 0;
  font-size: 14.5px; }
.banner.red { background: var(--red-bg); color: var(--red); }
.banner.orange { background: var(--orange-bg); color: var(--orange); }
.banner.yellow { background: color-mix(in srgb, var(--accent) 30%, var(--card)); color: var(--label); }
.banner .b-main { flex: 1; }
.banner b { display: block; margin-bottom: 2px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--sep); }
.stats > div { background: var(--card); padding: 12px 10px; text-align: center; }
.stats .k { font-size: 12px; color: var(--label2); }
.stats .v { font-size: 17px; font-weight: 700; margin-top: 2px; }

/* ---------- agents ---------- */
.cycle { margin-bottom: 12px; }
.cycle-head { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; width: 100%; text-align: left; }
.cycle-head .main { flex: 1; min-width: 0; }
.cycle-head .t { font-weight: 600; font-size: 15.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cycle-head .s { font-size: 14px; color: var(--label2); margin-top: 3px; }
.cycle-body { border-top: .5px solid var(--sep); padding: 4px 16px 16px; display: none; }
.cycle.open .cycle-body { display: block; }
.agent { margin-top: 14px; }
.agent-h { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.agent-h .dot { width: 26px; height: 26px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 14px; background: var(--ai-bg); }
.agent-h small { color: var(--label2); font-weight: 500; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13.5px; margin-top: 6px; }
.kv dt { color: var(--label2); } .kv dd { margin: 0; }
.sym-row { background: var(--card2); border-radius: 12px; padding: 10px 12px; margin-top: 8px; font-size: 14px; }
.sym-row .h { display: flex; gap: 8px; align-items: center; font-weight: 700; flex-wrap: wrap; }
.sym-row p { margin: 5px 0 0; color: var(--label); }
.qbar { height: 5px; width: 60px; background: var(--fill); border-radius: 3px; overflow: hidden; display: inline-block; }
.qbar i { display: block; height: 100%; background: var(--ai); border-radius: 3px; }
.gate { font-size: 13.5px; margin-top: 6px; }
.gate li { margin: 2px 0; }
ul.clean { margin: 6px 0 0; padding-left: 18px; }

/* ---------- market ---------- */
.trend { display: inline-flex; gap: 3px; font-size: 12px; font-weight: 600; }
.trend span { padding: 1px 6px; border-radius: 6px; background: var(--fill); color: var(--label2); }
.trend .u { background: var(--green-bg); color: var(--green); } .trend .d { background: var(--red-bg); color: var(--red); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.tags .pill { font-weight: 500; font-size: 11.5px; }
#candles { height: 340px; margin: 4px -4px 0; }

/* ---------- chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 180px); min-height: 380px; }
@media (min-width: 1000px) { .chat-wrap { height: calc(100vh - 130px); max-width: 760px; } }
.msgs { flex: 1; overflow-y: auto; padding: 8px 2px 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 9px 13px; border-radius: 19px; font-size: 15.5px; white-space: pre-wrap; word-wrap: break-word;
  line-height: 1.38; }
.msg.user { align-self: flex-end; background: var(--tint); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg .meta { display: block; font-size: 11px; opacity: .6; margin-top: 3px; }
.typing { align-self: flex-start; background: var(--card); border-radius: 19px; padding: 12px 16px; display: none; gap: 4px; }
.typing.on { display: flex; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--label3); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-5px); } }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 0 0; }
.composer textarea { flex: 1; resize: none; border: .5px solid var(--sep); background: var(--card); border-radius: 20px;
  padding: 9px 14px; max-height: 140px; outline: none; font-size: 15.5px; }
.composer button { width: 36px; height: 36px; border-radius: 50%; background: var(--tint); color: #fff; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0; }
.composer button[disabled] { opacity: .4; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 0; }
.chips button { background: var(--card); border: .5px solid var(--sep); padding: 6px 12px; border-radius: 999px; font-size: 13.5px; }

/* ---------- settings ---------- */
.group-h { font-size: 13px; color: var(--label2); text-transform: uppercase; letter-spacing: .3px; margin: 26px 16px 7px; }
.set .cell { min-height: 46px; padding: 9px 16px; }
.set .cell + .cell::before { left: 16px; }
.set .cell .main { font-size: 15.5px; }
.set .cell .main small { display: block; font-size: 12.5px; color: var(--label2); }
.set input.inp { width: 92px; text-align: right; border: 0; background: transparent; outline: none; font-size: 15.5px;
  color: var(--label2); padding: 4px 0; }
.set input.inp:focus { color: var(--tint); }
.set input.wide { width: 210px; }
.set .val { color: var(--label2); }
.ok { color: var(--green); font-weight: 600; } .bad { color: var(--red); font-weight: 600; }

/* ---------- sheet ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .32); z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity .2s; }
.sheet-bg.on { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; background: var(--bg); border-radius: 14px 14px 0 0;
  max-height: 92vh; overflow-y: auto; transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet.on { transform: none; }
.sheet .grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label3); margin: 0 auto 10px; }
.sheet .sheet-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet .sheet-h h3 { margin: 0; font-size: 20px; }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; width: 600px; bottom: 50%; transform: translate(-50%, 60%) scale(.98); opacity: 0;
    border-radius: 16px; pointer-events: none; transition: transform .22s, opacity .22s; }
  .sheet.on { transform: translate(-50%, 50%); opacity: 1; pointer-events: auto; }
}

.toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -80px); background: var(--label); color: var(--card);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 80; transition: transform .25s;
  max-width: calc(100% - 32px); }
.toast.on { transform: translate(-50%, 0); }

.feed .cell { align-items: flex-start; }
.feed .cell .ic { width: 28px; text-align: center; font-size: 16px; flex-shrink: 0; padding-top: 1px; }
.feed .cell .main { font-size: 14px; white-space: normal; }
.feed .cell + .cell::before { left: 56px; }
.feed time { font-size: 12px; color: var(--label2); flex-shrink: 0; }

.statusline { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin: 0 4px; }
.iconbtn { width: 36px; height: 36px; border-radius: 50%; background: var(--fill); display: inline-flex; align-items: center;
  justify-content: center; }
.iconbtn svg { width: 19px; height: 19px; }
.spacer { height: 10px; }
