/* TradingBot PWA — Dark mobile-first theme */
:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --border:     #2d3150;
  --text:       #e8eaf0;
  --text-dim:   #7a7f9a;
  --green:      #00d4aa;
  --red:        #ff4d6d;
  --yellow:     #ffd166;
  --blue:       #4dabf7;
  --radius:     12px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --header-h:   56px;
  --nav-h:      60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ---- Layout ---- */
#app { display: flex; flex-direction: column; height: 100dvh; }

header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 { font-size: 18px; font-weight: 700; flex: 1; }
header h1 span { color: var(--green); }

#market-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#market-badge.open  { background: rgba(0,212,170,0.15); color: var(--green); }
#market-badge.closed { background: rgba(255,77,109,0.15); color: var(--red); }

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + 16px);
}

nav {
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  position: sticky;
  bottom: 0;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: none;
  transition: color 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.nav-tab svg { width: 22px; height: 22px; }
.nav-tab.active { color: var(--green); }
.nav-tab .badge {
  position: absolute;
  top: 8px;
  right: calc(50% - 18px);
  background: var(--red);
  color: white;
  font-size: 9px;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}

/* ---- Pages ---- */
.page { display: none; }
.page.active { display: block; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* ---- Portfolio ---- */
.equity-display {
  text-align: center;
  padding: 24px 0 16px;
}
.equity-display .label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.equity-display .value { font-size: 36px; font-weight: 700; margin: 4px 0; }
.equity-display .pnl   { font-size: 14px; }
.pnl.positive { color: var(--green); }
.pnl.negative { color: var(--red); }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.stat-box {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
}
.stat-box .label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }
.stat-box .value { font-size: 18px; font-weight: 700; margin-top: 2px; }

.position-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.position-row:last-child { border-bottom: none; }
.position-sym  { font-weight: 700; font-size: 15px; }
.position-meta { font-size: 12px; color: var(--text-dim); }

/* ---- Signal Cards ---- */
.signal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
}
.signal-card.buy  { border-left: 4px solid var(--green); }
.signal-card.sell { border-left: 4px solid var(--red); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.signal-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.signal-symbol { font-size: 22px; font-weight: 700; }
.signal-dir    { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.signal-dir.buy  { background: rgba(0,212,170,0.15); color: var(--green); }
.signal-dir.sell { background: rgba(255,77,109,0.15); color: var(--red); }

.signal-score-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  margin-bottom: 12px;
  overflow: hidden;
}
.signal-score-fill { height: 100%; border-radius: 3px; transition: width 0.5s; }
.signal-score-fill.buy  { background: var(--green); }
.signal-score-fill.sell { background: var(--red); }

.signal-levels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.level-box { text-align: center; background: var(--surface2); border-radius: 8px; padding: 8px; }
.level-box .label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; }
.level-box .value { font-size: 14px; font-weight: 700; margin-top: 2px; }
.level-box .value.entry  { color: var(--blue); }
.level-box .value.stop   { color: var(--red); }
.level-box .value.target { color: var(--green); }

.signal-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.meta-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text-dim);
}
.meta-pill.highlight { background: rgba(77,171,247,0.12); color: var(--blue); }

.signal-actions { display: flex; gap: 10px; }
.btn {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.3px;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn-approve { background: var(--green); color: #000; }
.btn-reject  { background: var(--surface2); color: var(--red); border: 1px solid var(--red); }

/* ---- Reasons accordion ---- */
.reasons-toggle {
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  user-select: none;
}
.reasons-list {
  display: none;
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
}
.reasons-list.open { display: block; }

/* ---- History ---- */
.hist-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.hist-row:last-child { border-bottom: none; }
.hist-sym { font-weight: 700; width: 60px; }
.hist-status {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  font-weight: 600;
}
.hist-status.approved { background: rgba(0,212,170,0.15); color: var(--green); }
.hist-status.rejected { background: rgba(255,77,109,0.12); color: var(--red); }
.hist-status.pending  { background: rgba(255,209,102,0.15); color: var(--yellow); }
.hist-status.executed { background: rgba(77,171,247,0.15); color: var(--blue); }

/* ---- Risk Monitor ---- */
.risk-bar-wrap { margin: 8px 0 14px; }
.risk-bar-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; color: var(--text-dim); }
.risk-bar { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.risk-bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s; }
.risk-bar-fill.low  { background: var(--green); }
.risk-bar-fill.mid  { background: var(--yellow); }
.risk-bar-fill.high { background: var(--red); }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 17px; margin-bottom: 8px; color: var(--text); }
.empty-state p  { font-size: 14px; line-height: 1.5; }

/* ---- Loading spinner ---- */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 999;
  white-space: nowrap;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
