/* ===== Design Tokens ===== */
:root {
  --bg:       #0D0D0F;
  --surface:  #1A1A1E;
  --elevated: #242428;
  --border:   rgba(255,255,255,0.06);
  --text:     rgba(255,255,255,0.92);
  --text2:    #8E8E93;
  --text3:    #636366;
  --text4:    #48484A;
  --green:    #00C087;
  --green-bg: rgba(0,192,135,0.12);
  --red:      #FF4D4D;
  --red-bg:   rgba(255,77,77,0.12);
  --blue:     #3B82F6;
  --blue-bg:  rgba(59,130,246,0.12);
  --amber:    #FFB800;
  --amber-bg: rgba(255,184,0,0.12);
  --r:        16px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== Pages ===== */
.page { display: none; padding: 0 16px 24px; }
.page.active { display: block; }

.page-header {
  font-size: 20px;
  font-weight: 700;
  padding: 20px 0 16px;
}

/* ===== Tab Bar ===== */
#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(20,20,22,0.92);
  border-top: 1px solid var(--border);
  padding: 2px 4px calc(6px + env(safe-area-inset-bottom, 8px));
  z-index: 200;
  max-width: 430px;
  margin: 0 auto;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.tb {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text3);
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  padding: 10px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  min-height: 52px;
}
.tb svg { width: 22px; height: 22px; flex-shrink: 0; }
.tb.active { color: var(--blue); }
.tb:active { opacity: 0.6; }

/* ===== Hero (Dashboard) ===== */
.hero {
  padding: 24px 0 4px;
  text-align: center;
}
.hero-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 4px;
}
.hero-value {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
}
.hero-change {
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
  color: var(--text2);
}
.hero-dot { margin: 0 4px; opacity: 0.4; }

/* ===== Chart ===== */
.chart-wrap {
  position: relative;
  margin: 16px 0 0;
  height: 180px;
}
.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.chart-labels {
  position: absolute;
  top: 0; left: 16px;
  right: 16px; bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  pointer-events: none;
}

/* Period Pills */
.pill-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 12px 0 0;
}
.pill {
  background: var(--surface);
  border: none;
  border-radius: 20px;
  color: var(--text2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}
.pill.active {
  background: var(--blue-bg);
  color: var(--blue);
}
.pill:active { transform: scale(0.95); }

/* ===== Section Title ===== */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 24px 0 12px;
}

/* ===== KPI Grid ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  overflow: hidden;
}
.kpi {
  background: var(--surface);
  border-radius: var(--r);
  padding: 16px;
}
.kpi-val {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}
.kpi-lbl {
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
}

/* ===== Colors ===== */
.up { color: var(--green); }
.dn { color: var(--red); }
.flat { color: var(--text2); }

/* ===== Position Cards ===== */
.pos-card {
  background: var(--surface);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 8px;
}
.pos-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.pos-left { display: flex; align-items: center; gap: 10px; }
.pos-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}
.pos-icon.long  { background: var(--green-bg); color: var(--green); }
.pos-icon.short { background: var(--red-bg);   color: var(--red); }
.pos-name { font-size: 15px; font-weight: 600; }
.pos-side-label { font-size: 12px; color: var(--text2); }
.pos-right { text-align: right; }
.pos-upl { font-size: 16px; font-weight: 700; }
.pos-upl-pct { font-size: 12px; font-weight: 500; }

.pos-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}
.pos-m-item {}
.pos-m-lbl { font-size: 11px; color: var(--text3); }
.pos-m-val { font-size: 13px; font-weight: 600; margin-top: 1px; }

/* ===== PnL Cards ===== */
.pnl-card {
  background: var(--surface);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 8px;
}
.pnl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.pnl-period { font-size: 15px; font-weight: 700; }
.pnl-total { font-size: 18px; font-weight: 700; }

.pnl-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.pnl-s { text-align: center; }
.pnl-s-val { font-size: 14px; font-weight: 700; }
.pnl-s-lbl { font-size: 10px; font-weight: 500; color: var(--text3); margin-top: 2px; }

/* ===== Regime Cards ===== */
.regime-card {
  background: var(--surface);
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.regime-left { display: flex; align-items: center; gap: 12px; }
.regime-coin {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--elevated);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--text2);
}
.regime-name { font-size: 15px; font-weight: 600; }
.regime-conf {
  font-size: 11px; color: var(--text3); margin-top: 2px;
  display: flex; align-items: center; gap: 6px;
}
.conf-track {
  width: 40px; height: 3px;
  background: var(--elevated);
  border-radius: 2px;
  overflow: hidden;
}
.conf-fill { height: 100%; border-radius: 2px; }
.regime-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-trending_up   { background: var(--green-bg); color: var(--green); }
.badge-trending_down { background: var(--red-bg);   color: var(--red); }
.badge-ranging       { background: rgba(142,142,147,0.12); color: var(--text2); }
.badge-volatile      { background: var(--amber-bg); color: var(--amber); }
.badge-unknown       { background: rgba(142,142,147,0.08); color: var(--text3); }

