/* Sultrix PWA v2.0 — Mobile-first design
   Dark trading-dashboard aesthetic. Compact, touch-friendly, low bandwidth.
*/
:root {
  --bg: #0b0f17;
  --bg-elev: #131a26;
  --bg-card: #1a2333;
  --line: #243149;
  --text: #e6edf3;
  --text-dim: #8b95a7;
  --text-mute: #586472;
  --green: #2ea043;
  --green-soft: rgba(46, 160, 67, 0.12);
  --red: #f85149;
  --red-soft: rgba(248, 81, 73, 0.12);
  --yellow: #d29922;
  --yellow-soft: rgba(210, 153, 34, 0.12);
  --blue: #58a6ff;
  --blue-soft: rgba(88, 166, 255, 0.12);
  --purple: #bc8cff;
  --purple-soft: rgba(188, 140, 255, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 12px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
body { padding-bottom: calc(64px + var(--safe-bottom)); }

a { color: var(--blue); text-decoration: none; }
button {
  font-family: inherit; font-size: inherit; color: inherit;
  background: none; border: none; padding: 0; cursor: pointer;
}

/* ── App shell ─────────────────────────────────── */
.app {
  max-width: 720px; margin: 0 auto;
  padding: var(--safe-top) 12px 12px;
}
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 10px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
  animation: pulse 2.5s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
.brand-dot.idle { background: var(--text-mute); box-shadow: none; animation: none; }
.brand-dot.error { background: var(--red); box-shadow: 0 0 10px var(--red); }

.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  position: relative;
}
.icon-btn:hover { background: var(--bg-elev); color: var(--text); }
.badge-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red);
}

