/* Telegram Mini App look + browser fallback.
 * All colours come from `tma.js` which writes theme params into CSS vars.
 * Fallbacks below match Telegram's default light theme.
 */
:root {
  --tg-bg: #ffffff;
  --tg-text: #000000;
  --tg-hint: #707579;
  --tg-link: #2481cc;
  --tg-button: #2481cc;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f4f4f5;
  --tg-section-bg: #ffffff;
  --tg-section-sep: #c8c7cc;
  --tg-accent: #2481cc;
  --tg-destructive: #ff3b30;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--tg-link); text-decoration: none; }

.page {
  padding: 12px max(12px, env(safe-area-inset-left))
           max(20px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
  max-width: 720px;
  margin: 0 auto;
}

/* ── tabs ─────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  background: var(--tg-bg);
  border-bottom: 0.5px solid var(--tg-section-sep);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tabs a {
  flex: 1;
  padding: 12px 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--tg-hint);
  border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--tg-accent); border-bottom-color: var(--tg-accent); }

.mode-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  flex: 0 0 auto;
  align-self: center;
  margin: 0 8px;
}
.mode-paper {
  background: rgba(36, 129, 204, 0.12);
  color: var(--tg-accent);
}
.mode-live {
  background: rgba(255, 59, 48, 0.12);
  color: var(--tg-destructive);
}

/* ── cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--tg-section-bg);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 0 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--tg-hint);
  letter-spacing: 0.04em;
  margin: 0 0 8px;
}

/* ── stat row (e.g. KPI grid) ─────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label {
  font-size: 12px;
  color: var(--tg-hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-value {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat-value.positive,
.positive { color: #34c759; }
.stat-value.negative,
.negative { color: var(--tg-destructive); }

/* ── status dot ───────────────────────────────────────────────────── */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
}
.dot-live { background: #34c759; }
.dot-paused { background: var(--tg-destructive); }

/* ── pipeline flow (used by cycle summary) ────────────────────────── */
.flow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.flow-step {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}
.flow-step .n {
  font-size: 18px;
  font-weight: 600;
}
.flow-step .l {
  font-size: 12px;
  color: var(--tg-hint);
  text-transform: uppercase;
}
.flow-arrow {
  color: var(--tg-hint);
  font-size: 14px;
}

/* ── lists ────────────────────────────────────────────────────────── */
.list { margin: 0; padding: 0; list-style: none; }
.list li {
  padding: 8px 0;
  border-bottom: 0.5px solid var(--tg-section-sep);
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.list li:last-child { border-bottom: 0; }
.list .market { color: var(--tg-text); flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--tg-hint); font-size: 13px; }

/* ── tables ───────────────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--tg-hint);
  font-weight: 500;
  padding: 8px 6px;
  border-bottom: 0.5px solid var(--tg-section-sep);
  white-space: nowrap;
}
td {
  padding: 8px 6px;
  border-bottom: 0.5px solid var(--tg-section-sep);
  white-space: nowrap;
}
td.num { text-align: right; }
td.positive { color: #34c759; }
td.negative { color: var(--tg-destructive); }

/* ── row-cards (mobile-friendly alternative to wide tables) ───────── */
.row-card {
  background: var(--tg-section-bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 8px;
}
.row-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.row-card-title {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 500;
  word-break: break-word;
}
.row-card-pnl {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 15px;
}
.row-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--tg-hint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.row-card-meta b { color: var(--tg-text); font-weight: 500; }
.row-card-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── health card ──────────────────────────────────────────────────── */
.health-status {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: middle;
}
.health-ok       { background: rgba(52, 199, 89, 0.16);  color: #34c759; }
.health-warning  { background: rgba(255, 149, 0, 0.16);  color: #ff9500; }
.health-critical { background: rgba(255, 59, 48, 0.16);  color: var(--tg-destructive); }

.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 0.5px solid var(--tg-section-sep);
  font-size: 14px;
}
.check-list li:last-child { border-bottom: 0; }
.check-name { color: var(--tg-text); }
.check-detail {
  color: var(--tg-hint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.check-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.check-ok       { background: #34c759; }
.check-warning  { background: #ff9500; }
.check-critical { background: var(--tg-destructive); }

/* ── risk knob row ────────────────────────────────────────────────── */
.knob-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.knob-name {
  font-size: 15px;
  font-weight: 500;
}
.knob-key {
  font-size: 11px;
  color: var(--tg-hint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.knob-desc {
  margin-top: 2px;
  color: var(--tg-hint);
  font-size: 12px;
  line-height: 1.35;
}
.knob-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.knob-form input { flex: 1; max-width: 160px; }

/* ── buttons ──────────────────────────────────────────────────────── */
button, .btn {
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
button.danger { background: var(--tg-destructive); }
button.ghost {
  background: transparent;
  color: var(--tg-accent);
  border: 1px solid var(--tg-accent);
}
button:disabled { opacity: 0.5; cursor: default; }

/* ── form inputs ──────────────────────────────────────────────────── */
input[type=number], input[type=text] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--tg-section-sep);
  border-radius: 8px;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.row label { flex: 1; }

/* ── empty state ──────────────────────────────────────────────────── */
.empty {
  color: var(--tg-hint);
  text-align: center;
  padding: 20px 12px;
  font-size: 14px;
}

/* ── login page ───────────────────────────────────────────────────── */
.login-card {
  max-width: 420px;
  margin: 80px auto;
  text-align: center;
  background: var(--tg-section-bg);
  border-radius: 12px;
  padding: 24px;
}
