:root {
  --bg: #0a111b;
  --surface: #0f1825;
  --surface-2: #122033;
  --text: #e8edf5;
  --muted: #9eb0c9;
  --line: #233247;
  --brand: #2d7dd2;
  --ok: #2fbf71;
  --warn: #f2b138;
  --danger: #f25f5c;
  --app-vh: 100dvh;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: var(--app-vh);
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Source Sans 3", "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--text);
  background: radial-gradient(circle at top, #13233a 0%, #0a111b 45%);
}

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

.shell {
  max-width: none;
  width: 100%;
  max-width: 100vw;
  margin: 0 auto;
  padding: calc(6px + env(safe-area-inset-top)) 8px calc(6px + env(safe-area-inset-bottom));
  height: var(--app-vh);
  min-height: var(--app-vh);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  overflow-x: hidden;
}

.page-content {
  flex: 1;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  overflow: hidden;
  display: grid;
  gap: 8px;
  grid-auto-rows: min-content;
}

.page-content.scrollable {
  overflow: auto;
}

.page-content.table-page {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.page-content.table-page > .card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  min-height: 44px;
}

.account-mode-banner {
  border-radius: 8px;
  padding: 4px 10px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.account-mode-banner.paper {
  background: #4a3a09;
  color: #ffd97a;
  border-color: #7a6210;
}

.account-mode-banner.live {
  background: #12321f;
  color: #7ef2a6;
  border-color: #1f5c3f;
}

.nav-links {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.nav-links a {
  width: 30px;
  height: 30px;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
}

.nav-links a.active {
  border-color: var(--line);
  background: var(--surface-2);
}

.profile {
  position: relative;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  background: #1b2d45;
  font-size: 14px;
  cursor: pointer;
}

.profile-menu {
  position: absolute;
  right: 0;
  top: 38px;
  width: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px;
  font-size: 15px;
  display: none;
  z-index: 5;
}

.profile.open .profile-menu {
  display: block;
}

.page-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 8px 0 14px;
}

.page-title h1 {
  margin: 0;
  font-size: 24px;
}

.page-title .meta {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 12px;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.card.tight {
  padding: 8px;
}

.card h2,
.card h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.strategy-grid {
  display: grid;
  gap: 8px;
}

.strategy-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px;
}

.strategy-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.strategy-name {
  font-weight: 700;
}

.strategy-kv {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.strategy-kv > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.strategy-kv span {
  color: var(--muted);
}

.status-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.micro-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.micro {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 4px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  min-height: 28px;
  font-weight: 700;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.status-dot.green {
  background: #2fbf71;
  box-shadow: 0 0 0 2px rgba(47,191,113,0.25);
}

.status-dot.red {
  background: #f25f5c;
  box-shadow: 0 0 0 2px rgba(242,95,92,0.25);
}

.incident-strip {
  border: 1px solid #6b4a17;
  background: #34270f;
  color: #ffd17d;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
}

.graph-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #122033 0%, #0e1a2a 100%);
  height: min(36vh, 300px);
  position: relative;
  overflow: hidden;
}

.graph-lines {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(158,176,201,0.08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(158,176,201,0.08) 1px, transparent 1px);
  background-size: 26px 26px;
}

#chart-plot {
  touch-action: none;
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid transparent;
}

.pill.ok {
  background: #143223;
  color: var(--ok);
  border-color: #1f5c3f;
}

.pill.warn {
  background: #34270f;
  color: var(--warn);
  border-color: #6b4a17;
}

.pill.danger {
  background: #371517;
  color: var(--danger);
  border-color: #703034;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--surface-2);
}

.metric .k {
  color: var(--muted);
  font-size: 13px;
}

.metric .v {
  margin-top: 2px;
  font-size: 16px;
  font-weight: 700;
}

.dash-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed;
}

.table th,
.table td {
  border-top: 1px solid var(--line);
  padding: 6px 5px;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow: visible;
  text-overflow: clip;
  max-width: 0;
  vertical-align: top;
}

.table th {
  color: var(--muted);
  font-weight: 700;
  border-top: 0;
  white-space: nowrap;
}

.table-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-bottom: 8px;
  min-width: 0;
  max-width: 100%;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 2px;
}

.table-wrap.scroll-x {
  overflow-x: auto;
}

