:root {
  --bg: #0b0d0f;
  --side: #0f1316;
  --panel: #14191d;
  --panel-2: #192126;
  --panel-3: #202a30;
  --line: #2c373f;
  --line-strong: #43515b;
  --text: #edf2f6;
  --muted: #9aa8b3;
  --muted-2: #74828d;
  --green: #5ec489;
  --teal: #4bc4cf;
  --amber: #e9b14a;
  --red: #ef6b6b;
  --blue: #6da4f8;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--panel-3);
}

button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100svh;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: var(--side);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  margin-bottom: 20px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid #3a6d73;
  border-radius: 7px;
  background: #102325;
  color: var(--teal);
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 38px;
  padding: 0 10px;
  text-align: left;
  background: transparent;
  color: #c9d3db;
  font-weight: 800;
}

.nav-link span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 900;
}

.nav-link.active,
.nav-link:hover {
  background: var(--panel-2);
  color: #fff;
}

.side-status {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.side-status div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11171b;
}

.side-status span {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 800;
}

.side-status strong {
  font-size: 13px;
}

.workspace {
  min-width: 0;
  padding: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(238px, 1.2fr) repeat(6, minmax(126px, .72fr)) auto;
  gap: 8px;
  align-items: stretch;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 19, 22, .96);
  backdrop-filter: blur(10px);
}

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

.mode-button {
  height: 40px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 900;
}

.mode-button.active {
  border-color: var(--teal);
  background: #102e32;
  color: #d9fbff;
}

.top-stat {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #10161a;
}

.top-stat span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.top-stat strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gain {
  color: var(--green) !important;
}

.loss {
  color: var(--red) !important;
}

.watch {
  color: var(--amber) !important;
}

.kill-switch {
  min-width: 128px;
  height: 58px;
  border-color: #704149;
  background: #291719;
  color: #ffd8de;
  font-weight: 900;
}

.kill-switch.active {
  border-color: var(--red);
  background: #5b1f24;
  color: #fff;
}

.live-strip {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #75532b;
  border-radius: 8px;
  background: #241b10;
  color: #ffdda8;
  font-size: 13px;
  font-weight: 850;
}

