:root {
  --bg: #f6f0e4;
  --bg-2: #e7f0de;
  --ink: #17201a;
  --muted: #687366;
  --panel: rgba(255, 252, 245, 0.88);
  --panel-solid: #fffdf7;
  --line: rgba(81, 74, 54, 0.18);
  --green: #277044;
  --green-2: #78b84d;
  --red: #aa3730;
  --amber: #b6791d;
  --blue: #205d72;
  --black: #111612;
  --shadow: 0 24px 60px rgba(38, 43, 31, 0.12);
  --radius: 24px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  max-width: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
}

body {
  color: var(--ink);
  font-family: "Rubik", "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at 12% 6%, rgba(120, 184, 77, 0.24), transparent 28rem),
    radial-gradient(circle at 88% 12%, rgba(32, 93, 114, 0.18), transparent 26rem),
    linear-gradient(140deg, var(--bg), var(--bg-2));
}

button,
input,
select {
  font: inherit;
}

button,
select,
input,
a {
  min-width: 0;
}

.shell {
  width: min(100%, 1680px);
  margin: 0 auto;
  padding: 22px;
  overflow-x: hidden;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
}

.hero-copy,
.hero-status,
.topbar,
.metric,
.panel {
  backdrop-filter: blur(18px);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero-copy {
  border-radius: 32px;
  padding: 28px;
  min-width: 0;
  position: relative;
  overflow: hidden;
  text-align: start;
}

.hero-copy::after {
  content: "";
  position: absolute;
  inset: auto -10% -45% 20%;
  height: 110px;
  background: linear-gradient(90deg, transparent, rgba(39, 112, 68, 0.18), rgba(182, 121, 29, 0.18));
  transform: rotate(-5deg);
}

.eyebrow,
.section-kicker {
  color: var(--blue);
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(30px, 4.5vw, 64px);
  letter-spacing: -0.05em;
  max-width: 100%;
  overflow-wrap: anywhere;
}

h2 {
  font-size: clamp(18px, 2.1vw, 27px);
  letter-spacing: -0.03em;
}

p {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 760px;
}

.hero-status {
  border-radius: 26px;
  padding: 18px;
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 240px;
}

.hero-status small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

.sync-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 8px rgba(182, 121, 29, 0.12);
}

.sync-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 8px rgba(39, 112, 68, 0.14);
}

.sync-dot.bad {
  background: var(--red);
  box-shadow: 0 0 0 8px rgba(170, 55, 48, 0.14);
}

.topbar {
  border-radius: 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
  padding: 14px;
  position: sticky;
  top: 10px;
  z-index: 4;
}

.topbar label {
  color: var(--muted);
  display: grid;
  gap: 5px;
  font-size: 12px;
  min-width: 150px;
}

#strategySelect {
  display: none;
}

.auto-strategy-card {
  align-self: stretch;
  background: linear-gradient(135deg, rgba(17, 22, 18, 0.94), rgba(32, 93, 114, 0.88));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 22px;
  color: white;
  display: grid;
  flex: 1 1 360px;
  gap: 4px;
  min-width: min(360px, 100%);
  padding: 10px 14px;
  overflow: hidden;
}

.auto-strategy-card strong,
.auto-strategy-card span,
.auto-strategy-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auto-strategy-card strong {
  font-size: 14px;
  letter-spacing: 0.02em;
}

.auto-strategy-card span {
  color: rgba(255, 255, 255, 0.84);
  font-size: 12px;
}

.auto-strategy-card small {
  color: rgba(255, 255, 255, 0.66);
  font-size: 11px;
}

button,
select,
input,
.topbar a {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  padding: 10px 14px;
  text-decoration: none;
}

button,
.topbar a {
  background: var(--black);
  color: white;
  cursor: pointer;
  font-weight: 750;
  overflow-wrap: anywhere;
  white-space: normal;
}

button.ghost {
  background: rgba(255, 255, 255, 0.65);
  color: var(--black);
}

button.danger {
  border-color: rgba(170, 55, 48, 0.4);
  color: var(--red);
}

.kpi-grid,
.ops-grid,
.workbench,
.wallet-overview-grid {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 14px;
}

.ops-grid,
.workbench,
.wallet-overview-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  margin-bottom: 14px;
}

.metric,
.panel {
  border-radius: var(--radius);
  min-width: 0;
  overflow: hidden;
}

.metric {
  padding: 18px;
}

.metric.strong {
  background: linear-gradient(145deg, rgba(17, 22, 18, 0.94), rgba(32, 93, 114, 0.9));
  color: white;
}

.metric span,
.metric small {
  color: var(--muted);
  display: block;
}

.metric small {
  line-height: 1.35;
  margin-top: 4px;
}

.metric.strong span,
.metric.strong small {
  color: rgba(255, 255, 255, 0.72);
}

.metric strong {
  display: block;
  font-feature-settings: "tnum";
  font-size: clamp(21px, 2.45vw, 34px);
  letter-spacing: -0.05em;
  line-height: 1.08;
  margin: 7px 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

#entryRate {
  font-size: clamp(19px, 2.1vw, 28px);
  line-height: 1.18;
}

