:root { --header-h: 52px; --nav-h: 58px; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #0b0b10; color: #f2f2f5;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  overscroll-behavior-y: none;
}
#app {
  max-width: 480px; margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  min-height: 100vh;
}
.topbar {
  position: sticky; top: env(safe-area-inset-top); z-index: 5;
  height: var(--header-h); box-sizing: border-box;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem; font-weight: 700; font-size: 1.05rem;
  background: #0b0b10;
}
.topbar .brand { color: #f7b731; letter-spacing: .02em; }
.topbar .mode-chip {
  font-size: .7rem; font-weight: 600; padding: .2rem .55rem; border-radius: 999px;
  background: #1c1c24; color: #9a9aa5; border: 1px solid #2a2a33;
}
.topbar .mode-chip.live { color: #ef4444; border-color: #ef444455; }

.view { padding: 0 1rem 1.25rem; display: none; }
.view.active { display: block; }

/* Bot Log fills the space between header and nav exactly, instead of relying on page scroll */
.view#view-log.active {
  display: flex; flex-direction: column;
  position: fixed; left: 0; right: 0; margin: 0 auto; max-width: 480px;
  top: calc(var(--header-h) + env(safe-area-inset-top));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: .75rem 1rem 1rem;
}

.balance-card {
  background: linear-gradient(145deg, #16161d, #0f0f14);
  border: 1px solid #22222c; border-radius: 20px;
  padding: 1.25rem 1.3rem; margin-bottom: 1rem;
}
.balance-card .label { font-size: .8rem; color: #9a9aa5; }
.balance-card .amount { font-size: 2rem; font-weight: 700; margin: .3rem 0; letter-spacing: -0.01em; }
.balance-card .est-idr { font-size: .8rem; color: #9a9aa5; margin: -.15rem 0 .6rem; }
.pill { display: inline-flex; align-items: center; gap: .2rem; font-size: .8rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; }
.pill.pos { background: #16321f; color: #34d058; }
.pill.neg { background: #391a1c; color: #ff5c5c; }
.pill.neutral { background: #1c1c24; color: #9a9aa5; }

.section-title { font-size: .85rem; font-weight: 700; color: #9a9aa5; text-transform: uppercase; letter-spacing: .04em; margin: 1.1rem 0 .5rem; }

.card {
  background: #14141b; border: 1px solid #22222c; border-radius: 16px;
  padding: 1rem 1.1rem; margin-bottom: .7rem;
}
.card-row { display: flex; justify-content: space-between; align-items: center; }
.card-row .k { font-size: .8rem; color: #9a9aa5; }
.card-row .v { font-size: .95rem; font-weight: 600; }
.card .title { font-weight: 700; margin-bottom: .5rem; display: flex; align-items: center; gap: .5rem; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: #6f6f7a; }
.empty-state .emoji { font-size: 2.2rem; margin-bottom: .5rem; }

.spark { width: 100%; height: 60px; display: block; margin: .6rem 0; }

.ticker-card { padding: 1.1rem 1.2rem; }
.ticker-head { display: flex; justify-content: space-between; align-items: center; }
.ticker-symbol { font-weight: 700; font-size: 1rem; letter-spacing: .01em; }
.ticker-price { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.01em; margin-top: .35rem; font-family: "SF Mono", Menlo, Consolas, monospace; }
.ticker-quote { font-size: .95rem; font-weight: 600; color: #6f6f7a; }
.ticker-stats { display: flex; gap: 1.5rem; margin-top: .3rem; padding-top: .8rem; border-top: 1px solid #1c1c24; }
.ticker-stats > div { display: flex; flex-direction: column; gap: .15rem; }
.ticker-stats .k { font-size: .72rem; color: #9a9aa5; }
.ticker-stats .v { font-size: .9rem; font-weight: 600; font-family: "SF Mono", Menlo, Consolas, monospace; }

.candle-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .65rem 1.1rem; border-bottom: 1px solid #1c1c24;
}
.candle-row:last-child { border-bottom: none; }
.candle-row .k { font-size: .8rem; color: #9a9aa5; }
.candle-row .v { font-size: .9rem; font-weight: 600; font-family: "SF Mono", Menlo, Consolas, monospace; }
.candle-row .v.up { color: #34d058; }
.candle-row .v.down { color: #ff5c5c; }

.summary-card { display: flex; justify-content: space-between; padding: 1rem 1.2rem; }
.summary-stat { display: flex; flex-direction: column; align-items: center; gap: .25rem; flex: 1; }
.summary-stat .v { font-size: 1.1rem; font-weight: 700; font-family: "SF Mono", Menlo, Consolas, monospace; }
.summary-stat .v.pos { color: #34d058; } .summary-stat .v.neg { color: #ff5c5c; } .summary-stat .v.neutral { color: #f2f2f5; }
.summary-stat .k { font-size: .7rem; color: #9a9aa5; }

.trade-card { padding: .9rem 1.1rem; }
.trade-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .55rem; }
.trade-head .dir { font-weight: 700; font-size: .8rem; letter-spacing: .02em; }
.trade-head .dir.long { color: #34d058; }
.trade-head .dir.short { color: #ff5c5c; }
.trade-prices {
  display: flex; align-items: baseline; gap: .5rem;
  font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 1rem; font-weight: 600;
  padding-bottom: .6rem; margin-bottom: .55rem; border-bottom: 1px solid #1c1c24;
}
.trade-prices .arrow { color: #6f6f7a; font-size: .85rem; }
.trade-margin { font-size: .75rem; color: #9a9aa5; margin: -.3rem 0 .55rem; font-family: "SF Mono", Menlo, Consolas, monospace; }
.trade-foot { display: flex; justify-content: space-between; align-items: center; }
.trade-foot .pnl { font-weight: 700; font-size: .95rem; }
.trade-foot .pnl.pos { color: #34d058; } .trade-foot .pnl.neg { color: #ff5c5c; }
.trade-foot .meta { font-size: .72rem; color: #6f6f7a; }

.dot-live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #34d058; margin-right: .35rem; box-shadow: 0 0 0 3px #34d05822; }

.bot-control { padding: 1rem 1.1rem; }
.bot-toggle-btn {
  width: 100%; margin-top: .8rem; padding: .75rem; border: none; border-radius: 12px;
  font-family: inherit; font-weight: 700; font-size: .9rem; cursor: pointer;
}
.bot-toggle-btn.start { background: #34d058; color: #05130a; }
.bot-toggle-btn.stop { background: #391a1c; color: #ff5c5c; border: 1.5px solid #ff5c5c55; }
.bot-toggle-btn:disabled { opacity: .5; pointer-events: none; }

.terminal {
  background: #05070a; border: 1px solid #22222c; border-radius: 14px;
  overflow: hidden; display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}
.terminal-bar {
  flex: none;
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .8rem; background: #101218; border-bottom: 1px solid #1c1c24;
}
.terminal-bar .dot { width: 10px; height: 10px; border-radius: 50%; }
.terminal-bar .dot.red { background: #ff5c5c; }
.terminal-bar .dot.yellow { background: #f5c518; }
.terminal-bar .dot.green { background: #34d058; }
.terminal-bar .filename { margin-left: .4rem; font-size: .75rem; color: #6f6f7a; font-family: "SF Mono", Menlo, Consolas, monospace; }
.terminal-body {
  flex: 1; min-height: 0; overflow-y: auto; padding: .7rem .85rem;
  font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .78rem; line-height: 1.5;
}
.term-line { white-space: normal; overflow-wrap: anywhere; cursor: pointer; padding: .1rem 0; }
.term-line .t { color: #565660; }
.term-line .lvl { font-weight: 700; }
.term-line.level-info .lvl { color: #34d058; }
.term-line.level-warn .lvl { color: #f5c518; }
.term-line.level-error .lvl { color: #ff5c5c; }
.term-line .m { color: #d7d7de; }
.term-line.copied .m { color: #f7b731; }
.term-cursor { display: inline-block; width: 6px; height: 1em; background: #34d058; vertical-align: text-bottom; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.settings-item { display: flex; justify-content: space-between; align-items: center; padding: .7rem 0; border-bottom: 1px solid #1c1c24; }
.settings-item:last-child { border-bottom: none; }
.settings-item .k { color: #9a9aa5; font-size: .85rem; }
.settings-item .v { font-weight: 600; font-size: .85rem; font-family: "SF Mono", Menlo, Consolas, monospace; }
.settings-item .v.mode-live { color: #ff5c5c; }
.settings-item .v.mode-paper { color: #34d058; }
.settings-item .v.limit-text { color: #f5c518; }
.settings-note { font-size: .75rem; color: #6f6f7a; margin: 1rem 0 0; line-height: 1.6; padding: 0 .1rem; }
.settings-note code { background: #1c1c24; padding: .1rem .3rem; border-radius: 4px; font-size: .7rem; }

.plan-selector { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .6rem; }
.plan-option {
  text-align: left; background: #14141b; border: 1.5px solid #22222c; border-radius: 14px;
  padding: .8rem 1rem; font-family: inherit; color: #f2f2f5; cursor: pointer;
  display: flex; flex-direction: column; gap: .2rem;
}
.plan-option.active { border-color: #f7b731; background: #1a1710; }
.plan-option.loading { opacity: .5; pointer-events: none; }
.plan-option:disabled { opacity: .45; cursor: not-allowed; }

.leverage-picker { display: flex; gap: .6rem; margin-bottom: .6rem; }
.leverage-option {
  flex: 1; padding: .75rem; border-radius: 12px; border: 1.5px solid #22222c;
  background: #14141b; color: #f2f2f5; font-family: inherit; font-weight: 700; font-size: 1rem; cursor: pointer;
}
.leverage-option.active { border-color: #f7b731; background: #1a1710; color: #f7b731; }
.leverage-option.loading { opacity: .5; pointer-events: none; }
.leverage-option:disabled { opacity: .45; cursor: not-allowed; }
.plan-option-head { font-weight: 700; font-size: .95rem; }
.plan-option-risk { font-size: .72rem; font-weight: 600; color: #9a9aa5; text-transform: uppercase; letter-spacing: .03em; }
.plan-option-desc { font-size: .78rem; color: #9a9aa5; line-height: 1.4; margin-top: .15rem; }
.plan-option.active .plan-option-risk { color: #f7b731; }

nav.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 480px; margin: 0 auto;
  display: flex; background: rgba(15,15,20,0.92); backdrop-filter: blur(14px);
  border-top: 1px solid #22222c;
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabbar button {
  flex: 1; background: none; border: none; color: #6f6f7a;
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  padding: .55rem 0 .5rem; font-size: .65rem; font-family: inherit;
}
nav.tabbar button .icon { font-size: 1.25rem; }
nav.tabbar button.active { color: #f7b731; }

/* ---- Wide screens (tablet landscape, desktop): left sidebar nav + 2-column cards ---- */
@media (min-width: 760px) {
  #app {
    max-width: 1100px;
    padding-left: 220px;
    padding-bottom: 2rem;
  }
  nav.tabbar {
    top: 0; bottom: 0; right: auto; left: 0; margin: 0;
    width: 220px; max-width: 220px;
    flex-direction: column; justify-content: flex-start;
    gap: .2rem;
    padding-top: calc(var(--header-h) + env(safe-area-inset-top) + 1rem);
    padding-bottom: 1rem;
    border-top: none; border-right: 1px solid #22222c;
  }
  nav.tabbar button {
    flex-direction: row; justify-content: flex-start; gap: .8rem;
    padding: .75rem 1.3rem; font-size: .85rem;
  }
  nav.tabbar button .icon { font-size: 1.15rem; }

  .view.active:not(#view-log) {
    column-count: 2; column-gap: 1rem;
  }
  .view.active:not(#view-log) > * { break-inside: avoid; }

  .view#view-log.active {
    left: 220px; right: 0; margin: 0; max-width: none;
    bottom: 2rem;
  }
}