/* Regime enhancements */
.regime-indicators {
  display: flex;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  margin-top: 3px;
}
.regime-right-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.pos-badge {
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}
.remove-sym-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text3);
  font-size: 11px;
  font-weight: 700;
  width: 24px; height: 24px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}
.remove-sym-btn:active { color: var(--red); border-color: var(--red); }

/* Add symbol */
.add-symbol-btn {
  background: var(--blue);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  width: 36px; height: 36px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.add-symbol-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

/* ===== Trade Rows ===== */
.trades-date {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  padding: 16px 0 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.trades-date:first-child { padding-top: 0; }
.day-sum { font-size: 12px; font-weight: 700; }

.trade-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.trade-row:last-child { border-bottom: none; }
.trade-row.selected {
  background: rgba(59,130,246,0.08);
  border-radius: 8px;
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
}
.trade-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 12px;
}
.dot-win  { background: var(--green); box-shadow: 0 0 8px rgba(0,192,135,0.3); }
.dot-loss { background: var(--red);   box-shadow: 0 0 8px rgba(255,77,77,0.3); }
.trade-info { flex: 1; min-width: 0; }
.trade-sym { font-size: 14px; font-weight: 600; }
.trade-sym-side { font-size: 12px; color: var(--text3); font-weight: 400; margin-left: 4px; }
.trade-meta { font-size: 12px; color: var(--text3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trade-right { text-align: right; flex-shrink: 0; margin-left: 12px; }
.trade-pnl { font-size: 15px; font-weight: 700; }
.trade-r { font-size: 11px; color: var(--text3); margin-top: 1px; }

/* Trade Detail (expand) */
.trade-detail {
  width: 100%;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.trade-row.expanded .trade-detail {
  max-height: 220px;
}
.td-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  padding: 10px 0 4px 22px;
}
.td-item { display: flex; flex-direction: column; }
.td-lbl { font-size: 10px; color: var(--text3); font-weight: 500; }
.td-val { font-size: 12px; font-weight: 600; color: var(--text2); margin-top: 1px; }

/* Selection Bar */
.selection-bar {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  left: 0; right: 0;
  max-width: 430px;
  margin: 0 auto;
  background: var(--elevated);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 199;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}
.selection-bar.visible {
  transform: translateY(0);
}
.sel-text { font-size: 14px; font-weight: 700; }
.sel-close {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Date Range (Phase 3) ===== */
.date-range-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.date-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  outline: none;
  -webkit-appearance: none;
  color-scheme: dark;
}
.date-input:focus {
  border-color: var(--blue);
}
.date-sep {
  color: var(--text3);
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ===== Empty State ===== */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text2);
  font-size: 15px;
  font-weight: 500;
}
.empty-icon { color: var(--text4); margin-bottom: 12px; }
.empty-sub { font-size: 13px; color: var(--text3); margin-top: 4px; }

/* ===== Settings ===== */
.settings-toggle {
  background: var(--surface);
  border-radius: var(--r);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.stg-label { font-size: 15px; font-weight: 600; }
.stg-hint { font-size: 12px; color: var(--text3); margin-top: 2px; }

.toggle-btn {
  width: 50px; height: 28px;
  border-radius: 14px;
  border: none;
  background: var(--elevated);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.toggle-btn.on { background: var(--green); }
.toggle-knob {
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle-btn.on .toggle-knob { transform: translateX(22px); }

/* Status row: mode badge + bot times */
.stg-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.mode-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.mode-paper { background: var(--amber-bg); color: var(--amber); }
.mode-live  { background: var(--green-bg); color: var(--green); }

.stg-bot-times {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--text3);
  font-weight: 500;
}

/* Trigger Button */
.trigger-btn {
  width: 100%;
  padding: 14px;
  margin-top: 12px;
  border: none;
  border-radius: var(--r);
  background: var(--blue);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s, background 0.15s;
}
.trigger-btn:active { opacity: 0.8; }
.trigger-btn:disabled {
  background: var(--blue-bg);
  color: var(--blue);
  cursor: default;
}

.param-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.param-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--elevated);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.param-btn:active { background: var(--blue-bg); color: var(--blue); }
.param-cur {
  font-size: 15px;
  font-weight: 700;
  min-width: 56px;
  text-align: center;
}

/* ===== Loading Pulse ===== */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.loading { animation: pulse 1.5s ease-in-out infinite; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 0; }