.table.decision-table {
  table-layout: auto;
  min-width: 720px;
}

.table.decision-table th,
.table.decision-table td {
  white-space: nowrap;
  max-width: none;
}



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

.decision-kv-card,
.decision-detail-card,
.decision-ok-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 10px;
}

.decision-k {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.decision-v {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.decision-stack {
  display: grid;
  gap: 8px;
}

.decision-card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.decision-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.decision-detail-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.decision-detail-row span {
  color: var(--muted);
}

.decision-detail-row strong {
  text-align: right;
  font-weight: 700;
}

.decision-ok-card {
  color: var(--ok);
  font-weight: 700;
}

.table-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  grid-column: 1 / -1;
  min-width: 0;
  max-width: 100%;
}

.table-filter-field {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.table-filter-label {
  font-size: 12px;
  color: var(--muted);
  line-height: 1;
}

.table-filter-input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #0d1a2d;
  color: var(--text);
  font-size: 13px;
  width: 100%;
  min-width: 0;
  height: 36px;
  max-width: 100%;
}

.table-row-click {
  cursor: pointer;
}

.table-row-click:active {
  background: #122033;
}

.table-sort {
  cursor: pointer;
  user-select: none;
}

.table-pager {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  margin-bottom: 0;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 2;
}

.table-host {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.single-line-incident {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.row-list {
  display: grid;
  gap: 6px;
  max-height: 92px;
  overflow: hidden;
}

.row-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--surface-2);
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 16, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 12px;
}

.modal.open {
  display: flex;
}

.modal-card {
  width: min(100%, 560px);
  max-height: 85vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px;
}

.modal-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.feed {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.feed-item {
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 15px;
}

.feed-item:first-child {
  border-top: 0;
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.section-title {
  margin: 0 0 8px;
  font-size: 18px;
}

.section-head {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.section-head .section-title {
  margin: 0;
}

.section-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.range-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  width: 100%;
  justify-content: flex-end;
}

.range-btn {
  padding: 4px 8px;
  font-size: 14px;
  white-space: nowrap;
}

.range-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.page-loading {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(10, 17, 27, 0.92);
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: none;
}

.action-link {
  color: #7cc0ff;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 700;
}

.field {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #0d1a2d;
  font-size: 14px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  border-radius: 999px;
  padding: 4px 10px;
  border: 1px solid;
  font-weight: 800;
  font-size: 14px;
}

.toggle-chip.on {
  background: #143223;
  color: #2fbf71;
  border-color: #1f5c3f;
}

.toggle-chip.off {
  background: #3a1820;
  color: #ff8b9a;
  border-color: #6a2a35;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #4b5568;
  transition: .2s;
  border-radius: 999px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: .2s;
  border-radius: 999px;
}

.switch input:checked + .slider {
  background-color: #2fbf71;
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

.order-page {
  max-width: 780px;
  margin: 0 auto;
}

.order-page .card {
  overflow: visible !important;
}

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

.quote-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quote-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  font-weight: 700;
}

.quote-box.bid { background: #122b4d; color: #8ec3ff; }
.quote-box.ask { background: #431b29; color: #ff9dad; }

.control-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  padding: 6px 0;
  border-top: 1px dashed #d5dae2;
}

.toggle:first-child {
  border-top: 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-update-row .btn {
  width: 100%;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(460px, 95vw);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 20px;
}

.login-card h1 {
  margin-top: 0;
}

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

.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 700px) {
  .shell {
    padding: 10px;
  }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 1050px) {
  .status-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .micro-row { grid-template-columns: repeat(8, 1fr); }
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .dash-main {
    grid-template-columns: 1.2fr 1fr 1fr;
  }
  .controls {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 480px) {
  .shell {
    padding: calc(4px + env(safe-area-inset-top)) 6px calc(4px + env(safe-area-inset-bottom));
    gap: 6px;
  }
  .top-nav {
    padding: 5px 6px;
    min-height: 40px;
  }
  .card {
    padding: 9px;
  }
  .section-title {
    font-size: 17px;
  }
  .metric .v {
    font-size: 15px;
  }
  .table-toolbar {
    grid-template-columns: 1fr;
  }
  .table-filters {
    grid-template-columns: 1fr 1fr;
  }
  .table-filter-input {
    min-width: 0;
  }
  .graph-box {
    height: min(32vh, 260px);
  }
}