#paperPnl,
#livePnl {
  font-size: clamp(20px, 2vw, 31px);
  letter-spacing: -0.065em;
}

#runtimeMode,
#liveSubStatus {
  font-size: clamp(20px, 2.2vw, 32px);
  letter-spacing: -0.065em;
  line-height: 1.02;
  word-break: break-word;
}

.panel {
  padding: 16px;
}

.panel.tall {
  min-height: 320px;
}

.compact-panel {
  padding: 0;
}

.compact-panel summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  list-style: none;
  padding: 16px;
  min-width: 0;
}

.compact-panel summary::-webkit-details-marker {
  display: none;
}

.compact-panel summary span,
.compact-panel summary strong {
  min-width: 0;
}

.compact-panel summary b,
.compact-panel summary strong {
  overflow-wrap: anywhere;
}

.compact-panel summary strong {
  color: var(--blue);
  font-size: 13px;
  text-align: end;
}

.compact-panel[open] > .matrix-grid,
.compact-panel[open] > .wallet-grid,
.compact-panel[open] > .wallet-form,
.compact-panel[open] > .settings-form,
.compact-panel[open] > .note {
  margin: 0 16px 16px;
}

.secondary-settings:not([open]) {
  min-height: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
  min-width: 0;
}

.panel-head > *,
.hero-copy > *,
.metric > * {
  min-width: 0;
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 10px;
  white-space: nowrap;
}

.badge.positive,
.profit {
  background: rgba(39, 112, 68, 0.12);
  color: var(--green);
}

.badge.negative,
.loss {
  background: rgba(170, 55, 48, 0.12);
  color: var(--red);
}

.badge.neutral {
  background: rgba(32, 93, 114, 0.1);
  color: var(--blue);
}

.progress-stack {
  display: grid;
  gap: 16px;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 10px;
}

.bar {
  grid-column: 1 / -1;
  height: 13px;
  overflow: hidden;
  background: rgba(17, 22, 18, 0.1);
  border-radius: 999px;
}

.bar i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--green-2));
  transition: width 0.35s ease;
}

.note-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  max-height: 120px;
  overflow: auto;
  padding-inline-end: 4px;
}

.note {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.62);
  padding: 10px;
  overflow-wrap: anywhere;
}

canvas {
  width: 100%;
  max-width: 100%;
  display: block;
  background: linear-gradient(180deg, rgba(255,255,255,0.7), rgba(255,255,255,0.35));
  border: 1px solid var(--line);
  border-radius: 18px;
}

.position-grid,
.candidate-list,
.reason-grid,
.activity-list,
.wallet-grid,
.matrix-grid {
  display: grid;
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding-inline-end: 4px;
}

.matrix-grid,
.wallet-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  max-height: 460px;
}

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

.exposure-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.72), rgba(246, 240, 228, 0.6)),
    radial-gradient(circle at 10% 0%, rgba(120, 184, 77, 0.16), transparent 15rem);
  min-width: 0;
  padding: 14px;
}

.exposure-card.live {
  background:
    linear-gradient(145deg, rgba(17, 22, 18, 0.91), rgba(32, 93, 114, 0.86)),
    radial-gradient(circle at 12% 0%, rgba(120, 184, 77, 0.18), transparent 15rem);
  color: white;
}

.exposure-card.live .micro {
  background: rgba(255, 255, 255, 0.12);
}

.exposure-card.live .micro span {
  color: rgba(255, 255, 255, 0.7);
}

.exposure-card header {
  align-items: end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.exposure-card header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.exposure-card.live header span {
  color: rgba(255, 255, 255, 0.72);
}

.exposure-card header b {
  font-size: clamp(24px, 3vw, 38px);
  letter-spacing: -0.05em;
  overflow-wrap: anywhere;
}

.position-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.position-card,
.candidate,
.reason-card,
.matrix-card,
.wallet-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.65);
  padding: 13px;
  min-width: 0;
}

.position-card header,
.candidate header,
.reason-card header,
.matrix-card header,
.wallet-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.matrix-card.live,
.matrix-card.wallet-status {
  background:
    linear-gradient(145deg, rgba(17, 22, 18, 0.93), rgba(32, 93, 114, 0.86)),
    radial-gradient(circle at 12% 0%, rgba(120, 184, 77, 0.18), transparent 15rem);
  color: white;
}

.matrix-card.live .micro,
.matrix-card.wallet-status .micro {
  background: rgba(255, 255, 255, 0.12);
}

.matrix-card.live .micro span,
.matrix-card.wallet-status .micro span {
  color: rgba(255, 255, 255, 0.72);
}

.wallet-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin: 10px 0 0;
}

