:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --paper: #f4f6f8;
  --accent: #146c5f;
  --accent-ink: #ffffff;
  --warn: #9f5300;
  --bad: #a5282c;
  --good: #13744f;
  --shadow: 0 16px 40px rgba(31, 42, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: linear-gradient(180deg, #f8fafb 0%, #eef2f4 100%);
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  min-height: 34px;
  padding: 7px 12px;
}

button:hover {
  border-color: #9aa7b7;
}

button.primary,
#saveBtn,
#refreshMarketBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  padding: 6px 8px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 251, 0.94);
  backdrop-filter: blur(10px);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
}

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px 24px 40px;
}

.actions,
.compact-controls,
.matrix-controls,
.instrument-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.status-grid > div,
.summary-cards > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 12px;
}

.label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
}

.tab.active {
  background: #1f2933;
  border-color: #1f2933;
  color: #fff;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.compact-controls label,
.matrix-controls label,
.instrument-controls label {
  min-width: 120px;
}

.instrument-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  margin-bottom: 12px;
}

.checkbox-label {
  align-content: end;
  grid-template-columns: 18px 1fr;
  min-height: 57px;
}

.checkbox-label input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 10px 0 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #344054;
  padding: 4px 9px;
  font-size: 12px;
}

.badge.good {
  color: var(--good);
  border-color: rgba(19, 116, 79, 0.35);
}

.badge.warn {
  color: var(--warn);
  border-color: rgba(159, 83, 0, 0.35);
}

.badge.bad {
  color: var(--bad);
  border-color: rgba(165, 40, 44, 0.35);
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-cards strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.table-wrap,
.matrix-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafb;
  color: #344054;
  font-size: 12px;
  text-transform: uppercase;
}

td:first-child,
th:first-child {
  text-align: left;
}

td input,
td select {
  min-width: 90px;
}

.matrix-controls {
  margin: 16px 0 10px;
}

.matrix-shell {
  max-height: 72vh;
}

#matrixTable th:first-child,
#matrixTable td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
  font-weight: 800;
}

#matrixTable th:first-child {
  z-index: 3;
  background: #f8fafb;
}

.cell-pos {
  color: #063f2d;
}

.cell-neg {
  color: #6d1519;
}

.remove-btn {
  color: var(--bad);
}

@media (max-width: 900px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .status-grid,
  .summary-cards,
  .instrument-controls {
    grid-template-columns: 1fr;
  }

  main {
    padding: 14px;
  }
}
