:root {
  color-scheme: dark;
  --bg: #081018;
  --surface: #111c26;
  --surface-2: #172532;
  --stroke: #203343;
  --text: #f2f6f8;
  --muted: #8193a6;
  --green: #25c38b;
  --red: #ef5d68;
  --amber: #f3b546;
  --blue: #4b9cff;
  --cyan: #25cfc2;
  --radius: 8px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

body {
  padding: env(safe-area-inset-top) 0 calc(64px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(8, 16, 24, 0.96);
}

.brand {
  font-size: 17px;
  font-weight: 700;
}

.muted {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.badge.live, .positive {
  color: var(--green);
}

.badge.pause, .warning {
  color: var(--amber);
}

.badge.danger, .negative {
  color: var(--red);
}

.badge.neutral {
  color: var(--muted);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 23px;
  line-height: 1;
}

.page {
  padding: 12px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.notice {
  padding: 12px;
  margin-bottom: 12px;
  border-radius: var(--radius);
}

.notice.error {
  border: 1px solid #69343b;
  background: #22171c;
  color: #ffb4bd;
}

.notice.success {
  border: 1px solid #175c47;
  background: #10231e;
  color: #7be4ba;
}

.hidden {
  display: none;
}

.summary {
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.status {
  font-size: 15px;
  font-weight: 700;
}

.status.active {
  color: var(--green);
}

.status.paused {
  color: var(--amber);
}

.status.safety {
  color: var(--red);
}

.balance {
  font-size: 30px;
  line-height: 1.1;
  font-weight: 700;
}

.balance-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.metric {
  min-height: 70px;
  padding: 10px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 7px;
  font-size: 18px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.section-title {
  margin: 17px 2px 10px;
  color: #cbd6df;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.controls {
  margin-bottom: 14px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.command {
  min-height: 43px;
  padding: 8px 9px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}

.command:disabled {
  opacity: 0.38;
}

.positive-button {
  border-color: #167354;
  color: #7be4ba;
}

.warning-button {
  border-color: #866225;
  color: #ffd27c;
}

.danger-outline {
  border-color: #73333c;
  color: #ffb2ba;
}

.danger-button {
  border-color: #8e3844;
  background: #301a20;
  color: #ffbec5;
}

.secondary-button {
  background: var(--surface-2);
  color: var(--muted);
}

.card {
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--surface);
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.symbol {
  font-size: 15px;
  font-weight: 700;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.pnl {
  font-size: 15px;
  font-weight: 700;
  text-align: right;
}

.levels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  padding-top: 11px;
  margin-top: 10px;
  border-top: 1px solid var(--stroke);
  font-size: 12px;
  color: var(--muted);
}

.levels strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 13px;
}

.position-close {
  width: 100%;
  min-height: 38px;
  margin-top: 12px;
  border: 1px solid #73333c;
  border-radius: var(--radius);
  background: transparent;
  color: #ffb2ba;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}

.position-close:disabled {
  opacity: 0.42;
}

.chart {
  display: block;
  width: 100%;
  aspect-ratio: 1.82;
  object-fit: contain;
  margin: 12px 0 2px;
  border: 1px solid #172631;
  border-radius: 6px;
  background: #081018;
}

.chart-slot {
  width: 100%;
  aspect-ratio: 1.82;
  margin: 12px 0 2px;
}

.chart-slot .chart {
  height: 100%;
  margin: 0;
}

.chart-loading {
  width: 100%;
  height: 100%;
  aspect-ratio: 1.82;
  border: 1px solid #172631;
  border-radius: 6px;
  background: linear-gradient(100deg, #0b151e 25%, #122330 42%, #0b151e 59%);
  background-size: 220% 100%;
  animation: chart-loading 1.1s ease-in-out infinite;
}

@keyframes chart-loading {
  to {
    background-position-x: -220%;
  }
}

.row-list {
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--stroke);
}

.list-row:last-child {
  border-bottom: 0;
}

.outcome {
  font-weight: 650;
  text-align: right;
}

.health-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--stroke);
}

.health-row:last-child {
  border: 0;
}

.strategy-rule {
  padding-top: 9px;
  line-height: 1.45;
}

.issue {
  padding: 10px;
  margin-top: 8px;
  border-left: 3px solid var(--red);
  background: #21171c;
  color: #ffc0c6;
  font-size: 13px;
}

.empty {
  padding: 20px 12px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  background: var(--surface);
}

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: 58px;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--stroke);
  background: #0b151e;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  background: rgba(3, 8, 12, 0.7);
}

.modal.hidden {
  display: none;
}

.modal-sheet {
  width: min(100%, 520px);
  padding: 16px;
  margin: 0 auto;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--surface);
}

.modal-sheet h2 {
  margin: 0 0 9px;
  font-size: 17px;
}

.modal-sheet p {
  margin: 0 0 16px;
  color: #c2cfda;
  line-height: 1.45;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 8px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tab.active {
  color: var(--blue);
  border-top: 2px solid var(--blue);
}