.live-strip.show {
  display: block;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(260px, .86fr) minmax(640px, 1.86fr) minmax(304px, .92fr);
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head.split {
  align-items: flex-start;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 900;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.panel-body {
  padding: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #141b20;
  color: #d7e0e7;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.pill.good {
  border-color: #32634b;
  background: #102119;
  color: #caffe0;
}

.pill.watch {
  border-color: #715423;
  background: #241d0f;
  color: #ffe1a2;
}

.pill.danger {
  border-color: #74383f;
  background: #2a171b;
  color: #ffd6dc;
}

.pill.info {
  border-color: #35616a;
  background: #10262a;
  color: #d8fbff;
}

.pill.neutral {
  color: #c7d0d8;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.metric {
  min-width: 0;
  min-height: 74px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.metric.wide {
  grid-column: 1 / -1;
}

.metric span,
.settings-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.metric strong,
.settings-grid strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.2;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1.35;
}

.meter {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #090d10;
}

.meter i {
  display: block;
  width: var(--fill);
  height: 100%;
  border-radius: inherit;
  background: var(--color);
}

.list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}

.list-row span {
  min-width: 0;
  overflow: hidden;
  color: #dce5ec;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1114;
}

.segmented button {
  min-width: 68px;
  height: 30px;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.segmented button.active {
  border-color: #3a686e;
  background: #102a2e;
  color: var(--text);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  background: #101518;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #151b20;
  color: var(--muted);
  font-weight: 900;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #151d22;
}

tbody tr.selected {
  outline: 2px solid #3d757d;
  outline-offset: -2px;
  background: #13272b;
}

tbody tr.critical-row {
  background: #241719;
}

.num {
  text-align: right;
}

.leg-pair {
  display: grid;
  gap: 5px;
  min-width: 184px;
}

.leg-line {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
}

.leg-side {
  display: inline-grid;
  place-items: center;
  height: 22px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
}

.leg-side.long {
  background: #12291d;
  color: #d9ffe7;
}

.leg-side.short {
  background: #331a1e;
  color: #ffe0e5;
}

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

.ticket-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.ticket-title h3 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.ticket-title span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ticket-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto auto;
  gap: 8px;
  align-items: center;
}

.ticket-toolbar button {
  min-height: 36px;
  font-weight: 900;
}

.ticket-leg-grid {
  display: grid;
  gap: 10px;
}

.ticket-leg {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101518;
}

.ticket-leg-head,
.toggle-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toggle-line {
  justify-content: flex-start;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.toggle-line input,
.checkbox-field input {
  width: 18px;
  height: 18px;
}

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

.form-grid.compact {
  margin-top: 10px;
  gap: 8px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1114;
  color: var(--text);
}

.checkbox-field {
  align-content: end;
}

.checkbox-field input {
  justify-self: start;
}

.field-disabled {
  opacity: .48;
}

.field input:disabled,
.field select:disabled {
  border-color: #222b31;
  background: #0a0e11;
  color: #66737d;
}

.check-list {
  display: grid;
  gap: 8px;
}

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

.action-row button {
  height: 42px;
  font-weight: 900;
}

.primary-button {
  border-color: #3b7077;
  background: #123238;
  color: #dcfbff;
}

.danger-button {
  border-color: #71363e;
  background: #2a171b;
  color: #ffd6dc;
}

.ghost-button {
  border-color: #344149;
  background: #12171b;
  color: #cdd7df;
}

.position-grid {
  min-width: 960px;
}

.position-row {
  display: grid;
  grid-template-columns: 28px minmax(136px, .9fr) repeat(8, minmax(82px, 1fr));
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #101518;
  font-size: 12px;
}

.position-row.header {
  background: #151b20;
  color: var(--muted);
  font-weight: 900;
}

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

.position-row button {
  width: 26px;
  height: 26px;
  padding: 0;
  font-weight: 900;
}

.position-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtext {
  display: block;
  margin-top: 3px;
  color: var(--muted-2);
  font-size: 11px;
}

.leg-detail {
  display: none;
  grid-column: 1 / -1;
  gap: 8px;
  padding: 8px 8px 4px 36px;
  border-top: 1px solid var(--line);
}

.position-row.open .leg-detail {
  display: grid;
}

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

.detail-box {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}

.detail-box h4 {
  margin: 0 0 8px;
  font-size: 12px;
}

.kv {
  display: grid;
  grid-template-columns: minmax(96px, .7fr) minmax(0, 1fr);
  gap: 8px;
  padding: 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.kv strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.mini-chart {
  height: 146px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101518;
}

.mini-chart h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.mini-chart svg {
  display: block;
  width: 100%;
  height: 96px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.api-config-form {
  display: grid;
  gap: 12px;
}

.api-config-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.api-config-head h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
}

.api-config-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.security-note {
  padding: 10px 12px;
  border: 1px solid #67542c;
  border-radius: 8px;
  background: #201a10;
  color: #f2d59a;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.5;
}

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

.settings-actions button {
  min-height: 40px;
  font-weight: 900;
}

.empty-cell {
  height: 76px;
  color: var(--muted);
  text-align: center;
  white-space: normal;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 96px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.5;
}

.settings-grid article {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(2, 5, 8, .72);
}

.modal-backdrop.show {
  display: grid;
}

.modal {
  width: min(540px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 80px rgba(0, 0, 0, .5);
}

.modal header,
.modal footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
}

.modal header {
  border-bottom: 1px solid var(--line);
}

.modal footer {
  border-top: 1px solid var(--line);
}

.modal h3 {
  margin: 0;
  font-size: 16px;
}

.modal main {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.confirm-grid {
  display: grid;
  gap: 8px;
  margin: 0;
}

.confirm-grid div {
  display: grid;
  grid-template-columns: minmax(150px, .8fr) minmax(0, 1fr);
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.confirm-grid dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  text-align: right;
  font-weight: 900;
}

.confirm-grid dt {
  margin: 0;
}

@media (max-width: 1380px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(7, minmax(108px, 1fr));
    overflow-x: auto;
  }

  .side-status {
    display: none;
  }

  .main-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mode-switch {
    grid-column: 1 / -1;
  }

  .kill-switch {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 10px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(112px, 1fr));
  }

  .topbar {
    grid-template-columns: 1fr 1fr;
  }

  .mode-switch {
    grid-column: 1 / -1;
  }

  .metrics,
  .form-grid,
  .detail-grid,
  .chart-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .field.wide,
  .metric.wide {
    grid-column: auto;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .ticket-toolbar {
    grid-template-columns: 1fr;
  }

  .api-config-head {
    flex-direction: column;
  }

  .settings-actions {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .panel-head.split {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented button {
    min-width: 0;
  }
}