.wallet-form {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.symbol {
  font-weight: 900;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

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

.micro {
  background: rgba(17, 22, 18, 0.045);
  border-radius: 14px;
  padding: 8px;
}

.micro span {
  color: var(--muted);
  display: block;
  font-size: 11px;
}

.micro b {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.settings-form {
  display: grid;
  gap: 10px;
}

.settings-form input,
.settings-form select {
  width: 100%;
}

.checkline {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 8px;
  font-size: 13px;
}

.checkline input {
  width: auto;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.manual-close {
  margin-top: 10px;
  width: 100%;
}

.money-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.money-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

.money-cell {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--line);
  border-radius: 16px;
  min-width: 0;
  padding: 10px;
}

.money-cell span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 800;
}

.money-cell b {
  display: block;
  font-size: 18px;
  letter-spacing: -0.03em;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.table-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  max-width: 100%;
  max-height: 520px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.48);
  -webkit-overflow-scrolling: touch;
}

.table-card::-webkit-scrollbar,
.position-grid::-webkit-scrollbar,
.candidate-list::-webkit-scrollbar,
.reason-grid::-webkit-scrollbar,
.activity-list::-webkit-scrollbar,
.wallet-grid::-webkit-scrollbar,
.matrix-grid::-webkit-scrollbar,
.note-list::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.table-card::-webkit-scrollbar-thumb,
.position-grid::-webkit-scrollbar-thumb,
.candidate-list::-webkit-scrollbar-thumb,
.reason-grid::-webkit-scrollbar-thumb,
.activity-list::-webkit-scrollbar-thumb,
.wallet-grid::-webkit-scrollbar-thumb,
.matrix-grid::-webkit-scrollbar-thumb,
.note-list::-webkit-scrollbar-thumb {
  background: rgba(32, 93, 114, 0.28);
  border-radius: 999px;
}

.table-card.compact {
  max-height: 430px;
}

table {
  border-collapse: collapse;
  min-width: 100%;
  width: max-content;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: start;
  vertical-align: top;
}

th {
  background: rgba(246, 240, 228, 0.92);
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  font-size: 13px;
  overflow-wrap: anywhere;
}

tr.positive td {
  background: rgba(39, 112, 68, 0.075);
}

tr.negative td {
  background: rgba(170, 55, 48, 0.075);
}

.empty-state {
  color: var(--muted);
  place-items: center;
  min-height: 120px;
}

@media (max-width: 1220px) {
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
}

@media (max-width: 900px) {
  .shell {
    padding: 12px;
  }

  .hero,
  .ops-grid,
  .workbench,
  .wallet-overview-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-status {
    min-width: 0;
  }

  .topbar {
    position: static;
  }

  .topbar label,
  .topbar button,
  .topbar a,
  .auto-strategy-card {
    width: 100%;
  }

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

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

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

  .matrix-grid,
  .wallet-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    border-bottom: 1px solid var(--line);
    padding: 8px;
  }

  td {
    border: 0;
    display: grid;
    grid-template-columns: 105px minmax(0, 1fr);
    gap: 8px;
    padding: 7px 4px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
  }
}

@media (max-width: 560px) {
  body {
    width: 100%;
  }

  .shell {
    max-width: 100vw;
    padding: 8px;
    width: 100vw;
  }

  .hero,
  .topbar,
  main,
  section,
  article,
  .panel,
  .metric,
  .hero-copy,
  .hero-status {
    max-width: 100%;
  }

  select,
  input,
  button,
  .topbar a,
  canvas {
    max-width: 100%;
  }

  .hero-copy {
    padding: 18px;
    border-radius: 24px;
    text-align: center;
  }

  h1 {
    font-size: clamp(22px, 7vw, 26px);
    line-height: 1.18;
    margin-inline: auto;
    max-width: 220px;
  }

  .hero-copy p,
  .hero-copy .eyebrow {
    margin-inline: auto;
    max-width: 230px;
    word-break: break-word;
  }

  h2 {
    font-size: clamp(18px, 7vw, 24px);
  }

  .eyebrow,
  .section-kicker {
    letter-spacing: 0.1em;
    overflow-wrap: anywhere;
  }

  .hero-status {
    width: 100%;
  }

  .topbar {
    gap: 8px;
    padding: 12px;
  }

  .topbar select,
  .topbar input,
  .topbar button,
  .topbar a,
  .auto-strategy-card {
    min-height: 42px;
    padding: 9px 12px;
  }

  .auto-strategy-card strong,
  .auto-strategy-card span,
  .auto-strategy-card small {
    white-space: normal;
  }

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

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

  .panel,
  .metric {
    border-radius: 20px;
    padding: 14px;
  }

  .metric strong {
    font-size: clamp(20px, 9vw, 28px);
  }

  #entryRate {
    font-size: clamp(18px, 8vw, 26px);
  }

  #paperPnl,
  #livePnl,
  #runtimeMode,
  #liveSubStatus {
    font-size: clamp(22px, 8vw, 30px);
    line-height: 1.1;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .compact-panel summary {
    align-items: stretch;
    flex-direction: column;
  }

  .compact-panel summary strong {
    text-align: start;
  }

  .badge {
    max-width: 100%;
    white-space: normal;
  }

  .micro-grid,
  .money-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  td {
    grid-template-columns: 88px minmax(0, 1fr);
  }
}
