
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1d2530;
  --muted: #657286;
  --green: #0f8a5f;
  --red: #c2413a;
  --blue: #2563eb;
  --amber: #a16207;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

.auth-pending #appTopbar,
.auth-pending #appShell,
.auth-pending #loginGate,
.logged-out #appTopbar,
.logged-out #appShell {
  display: none !important;
}

.authenticated #loginGate {
  display: none !important;
}

.authenticated #appTopbar {
  display: flex !important;
}

.authenticated #appShell {
  display: block !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #eef2f7;
}

.login-gate.hidden,
.app-hidden {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

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

.login-panel p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-panel input {
  width: 100%;
  height: 42px;
  box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

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

button {
  min-width: 96px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  background: #fff;
  color: var(--blue);
}

button.danger {
  border-color: #b91c1c;
  background: #b91c1c;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 28px 36px;
}

.mode-bar {
  display: grid;
  grid-template-columns: 160px auto 1fr;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.market-mode-bar {
  margin: 14px;
  border-color: #d8e5f7;
  background: #f8fbff;
}

.mode-bar strong {
  display: block;
  font-size: 20px;
}

.mode-buttons {
  display: flex;
  gap: 8px;
}

.mode-button {
  min-width: 88px;
  border-color: var(--line);
  background: #fff;
  color: #3b4658;
}

.mode-button.active[data-mode="paper"] {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.mode-button.active[data-mode="live_trade"] {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.mode-button.locked {
  opacity: 0.55;
}

#operationModeHelp {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-button {
  min-width: auto;
  height: 38px;
  border-color: var(--line);
  background: #fff;
  color: #3b4658;
}

.tab-button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.summary {
  display: grid;
  grid-template-columns: 140px 140px 1fr 180px 120px 120px;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.auto-panel {
  display: grid;
  grid-template-columns: 1.2fr 110px 1fr 1fr 1.4fr;
  gap: 1px;
  overflow: hidden;
  margin: 16px 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.auto-panel > div {
  min-height: 72px;
  padding: 14px;
  background: #fff;
}

.auto-panel strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

	.balance,
	.history,
	.paper-log,
	.order-log,
	.global-schedule,
	.global-positions,
	.global-log,
	.stats-wide,
	.ops-panel,
	.settings-panel {
	  margin: 16px 0 18px;
	}

	.ops-checklist {
	  display: grid;
	  grid-template-columns: repeat(2, minmax(0, 1fr));
	  gap: 12px;
	  padding: 14px;
	}

	.ops-check-group {
	  min-width: 0;
	  padding: 14px;
	  border: 1px solid var(--line);
	  border-radius: 8px;
	  background: #fff;
	}

	.ops-check-group h3 {
	  margin: 0 0 10px;
	  font-size: 16px;
	}

	.ops-check-item {
	  display: flex;
	  align-items: flex-start;
	  gap: 8px;
	  padding: 8px 0;
	  color: var(--text);
	  font-size: 14px;
	  font-weight: 700;
	}

	.ops-check-item span {
	  display: block;
	  color: var(--muted);
	  font-size: 12px;
	  font-weight: 700;
	}

	.ops-change-form {
	  display: grid;
	  grid-template-columns: 1.2fr 1.2fr 1fr auto;
	  gap: 10px;
	  align-items: end;
	  padding: 14px;
	  border-bottom: 1px solid var(--line);
	}

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

	.ops-change-form input {
	  width: 100%;
	  height: 36px;
	  padding: 0 10px;
	  border: 1px solid var(--line);
	  border-radius: 6px;
	  color: var(--text);
	  font: inherit;
	  font-size: 14px;
	}

	.ops-review-prompt {
	  display: grid;
	  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	  gap: 14px;
	  padding: 14px;
	}

	.ops-review-box {
	  min-width: 0;
	  padding: 14px;
	  border: 1px solid var(--line);
	  border-radius: 8px;
	  background: #fff;
	}

	.ops-review-box h3 {
	  margin: 0 0 10px;
	  font-size: 16px;
	}

	.ops-review-box ul {
	  margin: 0;
	  padding-left: 18px;
	  color: var(--text);
	  font-size: 14px;
	  line-height: 1.6;
	}

	.ops-review-box pre {
	  overflow: auto;
	  max-height: 360px;
	  margin: 0;
	  color: var(--text);
	  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
	  white-space: pre-wrap;
	}

	.stats-metrics {
	  display: grid;
	  grid-template-columns: repeat(4, minmax(150px, 1fr));
	  gap: 1px;
	  overflow: hidden;
	  margin: 16px 0 18px;
	  border: 1px solid var(--line);
	  border-radius: 8px;
	  background: var(--line);
	}

	.stats-metrics > div {
	  min-height: 78px;
	  padding: 14px;
	  background: #fff;
	}

	.stats-metrics strong {
	  display: block;
	  overflow: hidden;
	  font-size: 20px;
	  line-height: 1.25;
	  text-overflow: ellipsis;
	  white-space: nowrap;
	}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.metric-grid > div {
  min-height: 72px;
  padding: 14px;
  background: #fff;
}

.metric-grid strong {
  display: block;
  overflow: hidden;
  font-size: 20px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

	.stats-table {
	  min-width: 0;
	}

	.stats-table table {
	  min-width: 720px;
	}

	.stats-wide table {
	  min-width: 1120px;
	}

.balance-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.balance-summary > div {
  min-height: 72px;
  padding: 14px;
  background: #fff;
}

.settings-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  padding: 14px;
}

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

.settings-grid input,
.settings-grid select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font: inherit;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 14px 14px;
}

.test-order {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.test-order label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.test-order input {
  width: 120px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}

.test-order select {
  width: 120px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.test-order span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary > div {
  min-height: 76px;
  padding: 14px;
  background: var(--panel);
}

.label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary strong {
  display: block;
  overflow: hidden;
  font-size: 20px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.page-actions span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.user-panel {
  margin-bottom: 18px;
}

.user-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
  padding: 14px;
}

.user-card {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.user-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.user-card label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.user-card input,
.user-card select,
.credential-test-bar input,
.credential-test-bar select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.credential-test-bar {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(180px, 260px);
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.market-config-form,
.simulation-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.credential-test-bar label,
.market-config-form label,
.simulation-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.market-config-form input,
.market-config-form select,
.market-config-form textarea,
.simulation-form input,
.simulation-form select,
.simulation-form textarea {
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.market-config-form input,
.market-config-form select,
.simulation-form input,
.simulation-form select {
  height: 36px;
}

.market-config-form textarea,
.simulation-form textarea {
  min-height: 120px;
  padding: 10px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.market-config-form .wide-field,
.simulation-form .wide-field {
  grid-column: span 2;
}

.market-config-control {
  width: 100%;
  min-width: 110px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.market-config-capital {
  min-width: 120px;
}

.market-config-positions {
  min-width: 72px;
}

.market-config-save {
  min-width: 64px;
  height: 34px;
  padding: 0 10px;
}

.form-status {
  margin: 0;
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 13px;
}

.compact-status {
  padding: 0;
}

.telegram-link-code {
  min-height: 42px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: 14px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-word;
}

.market-config-form .checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 18px;
}

.execution-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.execution-actions span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.rule-strip span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #3b4658;
  font-size: 13px;
  font-weight: 700;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.positions {
  margin-bottom: 18px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

input[type="search"] {
  width: min(360px, 45vw);
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

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

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f7;
  color: #3b4658;
  font-size: 12px;
  font-weight: 800;
}

th:nth-child(1), td:nth-child(1),
th:nth-child(2), td:nth-child(2),
th:nth-child(9), td:nth-child(9) {
  text-align: left;
}

tbody tr:hover {
  background: #f9fbff;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-width: 62px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.match {
  background: #dcfce7;
  color: var(--green);
}

.badge.skip {
  background: #f1f5f9;
  color: var(--muted);
}

.positive { color: var(--red); font-weight: 750; }
.negative { color: var(--blue); font-weight: 750; }
.profit { color: var(--red); font-weight: 750; }
.loss { color: var(--blue); font-weight: 750; }
.reason { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 20px;
  }

  .actions {
    width: 100%;
  }

  button {
    flex: 1;
  }

  main {
    padding: 16px 14px 28px;
  }

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

  .mode-bar {
    grid-template-columns: 1fr;
  }

  .auto-panel {
    grid-template-columns: 1fr;
  }

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

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

	  .stats-metrics,
	  .stats-grid,
	  .ops-checklist,
	  .ops-change-form,
	  .ops-review-prompt,
	  .user-grid,
	  .credential-test-bar,
	  .market-config-form,
	  .simulation-form,
	  .metric-grid {
	    grid-template-columns: 1fr;
	  }

  input[type="search"] {
    width: 100%;
  }
}
