:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1a1d24;
  --panel-2: #20242d;
  --line: #343a46;
  --text: #eff2f7;
  --muted: #97a0ae;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --cyan: #38bdf8;
  --blue: #3b82f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

.shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.12;
}

h2 {
  font-size: 16px;
}

.topbar p,
.hint {
  color: var(--muted);
}

.topbar p {
  margin-top: 4px;
}

.mode-pill {
  min-width: 104px;
  flex: 0 0 auto;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 800;
}

.mode-pill.running {
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.5);
}

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

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  width: auto;
  height: 38px;
  padding: 0 14px;
  border-color: var(--line);
  border-bottom-color: transparent;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  background: transparent;
}

.tab-button.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  min-height: 74px;
  padding: 14px;
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.metric strong {
  font-size: 18px;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(380px, 0.65fr);
  gap: 12px;
}

.spread-layout {
  grid-template-columns: minmax(360px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
}

.terminal-layout {
  grid-template-columns: minmax(360px, 0.75fr) minmax(0, 1.25fr);
  gap: 12px;
}

.tab-panel:not(.active) {
  display: none;
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

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

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

label span,
.section-title {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.section-title {
  margin: 18px 0 8px;
  color: var(--cyan);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 10px;
  outline: none;
  min-width: 0;
  font: inherit;
}

input,
select {
  height: 38px;
}

textarea {
  min-height: 82px;
  padding: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
}

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

.symbol-suggest-host {
  position: relative;
}

.symbol-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: grid;
  gap: 4px;
  max-height: 360px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.32);
}

.symbol-suggest[hidden] {
  display: none;
}

.symbol-suggest-item {
  height: 34px;
  padding: 0 10px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 800;
  box-shadow: none;
}

.symbol-suggest-item:hover,
.symbol-suggest-item.active {
  background: rgba(64, 200, 224, 0.13);
  color: var(--cyan);
  transform: none;
}

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

.accounts-list,
.account-status-list {
  display: grid;
  gap: 8px;
}

.account-row {
  display: grid;
  grid-template-columns: 94px minmax(130px, 0.65fr) minmax(180px, 1fr) 76px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.account-master {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  color: var(--text);
  font-weight: 800;
}

.account-master input {
  width: 18px;
  height: 18px;
}

.account-card {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.account-card-head,
.account-card-stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.account-card-head strong,
.account-card-stats strong {
  overflow-wrap: anywhere;
}

.account-card-head span,
.account-card-stats span {
  color: var(--muted);
  font-size: 12px;
}

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

.scanner-item {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.scanner-item-head,
.scanner-item-stats,
.scanner-item-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.scanner-item-head strong,
.scanner-item-stats strong {
  overflow-wrap: anywhere;
}

.scanner-item-stats,
.scanner-item-reason {
  color: var(--muted);
  font-size: 12px;
}

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

.spread-table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
  font-size: 12px;
}

.spread-table th,
.spread-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.spread-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.table-empty {
  color: var(--muted);
  text-align: center;
}

.alert-message {
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  color: var(--text);
  font: 12px/1.45 "Cascadia Mono", Consolas, monospace;
}

.grade {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--yellow);
  font-size: 11px;
  font-weight: 800;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--text);
  min-width: 0;
}

.check input {
  width: 18px;
  height: 18px;
}

.live-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px;
  margin-top: 16px;
}

.actions,
.manual-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.terminal-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

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

.metric.mini {
  min-height: 62px;
  padding: 10px;
}

.terminal-margin-list,
.terminal-account-list {
  display: grid;
  gap: 8px;
}

.terminal-margin-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 140px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.terminal-account-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.terminal-account-head,
.terminal-account-stats,
.terminal-position-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(150px, 1fr) minmax(150px, 1fr);
  align-items: center;
  gap: 8px;
}

.terminal-account-stats,
.terminal-position-row {
  color: var(--muted);
  font-size: 12px;
}

.terminal-price-line strong {
  color: var(--text);
  font-size: 13px;
}

