:root {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #121826;
  --muted: #667085;
  --line: #d8e0e8;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #e6f7f5;
  --blue: #2563eb;
  --danger: #b42318;
  --danger-soft: #fff1f2;
  --warn: #a16207;
  --ok: #167447;
  --shadow: 0 18px 45px rgba(15, 23, 42, .08);
  --radius: 8px;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, .08), transparent 260px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 40px;
  border-radius: 7px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

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

input:focus,
select:focus {
  outline: 2px solid rgba(15, 118, 110, .18);
  border-color: var(--accent);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login-shell { width: min(420px, calc(100vw - 32px)); }

.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}

.login-panel h1,
.hero-bar h1,
.panel-title h2,
.page-head h2,
.account-card h2,
.modal-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel p,
.hero-bar p,
.page-head p {
  color: var(--muted);
  margin: 6px 0 0;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.login-form button {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.alert {
  padding: 10px 12px;
  margin-top: 14px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #fecdd3;
  border-radius: var(--radius);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  background: #101828;
  color: #fff;
  border-right: 1px solid rgba(255, 255, 255, .08);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 4px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.brand-block strong,
.brand-block span {
  display: block;
}

.brand-block span {
  color: rgba(255, 255, 255, .62);
  font-size: 12px;
  margin-top: 3px;
}

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

.nav-item {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, .72);
  background: transparent;
  border-color: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  color: #fff;
  background: rgba(255, 255, 255, .1);
  border-color: rgba(255, 255, 255, .12);
}

.logout-form { margin: 0; }
.logout { color: #fecaca; }

.main-shell {
  min-width: 0;
  padding: 22px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.hero-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  background: rgba(255, 255, 255, .82);
  border: 1px solid rgba(216, 224, 232, .9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

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

.hero-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hero-actions button,
.page-head button,
.panel-title button,
.form-actions button,
.dense-form > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
}

.hero-actions button:first-child,
.page-head button,
.form-actions button:first-child {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: grid;
  gap: 18px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

.summary-card,
.account-card,
.chart-panel,
.strategy-panel,
.tables > div,
.work-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.summary-card {
  padding: 16px;
  min-height: 112px;
  display: grid;
  align-content: space-between;
}

.summary-card span,
.summary-card small,
.account-head span,
.panel-title span,
.kpi-row span,
.strategy-list span {
  color: var(--muted);
  font-size: 12px;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.summary-card.risk {
  border-color: #fed7aa;
  background: #fffaf3;
}

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

.account-card {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.account-head,
.panel-title,
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.account-head h2,
.panel-title h2,
.page-head h2 {
  font-size: 18px;
}

.state-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
}

.state-pill.on {
  color: var(--ok);
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.state-pill.paused {
  color: var(--warn);
  border-color: #fde68a;
  background: #fffbeb;
}

.connection,
.decision {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.connection.ok {
  color: var(--ok);
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.connection.bad {
  color: var(--danger);
  border-color: #fecdd3;
  background: var(--danger-soft);
}

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

.kpi-row div,
.strategy-list div,
.info-list div,
.mini-metrics div,
.status-stack div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface-2);
  min-width: 0;
}

.kpi-row strong,
.strategy-list strong,
.info-list strong,
.info-list span,
.mini-metrics strong,
.mini-metrics span,
.status-stack strong,
.status-stack span {
  display: block;
}

.kpi-row strong {
  margin-top: 5px;
  font-size: 15px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions button,
.icon-only {
  width: 40px;
  min-width: 40px;
  padding: 0;
  display: grid;
  place-items: center;
}

.actions .danger,
button.danger,
.danger {
  color: var(--danger);
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, .8fr);
  gap: 18px;
}

.chart-panel,
.strategy-panel,
.tables > div,
.work-panel {
  padding: 16px;
}

.tradingview-widget-container {
  height: 470px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

#tradingview_chart { height: 100%; }

.strategy-list,
.info-list,
.broker-steps,
.mini-metrics,
.status-stack {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

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

.mini-metrics span,
.status-stack span {
  color: var(--muted);
  font-size: 12px;
}

.mini-metrics strong,
.status-stack strong {
  margin-top: 5px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.strategy-list strong,
.info-list span {
  margin-top: 4px;
}

.page-head {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.accounts-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.account-row {
  min-height: 122px;
  height: auto;
  padding: 14px;
  display: grid;
  gap: 8px;
  text-align: left;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.account-row strong,
.account-row span {
  display: block;
}

.account-row-top {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.account-row em {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
}

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

.account-row small {
  color: var(--ink);
  font-size: 12px;
}

.account-row.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.broker-panel {
  max-width: 920px;
}

.broker-steps {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.broker-steps div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  padding: 12px;
}

.broker-steps strong {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
}

.broker-steps span {
  color: var(--muted);
  font-size: 13px;
}

.feature-board,
.requirements-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.feature-board div,
.requirements-board div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 12px;
}

.feature-board svg {
  color: var(--accent);
}

.feature-board strong,
.feature-board span,
.requirements-board strong,
.requirements-board span {
  display: block;
}

.feature-board strong,
.requirements-board strong {
  margin-top: 8px;
}

.feature-board span,
.requirements-board span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.requirements-board div {
  background: var(--surface-2);
}

code,
pre {
  font-family: Consolas, Monaco, monospace;
}

code {
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f1f5f9;
  color: var(--ink);
}

.tables {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: 18px;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.profit-positive { color: var(--ok); }
.profit-negative { color: var(--danger); }

.log-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.log-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface-2);
}

.log-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.modal {
  width: min(920px, calc(100vw - 28px));
  max-height: min(860px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, .28);
  background: var(--surface);
  overflow: auto;
}

.small-modal {
  width: min(520px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(16, 24, 40, .48);
  backdrop-filter: blur(3px);
}

.modal-shell {
  margin: 0;
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(8px);
}

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

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

.modal-form {
  padding: 16px;
}

.modal-form.single {
  grid-template-columns: 1fr;
}

.dense-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.dense-form .check-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  color: var(--ink);
  font-size: 14px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.form-band {
  grid-column: 1 / -1;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.form-actions {
  grid-column: 1 / -1;
  padding-top: 4px;
}

.modal-copy {
  padding: 16px;
  color: var(--muted);
  line-height: 1.55;
}

.modal-copy p {
  margin: 0 0 12px;
}

.modal-copy pre {
  white-space: pre-wrap;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0f172a;
  color: #e5e7eb;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  background: #f0fdf4;
  color: var(--ok);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  color: var(--danger);
  border-color: #fecdd3;
  background: var(--danger-soft);
}

svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 1180px) {
  .summary-strip,
  .account-grid,
  .accounts-list,
  .broker-steps,
  .insight-grid,
  .feature-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-grid,
  .tables,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: sticky;
    height: auto;
    z-index: 10;
    padding: 10px;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
    align-items: center;
  }

  .brand-block {
    padding: 0;
    border: 0;
  }

  .brand-block div:last-child,
  .logout span {
    display: none;
  }

  .side-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
  }

  .nav-item {
    width: auto;
    min-width: 44px;
  }

  .nav-item span {
    display: none;
  }

  .main-shell {
    padding: 12px;
  }

  .hero-bar,
  .page-head,
  .account-head,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-strip,
  .account-grid,
  .accounts-list,
  .broker-steps,
  .insight-grid,
  .feature-board,
  .kpi-row,
  .mini-metrics,
  .dense-form {
    grid-template-columns: 1fr;
  }

  .hero-actions button {
    flex: 1 1 auto;
  }

  .tradingview-widget-container {
    height: 360px;
  }
}
