:root {
  color-scheme: dark;
  --bg: #090b0e;
  --bg-alt: #101317;
  --panel: #15191f;
  --panel-soft: #1b2027;
  --line: #29313b;
  --text: #edf1f7;
  --muted: #8d99a8;
  --accent: #f7c948;
  --accent-strong: #ffb800;
  --profit: #12b981;
  --loss: #f04444;
  --warning: #f59e0b;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(247, 201, 72, 0.08), transparent 220px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 15px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.login-panel {
  width: min(100%, 390px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11151a;
  box-shadow: 0 24px 70px var(--shadow);
}

.brand-mark {
  width: 68px;
  height: 34px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid rgba(247, 201, 72, 0.45);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 800;
}

.login-panel h1,
.topbar h1,
.panel h2 {
  margin: 0;
}

.login-panel h1 {
  margin-bottom: 22px;
  font-size: 26px;
}

label,
.field-card {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0c0f13;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(247, 201, 72, 0.12);
}

.login-panel label + label {
  margin-top: 14px;
}

.primary-action,
.danger-action,
.ghost-button,
.icon-button,
.command-button,
.tab,
.period-tabs button,
.segmented button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 14px;
  font-weight: 750;
}

.primary-action {
  width: 100%;
  margin-top: 18px;
  border-color: rgba(247, 201, 72, 0.65);
  background: var(--accent);
  color: #17130a;
}

.danger-action {
  border-color: rgba(240, 68, 68, 0.65);
  background: var(--loss);
  color: white;
}

.ghost-button,
.icon-button {
  background: transparent;
}

.form-error,
.save-status {
  min-height: 20px;
  color: var(--loss);
  font-size: 13px;
}

.app-shell {
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 16px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h1 {
  margin-top: 3px;
  font-size: clamp(28px, 7vw, 52px);
  line-height: 0.96;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.tabs,
.command-strip,
.filter-row,
.period-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar,
.command-strip::-webkit-scrollbar,
.filter-row::-webkit-scrollbar,
.period-tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  color: var(--muted);
}

.tab.is-active,
.period-tabs .is-active,
.segmented .is-active,
[data-log-file].is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(247, 201, 72, 0.1);
}

.tab-page {
  display: none;
  margin-top: 10px;
}

.tab-page.is-active {
  display: block;
}

.command-strip {
  margin: 8px 0 12px;
}

.command-button {
  flex: 1 0 118px;
  background: #171c22;
}

.command-open {
  border-color: rgba(247, 201, 72, 0.65);
  color: var(--accent);
}

.command-button.danger {
  border-color: rgba(240, 68, 68, 0.4);
  color: #ffb4b4;
}

.command-button.strong {
  background: rgba(240, 68, 68, 0.14);
}

.dashboard-grid,
.stats-grid,
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.panel,
.field-card,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 25, 31, 0.96);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.panel {
  padding: 14px;
}

.field-card {
  padding: 13px;
}

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

.panel h2 {
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 800;
}

.badge {
  min-width: max-content;
  border: 1px solid rgba(141, 153, 168, 0.35);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.badge.success,
.profit {
  color: var(--profit);
}

.badge.danger,
.loss {
  color: var(--loss);
}

.badge.warning {
  color: var(--warning);
}

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

.metric-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(41, 49, 59, 0.7);
}

.metric-line:last-child {
  border-bottom: 0;
}

.metric-line span,
.position-table span,
.trade-row span,
.confirm-position span,
.stat-card span {
  color: var(--muted);
  font-size: 12px;
}

.metric-line strong {
  text-align: right;
}

.pnl-value {
  margin-top: 2px;
  font-size: clamp(30px, 10vw, 52px);
  font-weight: 850;
  line-height: 1;
}

.pnl-percent {
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

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

.position-table div,
.confirm-position div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border-radius: 6px;
  background: #101419;
}

.position-table strong,
.trade-row strong,
.candidate-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.blocked-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.blocked-list span,
.reject-reasons {
  border: 1px solid rgba(245, 158, 11, 0.28);
  border-radius: 999px;
  color: #f8cf85;
  padding: 5px 9px;
  font-size: 12px;
}

.countdown {
  margin-top: 12px;
  color: var(--accent);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

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

.candidate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
  padding: 11px;
  border: 1px solid rgba(41, 49, 59, 0.8);
  border-radius: 8px;
  background: #101419;
}

.candidate-row > div:first-child {
  display: grid;
  gap: 4px;
}

.candidate-row span {
  color: var(--muted);
  font-size: 12px;
}

.candidate-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.candidate-metrics span {
  border-radius: 999px;
  background: #1a2027;
  padding: 5px 8px;
}

.reject-reasons {
  border-radius: 6px;
}

.settings-grid {
  align-items: start;
}

.toggle-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.toggle-field input {
  width: 46px;
  min-height: 26px;
  accent-color: var(--accent);
}

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

.segmented button {
  padding: 0 8px;
}

.save-row {
  display: grid;
  gap: 8px;
}

.stat-card {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.stat-card strong {
  font-size: 22px;
}

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 86px minmax(80px, 1fr) 36px;
  align-items: center;
  gap: 10px;
}

.bar-row div {
  height: 8px;
  border-radius: 999px;
  background: #222933;
  overflow: hidden;
}

.bar-row i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.filter-row {
  align-items: center;
  margin-bottom: 12px;
}

.filter-row input,
.filter-row select,
.filter-row button {
  flex: 0 0 142px;
}

.trades-table {
  display: grid;
  gap: 8px;
}

.trade-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101419;
}

.trade-row > div {
  display: grid;
  gap: 4px;
}

.log-output {
  min-height: 440px;
  max-height: 68vh;
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080a0d;
  color: #b8c2cf;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.confirm-dialog {
  width: min(92vw, 460px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
}

.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.confirm-dialog form {
  padding: 18px;
}

.confirm-dialog h2 {
  margin: 0 0 8px;
}

.confirm-dialog p {
  margin: 0 0 14px;
  color: #cbd5e1;
}

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

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

.toast {
  position: fixed;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  max-width: min(440px, calc(100vw - 28px));
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #15191f;
  color: var(--text);
  padding: 12px 14px;
  box-shadow: 0 18px 40px var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

@media (min-width: 720px) {
  .app-shell {
    padding-inline: 22px;
  }

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

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

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

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

  .candidate-row {
    grid-template-columns: minmax(160px, 1.2fr) minmax(240px, 2fr) auto;
    align-items: center;
  }

  .reject-reasons {
    grid-column: 1 / -1;
  }

  .trade-row {
    grid-template-columns: 1.5fr 1fr 0.8fr 1fr 1fr 1fr 1fr 1fr 1.4fr;
  }
}

@media (min-width: 1040px) {
  .dashboard-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .position-card {
    grid-column: span 2;
  }

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

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