button {
  height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  background: var(--panel-2);
  font-weight: 800;
  cursor: pointer;
  font: inherit;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary {
  background: var(--blue);
}

.danger,
.short {
  background: var(--red);
}

.long {
  background: var(--green);
  color: #07130c;
}

.close {
  background: var(--yellow);
  color: #171303;
}

.ghost {
  width: auto;
  height: 32px;
  padding: 0 10px;
  border-color: var(--line);
  color: var(--muted);
}

.side {
  display: grid;
  gap: 12px;
  align-content: start;
}

.log-panel {
  min-height: 620px;
}

.logs {
  height: 560px;
  overflow: auto;
  background: #0d0f13;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.log {
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  white-space: pre-wrap;
}

.log.INFO {
  color: #d8dee9;
}

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

.log.WARN {
  color: var(--yellow);
}

.log.ERROR {
  color: var(--red);
}

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

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

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

@media (max-width: 1050px) {
  .layout,
  .spread-layout,
  .terminal-layout,
  .grid.two {
    grid-template-columns: 1fr;
  }

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

  .live-row,
  .inline {
    grid-template-columns: 1fr;
  }

  .account-row {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .account-row label:nth-child(3) {
    grid-column: 1 / -1;
  }

  .log-panel {
    min-height: 420px;
  }

  .logs {
    height: 360px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 13px;
  }

  .shell {
    width: 100%;
    padding: max(14px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .topbar p {
    font-size: 12px;
    line-height: 1.35;
  }

  .mode-pill {
    width: 100%;
    min-width: 0;
    padding: 9px 12px;
  }

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

  .tabs {
    gap: 6px;
    overflow-x: auto;
  }

  .tab-button {
    height: 42px;
    flex: 0 0 auto;
  }

  .metric {
    min-height: 66px;
    padding: 10px;
  }

  .metric span {
    margin-bottom: 4px;
  }

  .metric strong {
    font-size: 15px;
    line-height: 1.2;
  }

  .layout,
  .side {
    gap: 10px;
  }

  .panel {
    padding: 12px;
  }

  .panel-head {
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 12px;
  }

  .panel-head .hint {
    max-width: 46%;
    text-align: right;
    font-size: 12px;
    line-height: 1.25;
  }

  .grid,
  .grid.two {
    gap: 8px;
  }

  label span,
  .section-title {
    font-size: 11px;
  }

  .section-title {
    margin: 14px 0 7px;
  }

  input,
  select,
  textarea,
  button {
    border-radius: 7px;
    font-size: 16px;
  }

  input,
  select,
  button {
    height: 44px;
  }

  .check {
    min-height: 44px;
  }

  .check input {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
  }

  .live-row,
  .actions,
  .manual-grid,
  .terminal-actions,
  .terminal-summary,
  .terminal-position-row,
  .terminal-margin-row {
    grid-template-columns: 1fr;
  }

  .account-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .account-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .account-row label:nth-child(3) {
    grid-column: auto;
  }

  .account-master {
    min-height: 44px;
  }

  .account-master input {
    width: 20px;
    height: 20px;
  }

  .live-row {
    margin-top: 12px;
  }

  .actions,
  .manual-grid {
    gap: 8px;
    margin-top: 12px;
  }

  .ghost {
    height: 36px;
    font-size: 13px;
  }

  .log-panel {
    min-height: 340px;
  }

  .logs {
    height: min(320px, 48vh);
    padding: 8px;
    font-size: 11px;
  }
}

@media (max-width: 380px) {
  .shell {
    padding-left: 8px;
    padding-right: 8px;
  }

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

  .panel-head {
    flex-wrap: wrap;
  }

  .panel-head .hint {
    max-width: none;
    width: 100%;
    text-align: left;
  }
}

/* Visual refresh */
:root {
  --bg: #0f1110;
  --bg-soft: #141716;
  --panel: #191d1c;
  --panel-2: #222827;
  --panel-3: #111412;
  --line: #303837;
  --line-soft: rgba(255, 255, 255, 0.07);
  --text: #f4f7f5;
  --muted: #a5afab;
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.13);
  --red: #ff5a5f;
  --red-soft: rgba(255, 90, 95, 0.13);
  --yellow: #f7c948;
  --yellow-soft: rgba(247, 201, 72, 0.13);
  --cyan: #40c8e0;
  --cyan-soft: rgba(64, 200, 224, 0.13);
  --blue: #4f8cff;
  --blue-soft: rgba(79, 140, 255, 0.14);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
  --shadow-soft: 0 10px 24px rgba(0, 0, 0, 0.16);
}

body {
  background:
    linear-gradient(135deg, rgba(64, 200, 224, 0.08) 0%, rgba(15, 17, 16, 0) 28%),
    linear-gradient(315deg, rgba(247, 201, 72, 0.06) 0%, rgba(15, 17, 16, 0) 24%),
    var(--bg);
}

.shell {
  padding-top: 18px;
}

.topbar {
  align-items: center;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.018));
  box-shadow: var(--shadow-soft);
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 15px;
  font-weight: 850;
}

.topbar p {
  color: #b6c0bc;
}

.mode-pill {
  border-color: var(--line-soft);
  background: var(--panel-3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.mode-pill.running {
  background: var(--green-soft);
  box-shadow: 0 0 0 1px rgba(48, 209, 88, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.dashboard {
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.panel {
  border-color: var(--line-soft);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012)),
    var(--panel);
  box-shadow: var(--shadow-soft);
}

.metric {
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, var(--cyan), rgba(247, 201, 72, 0.82), rgba(48, 209, 88, 0.72));
  opacity: 0.72;
}

.metric span,
label span,
.section-title,
.hint {
  color: var(--muted);
}

.metric strong {
  font-weight: 850;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  gap: 6px;
  padding: 6px;
  margin-bottom: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(17, 20, 18, 0.92);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
}

.tab-button {
  height: 36px;
  border: 0;
  border-radius: 6px;
  color: #bac5c1;
  background: transparent;
}

.tab-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
}

.tab-button.active {
  color: #08110d;
  background: var(--green);
  box-shadow: 0 8px 20px rgba(48, 209, 88, 0.18);
}

.layout,
.spread-layout,
.terminal-layout {
  gap: 14px;
}

.panel {
  padding: 18px;
}

.panel-head {
  min-height: 36px;
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}

.section-title {
  padding-top: 2px;
  color: var(--cyan);
  text-transform: uppercase;
  font-size: 11px;
}

input,
select,
textarea {
  border-color: var(--line-soft);
  background: #111513;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

input:hover,
select:hover,
textarea:hover {
  border-color: rgba(165, 175, 171, 0.44);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px var(--cyan-soft);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--green);
}

.account-row,
.account-card,
.scanner-item,
.terminal-margin-row,
.terminal-account-card {
  border-color: var(--line-soft);
  background: rgba(255, 255, 255, 0.025);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.account-row:hover,
.account-card:hover,
.scanner-item:hover,
.terminal-account-card:hover {
  border-color: rgba(64, 200, 224, 0.28);
  background: rgba(255, 255, 255, 0.04);
}

.account-master,
.check {
  padding: 0 10px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
}

.spread-table-wrap {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #111513;
}

.spread-table {
  border-collapse: separate;
  border-spacing: 0;
}

.spread-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #171b19;
  color: #bbc6c2;
}

.spread-table td {
  border-bottom-color: rgba(255, 255, 255, 0.055);
}

.spread-table tbody tr:hover td {
  background: rgba(64, 200, 224, 0.055);
}

.alert-message,
.logs {
  border-color: var(--line-soft);
  background: #0c0f0d;
}

.grade {
  border-color: rgba(247, 201, 72, 0.35);
  background: var(--yellow-soft);
  color: #ffd966;
}

button {
  border-color: rgba(255, 255, 255, 0.06);
  background: #252b2a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.055), 0 8px 18px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.065), 0 12px 26px rgba(0, 0, 0, 0.18);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

.primary {
  background: linear-gradient(180deg, #5a98ff, var(--blue));
}

.danger,
.short {
  background: linear-gradient(180deg, #ff7478, var(--red));
}

.long {
  background: linear-gradient(180deg, #54e878, var(--green));
}

.close {
  background: linear-gradient(180deg, #ffd968, var(--yellow));
}

.ghost {
  background: rgba(255, 255, 255, 0.035);
}

.terminal-actions .long,
.terminal-actions .short,
.terminal-actions .danger {
  height: 46px;
  font-size: 15px;
}

.terminal-summary {
  margin-bottom: 12px;
}

.terminal-account-head span {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  font-size: 11px;
  font-weight: 850;
}

.terminal-position-row {
  padding-top: 7px;
  border-top: 1px solid var(--line-soft);
}

.logs {
  border-radius: 8px;
}

.log {
  padding: 5px 0;
}

.positive {
  color: #54e878;
}

.negative {
  color: #ff7377;
}

.muted-cell {
  color: #8f9995;
}

@media (max-width: 640px) {
  .topbar,
  .tabs,
  .panel,
  .metric {
    border-radius: 8px;
  }

  .topbar {
    padding: 12px;
  }

  .tabs {
    padding: 5px;
  }

  .tab-button {
    height: 40px;
  }

  .panel {
    padding: 12px;
  }

  .account-master,
  .check {
    padding: 0 8px;
  }
}

.symbol-suggest {
  border-color: var(--line-soft);
  background: #111513;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.34);
}

.symbol-suggest-item:hover,
.symbol-suggest-item.active {
  background: rgba(64, 200, 224, 0.13);
  color: var(--cyan);
  transform: none !important;
  box-shadow: none !important;
}
