/* Grid Dashboard — mobile-first styles. Palette isolated from cockpit. */
:root {
  --bg: #0b0d12;
  --bg2: #14171e;
  --bg3: #1c2029;
  --fg: #e5e9f0;
  --fg2: #9ba3b3;
  --border: #2a2f3a;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --blue: #60a5fa;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
#app { min-height: 100vh; display: flex; flex-direction: column; }

.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.header .brand { font-weight: 700; font-size: 18px; }
.header .actions { display: flex; gap: 12px; font-size: 14px; color: var(--fg2); }

.tabs {
  display: flex; overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  scrollbar-width: none;
  position: sticky; top: 0; z-index: 10;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  padding: 14px 16px;
  font-size: 15px;
  color: var(--fg2);
  border: none; background: transparent; cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--fg); border-bottom-color: var(--blue); }
.tab .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-left: 6px; vertical-align: middle;
}
.tab .dot.win { background: var(--green); }
.tab .dot.loss { background: var(--red); }
.tab .dot.idle { background: var(--fg2); opacity: 0.4; }
.tab .dot.closing { background: var(--yellow); }

.view { padding: 16px; }
.view h2 { font-size: 14px; color: var(--fg2); margin: 24px 0 8px; font-weight: 500; }

.kpi { text-align: center; padding: 24px 0; }
.kpi .label { font-size: 13px; color: var(--fg2); letter-spacing: 1px; }
.kpi .pnl { font-size: 36px; font-weight: 700; margin-top: 8px; }
.kpi .pnl.pos { color: var(--green); }
.kpi .pnl.neg { color: var(--red); }
.kpi .pct { font-size: 16px; color: var(--fg2); margin-top: 4px; }

.summary { text-align: center; font-size: 14px; color: var(--fg2); margin: 16px 0; }

.cards-grid { display: grid; grid-template-columns: 1fr; gap: 0; }

.card {
  padding: 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s, border-color 0.15s;
}
.card:hover { background: rgba(255,255,255,0.02); }
.card:active { background: var(--bg3); }
.card .row { display: flex; justify-content: space-between; align-items: baseline; }
.card .asset { font-weight: 600; font-size: 16px; }
.card .pnl-small { font-size: 16px; font-weight: 600; }
.card .pnl-small.pos { color: var(--green); }
.card .pnl-small.neg { color: var(--red); }
.card .meta { font-size: 13px; color: var(--fg2); margin-top: 4px; }

.progress-bi {
  position: relative;
  height: 8px;
  background: linear-gradient(to right,
    rgba(248,113,113,0.3) 0%, rgba(248,113,113,0.3) 50%,
    rgba(74,222,128,0.3) 50%, rgba(74,222,128,0.3) 100%);
  border-radius: 4px;
  margin: 8px 0;
}
.progress-bi .needle {
  position: absolute; top: -4px;
  width: 2px; height: 16px;
  background: var(--fg);
  border-radius: 1px;
}
.progress-bi .labels {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--fg2); margin-top: 4px;
}

.detail-head { padding: 16px; border-bottom: 1px solid var(--border); }
.detail-head h1 { font-size: 18px; margin: 0 0 4px; font-weight: 600; }
.detail-head .meta { font-size: 13px; color: var(--fg2); }

.hero {
  padding: 24px 16px;
  text-align: center;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.hero .label { font-size: 13px; color: var(--fg2); letter-spacing: 1px; }
.hero .pnl { font-size: 44px; font-weight: 700; margin: 8px 0 4px; }
.hero .pnl.pos { color: var(--green); }
.hero .pnl.neg { color: var(--red); }
.hero .pct { font-size: 18px; color: var(--fg2); margin-bottom: 16px; }
.hero .meta { font-size: 13px; color: var(--fg2); margin-top: 12px; }

.grid-visual { font-family: "SF Mono", Menlo, monospace; font-size: 13px; }
.grid-visual .price-now { color: var(--blue); margin-bottom: 8px; }
.grid-visual .level { display: flex; gap: 8px; padding: 4px 0; }
.grid-visual .level .price { flex: 0 0 80px; color: var(--fg2); }
.grid-visual .level .sym { flex: 0 0 20px; text-align: center; }
.grid-visual .level .tag { color: var(--fg2); font-size: 12px; }
.grid-visual .level.buy .sym { color: var(--green); }
.grid-visual .level.sell .sym { color: var(--red); }
.grid-visual .level.pending .sym { color: var(--fg2); opacity: 0.6; }
.grid-visual .legend { font-size: 11px; color: var(--fg2); margin-top: 8px; }

.settings { padding: 8px 0; }
.settings label { display: block; font-size: 14px; margin-bottom: 8px; }
.settings input[type=range] { width: 100%; }

.history .hist-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.history .tag { font-size: 12px; color: var(--fg2); }

.btn {
  display: block;
  padding: 12px 20px;
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  text-align: center;
  width: 100%;
  margin: 8px 0;
}
.btn:active { background: var(--border); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { color: var(--red); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px; width: 100%;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 12px; font-size: 18px; }
.modal ul { padding-left: 20px; margin: 8px 0; }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .actions .btn { margin: 0; }

.killswitch {
  position: sticky;
  bottom: 16px;
  margin: 24px 16px;
  padding: 14px;
  background: rgba(248,113,113,0.1);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 8px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.loading {
  text-align: center; padding: 48px 16px;
  color: var(--fg2);
}

/* ─── Desktop layout ──────────────────────────────────────────── */

/* Detail-view bottom: grid visual + settings/history side-by-side on desktop */
.detail-bottom { display: grid; grid-template-columns: 1fr; gap: 24px; margin-top: 8px; }

@media (min-width: 768px) {
  .view { padding: 24px; max-width: 900px; margin: 0 auto; }
  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .card { border-top: none; border: 1px solid var(--border); border-radius: 12px; background: var(--bg2); }
  .cards-grid .card:hover { border-color: var(--blue); background: var(--bg2); transform: translateY(-1px); }
}

@media (min-width: 1024px) {
  .view { max-width: 1200px; padding: 32px 40px; }
  .cards-grid { grid-template-columns: repeat(3, 1fr); gap: 20px; }
  .detail-bottom { grid-template-columns: 3fr 2fr; gap: 32px; }

  /* Bigger KPIs on desktop */
  .kpi { padding: 32px 0; }
  .kpi .pnl { font-size: 52px; }
  .kpi .pct { font-size: 20px; }

  /* Hero: richer spacing */
  .hero { padding: 40px 24px; }
  .hero .pnl { font-size: 64px; }
  .hero .pct { font-size: 22px; }

  /* Detail head & sections breathe more */
  .detail-head h1 { font-size: 22px; }
  .view h2 { font-size: 15px; margin: 32px 0 12px; }

  /* Grid visual: two columns of levels if there are many */
  .grid-visual { font-size: 14px; }
  .grid-visual .level { padding: 5px 0; }

  /* Button: inline size on desktop, centered with max width */
  .hero .btn { max-width: 320px; margin: 12px auto 0; }
  .settings { max-width: 420px; }

  /* Killswitch: not sticky on desktop (plenty of scroll room) */
  .killswitch { position: static; max-width: 400px; margin: 40px auto; }

  /* History rows: a touch more spacing */
  .history .hist-row { padding: 12px 0; font-size: 15px; }
}

@media (min-width: 1400px) {
  .view { max-width: 1320px; }
}