/* ── Cards ─────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: var(--gap);
}
.card-h {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.card-h h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.card-h .sub { font-size: 11px; color: var(--text-mute); }

/* ── KPI tiles ─────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); margin-bottom: var(--gap); }
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi .lbl { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.kpi.green .val { color: var(--green); }
.kpi.red .val { color: var(--red); }
.kpi.big { grid-column: 1 / -1; }
.kpi.big .val { font-size: 30px; }

/* ── Markets grid ───────────────────────────────── */
.markets { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.market {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.market .name { font-size: 11px; color: var(--text-dim); }
.market .status { font-size: 12px; font-weight: 600; margin-top: 2px; }
.market .pnl { font-size: 11px; margin-top: 2px; }
.market.on .status { color: var(--green); }
.market.off .status { color: var(--text-mute); }
.market.on .pnl.green { color: var(--green); }
.market.on .pnl.red { color: var(--red); }

/* ── Positions ─────────────────────────────────── */
.pos { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.pos:last-child { border-bottom: 0; }
.pos .left { display: flex; align-items: center; gap: 10px; }
.pos .sym { font-weight: 700; }
.pos .meta { font-size: 11px; color: var(--text-dim); }
.pos .right { text-align: right; font-variant-numeric: tabular-nums; }
.pos .pnl { font-weight: 600; }
.pos .pnl.green { color: var(--green); }
.pos .pnl.red { color: var(--red); }
.side-tag {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.side-tag.long { background: var(--green-soft); color: var(--green); }
.side-tag.short { background: var(--red-soft); color: var(--red); }
.empty { color: var(--text-mute); font-size: 12px; padding: 12px 0; text-align: center; }

/* ── Agent list ────────────────────────────────── */
.agent { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.agent .info { display: flex; align-items: center; gap: 10px; }
.agent .name { font-weight: 600; }
.agent .hb { font-size: 11px; color: var(--text-mute); }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.ok { background: var(--green); }
.dot.warn { background: var(--yellow); }
.dot.bad { background: var(--red); }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.tag.ok { background: var(--green-soft); color: var(--green); }
.tag.warn { background: var(--yellow-soft); color: var(--yellow); }
.tag.bad { background: var(--red-soft); color: var(--red); }

/* ── Alerts ────────────────────────────────────── */
.alert { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.alert:last-child { border-bottom: 0; }
.alert .sev { width: 4px; border-radius: 2px; flex-shrink: 0; }
.alert .sev.crit { background: var(--red); }
.alert .sev.high { background: var(--orange, #d68b27); }
.alert .sev.med { background: var(--yellow); }
.alert .sev.low { background: var(--blue); }
.alert .body { flex: 1; min-width: 0; }
.alert .title { font-size: 13px; font-weight: 600; }
.alert .meta { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.alert.unread .title::before { content: '●'; color: var(--blue); margin-right: 4px; }

/* ── Tabs (bottom nav) ────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: space-around;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px;
  color: var(--text-mute);
  font-size: 10px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tabbar a.active { color: var(--blue); }
.tabbar .ic { font-size: 18px; line-height: 1; }

/* ── Login screen ───────────────────────────────── */
.login {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 0%, var(--blue-soft) 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 24px;
}
.login .logo { text-align: center; margin-bottom: 16px; }
.login .logo .b1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.login .logo .b2 { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.login .desc { font-size: 12px; color: var(--text-dim); text-align: center; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--blue); }
.btn {
  display: block; width: 100%;
  padding: 12px 14px;
  background: var(--blue);
  color: #0b0f17;
  font-weight: 700;
  border-radius: var(--radius-sm);
  text-align: center;
  margin-top: 8px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--bg-elev); color: var(--text); border: 1px solid var(--line); }
.error-msg { color: var(--red); font-size: 12px; margin-top: 12px; text-align: center; min-height: 18px; }
.hint { font-size: 11px; color: var(--text-mute); text-align: center; margin-top: 16px; }

/* ── Chart area ────────────────────────────────── */
.chart-wrap { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: var(--radius-sm); background: var(--bg-elev); }
.chart-wrap iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
.chart-controls { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.chart-controls select, .chart-controls button {
  padding: 8px 10px; font-size: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.chart-controls select { flex: 1; min-width: 0; }

/* ── Controls / commands ───────────────────────── */
.cmd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cmd-btn {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  color: var(--text);
  font-weight: 600;
  text-align: center;
}
.cmd-btn:active { background: var(--bg-card); }
.cmd-btn:disabled { opacity: 0.4; }
.cmd-btn.danger { color: var(--red); border-color: var(--red-soft); }
.cmd-btn.primary { color: var(--blue); border-color: var(--blue-soft); }

/* ── Connection banner ─────────────────────────── */
.banner {
  background: var(--yellow-soft);
  color: var(--yellow);
  font-size: 12px;
  text-align: center;
  padding: 6px;
  border-bottom: 1px solid var(--line);
}
.banner.error { background: var(--red-soft); color: var(--red); }
.banner.ok { background: var(--green-soft); color: var(--green); }

/* ── Toast ─────────────────────────────────────── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: 13px;
  z-index: 200; opacity: 0; transition: opacity 0.2s;
  pointer-events: none;
  max-width: 90%;
}
.toast.show { opacity: 1; }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); color: var(--green); }

/* ── Spinner ───────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: rot 0.8s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* ── Modal / sheet ─────────────────────────────── */
.sheet-mask {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,0.5);
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-mask.show { display: flex; }
.sheet {
  background: var(--bg-elev);
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  width: 100%; max-width: 480px; max-height: 80vh;
  padding: 16px;
  overflow-y: auto;
  padding-bottom: calc(16px + var(--safe-bottom));
}
.sheet h2 { margin: 0 0 12px; font-size: 16px; }

/* ── Filter chips ─────────────────────────────── */
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; }
.chip {
  padding: 6px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 12px;
  white-space: nowrap;
  color: var(--text-dim);
}
.chip.active { background: var(--blue-soft); color: var(--blue); border-color: var(--blue-soft); }

/* ── Utility ───────────────────────────────────── */
.row { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.muted { color: var(--text-mute); }
.dim { color: var(--text-dim); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Tablet / desktop fallback ────────────────── */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .app { max-width: 960px; padding: 20px; }
  .kpi-row { grid-template-columns: repeat(4, 1fr); }
}

/* ── Tier badge (in header) ────────────────────── */
.tier-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tier-badge.tier-free { background: #2a3a25; color: #a3d977; border: 1px solid #3a5a30; }
.tier-badge.tier-ultra { background: #3a2a5a; color: #c9a3ff; border: 1px solid #5a3a8a; }
.tier-badge.tier-trial { background: #5a4a2a; color: #ffd97a; border: 1px solid #8a6a3a; }
.tier-badge.tier-developer { background: #2a4a5a; color: #7ad4ff; border: 1px solid #3a6a8a; }

/* ── Footer link to sultrixtrade.com ────────────────────── */
.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.app-footer a { color: var(--text-dim); text-decoration: none; }
.app-footer a:hover { color: var(--blue); }
.app-footer .dot { color: var(--text-mute); }

/* ── Secondary button (for free-tier CTA) ────────────────────── */
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  margin-top: 8px;
}
.btn-secondary:hover { background: var(--bg-elev); }

/* ── Chat styles (PWA tab) ────────────────────── */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  min-height: 200px;
  overflow-y: auto;
  padding: 8px 4px;
  margin-bottom: 10px;
}
.chat-msg {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  max-width: 88%;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-user {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.chat-input {
  display: flex;
  gap: 6px;
}
.chat-input input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.chat-input input:focus { outline: none; border-color: var(--blue); }
.chat-input input:disabled { opacity: 0.6; }
