:root {
  --bg: #f3f6f5;
  --panel: #ffffff;
  --ink: #15211e;
  --muted: #6c7975;
  --line: #dfe7e4;
  --green: #08785f;
  --green-dark: #075b49;
  --green-pale: #eaf6f2;
  --blue: #2876c7;
  --blue-pale: #edf5ff;
  --red: #be3038;
  --red-pale: #fff0f1;
  --amber: #9b650b;
  --amber-pale: #fff7e4;
  --shadow: 0 12px 34px rgba(23, 48, 41, .07);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(27px, 3vw, 34px); letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 19px; letter-spacing: -.015em; }
h3 { margin: 0; font-size: 17px; }

.subtle { margin-bottom: 0; color: var(--muted); }
.eyebrow {
  margin-bottom: 5px;
  color: var(--green);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(22px, calc((100vw - 1320px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}

.brand, .brand > div, .top-actions, .strategy-head > div, .card-actions, .modal-actions {
  display: flex;
  align-items: center;
}

.brand { gap: 10px; }
.brand > div { align-items: flex-start; flex-direction: column; line-height: 1.35; }
.brand small { color: var(--muted); font-size: 11px; }
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #0a876c, #075443);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 9px 20px rgba(8, 119, 95, .22);
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 10px; font-size: 19px; }

.top-actions { gap: 9px; }
.clock { margin-right: 8px; color: var(--muted); font-variant-numeric: tabular-nums; }

.shell {
  width: min(1320px, calc(100% - 36px));
  margin: 0 auto;
  padding: 28px 0 54px;
}

.hero-row, .section-heading, .strategy-head, .monitor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.hero-row { margin-bottom: 18px; }
.section-heading { margin-bottom: 13px; }

.button {
  min-height: 39px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 780;
}
.button.primary { background: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { border-color: var(--line); background: #fff; color: var(--ink); }
.button.ghost { background: transparent; color: var(--muted); }
.button.danger { border-color: #f2c8cb; background: var(--red-pale); color: var(--red); }
.button.emergency {
  padding: 0 19px;
  background: var(--red);
  color: #fff;
  box-shadow: 0 8px 20px rgba(190, 48, 56, .18);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 25px;
}
.metrics article, .panel, .strategy-card {
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
  box-shadow: 0 4px 18px rgba(23, 48, 41, .035);
}
.metrics article { min-width: 0; padding: 16px 17px; }
.metrics span, .strategy-info span { display: block; color: var(--muted); font-size: 12px; }
.metrics strong {
  display: block;
  overflow: hidden;
  margin: 5px 0 1px;
  font-size: 22px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.metrics small { color: var(--muted); }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }

.automation-section { margin-bottom: 16px; }
.strategy-card { position: relative; overflow: hidden; padding: 20px; }
.card-accent {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--green), #67c6ae);
}
.strategy-head > div { gap: 11px; }
.strategy-head small { color: var(--muted); }
.index-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--green-pale);
  color: var(--green);
  font-size: 16px;
  font-weight: 900;
}
.strategy-card-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 0 14px;
}
.strategy-copy { min-width: 0; }
.strategy-copy strong, .strategy-copy span { display: block; }
.strategy-copy strong { margin-bottom: 3px; font-size: 15px; }
.strategy-copy span { color: var(--muted); font-size: 12px; }
.safety-pill {
  padding: 5px 9px;
  border: 1px solid #cde6de;
  border-radius: 999px;
  background: #f2faf7;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 800;
}
.strategy-info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 15px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.strategy-info div { min-width: 0; padding: 10px 0; }
.strategy-info div + div { padding-left: 14px; border-left: 1px solid var(--line); }
.strategy-info strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-actions { gap: 8px; }
.card-actions .button { flex: 1; }

.status {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}
.status.running { background: var(--green-pale); color: var(--green); }
.status.scheduled { background: var(--amber-pale); color: var(--amber); }
.status.error { background: var(--red-pale); color: var(--red); }
.status.idle, .status.stopped, .status.interrupted { background: #edf1f0; color: var(--muted); }

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
  margin-bottom: 17px;
}
.panel { padding: 19px; }
.monitor-card { min-width: 0; }
.monitor-head { align-items: flex-start; margin-bottom: 15px; }
.spot-line {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 11px;
  padding: 12px 14px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green-pale), #f8fcfb);
}
.spot-line span { color: var(--muted); font-weight: 700; }
.spot-line strong { color: var(--green-dark); font-size: 28px; letter-spacing: -.04em; }
.candle-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.candle-block strong, .candle-block small { display: block; }
.candle-block small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.ohlc { display: grid; grid-template-columns: repeat(4, minmax(55px, 1fr)); gap: 8px; }
.ohlc span { color: var(--muted); font-size: 10px; }
.ohlc b { display: block; color: var(--ink); font-size: 12px; }
.monitor-note {
  margin-top: 11px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--red-pale);
  color: var(--red);
  font-size: 12px;
}


.indicator-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  padding: 8px 10px;
  border: 1px solid #cde6de;
  border-radius: 9px;
  background: #f2faf7;
}
.indicator-meta span { color: var(--muted); font-size: 11px; font-weight: 750; }
.indicator-meta strong { color: var(--green-dark); font-size: 11px; font-weight: 850; text-align: right; }

.indicator-grid, .position-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.indicator-grid > div, .position-grid > div {
  min-width: 0;
  padding: 10px 11px;
  border-radius: 9px;
  background: #f5f8f7;
}
.indicator-grid span, .indicator-grid strong, .indicator-grid small,
.position-grid span, .position-grid strong { display: block; }
.indicator-grid span, .position-grid span { color: var(--muted); font-size: 11px; }
.indicator-grid strong, .position-grid strong {
  overflow: hidden;
  margin-top: 2px;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.indicator-grid small { color: var(--muted); font-size: 9px; font-weight: 800; }
.signal-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 9px;
}
.signal-banner span { font-size: 11px; }
.signal-banner strong { font-size: 15px; }
.signal-banner.neutral { background: #f1f4f3; color: var(--muted); }
.signal-banner.call { background: var(--blue-pale); color: var(--blue); }
.signal-banner.put, .signal-banner.exit { background: var(--red-pale); color: var(--red); }

.position-symbol-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.position-symbol-row > div { min-width: 0; }
.position-symbol-row strong, .position-symbol-row small { display: block; }
.position-symbol-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.position-symbol-row small { color: var(--muted); font-size: 11px; }
.option-badge {
  min-width: 40px;
  padding: 6px 8px;
  border-radius: 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
}
.option-badge.neutral { background: #edf1f0; color: var(--muted); }
.option-badge.call { background: var(--blue-pale); color: var(--blue); }
.option-badge.put { background: var(--red-pale); color: var(--red); }
.counter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.counter-row span {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  font-size: 11px;
}
.counter-row strong { display: block; margin-top: 2px; color: var(--ink); font-size: 13px; }

.condition-list { display: grid; gap: 7px; }
.condition {
  display: grid;
  grid-template-columns: 29px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfc;
}
.condition b {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #edf1f0;
  color: var(--muted);
  font-size: 11px;
}
.condition strong, .condition span { display: block; }
.condition strong { font-size: 12px; }
.condition span { color: var(--muted); font-size: 10px; }
.condition em { color: var(--muted); font-size: 10px; font-style: normal; font-weight: 800; text-align: right; }
.condition.call { border-color: #cfe2f7; background: #f6faff; }
.condition.call b, .condition.call em { color: var(--blue); }
.condition.call b { background: var(--blue-pale); }
.condition.put { border-color: #f2d0d3; background: #fff8f8; }
.condition.put b, .condition.put em { color: var(--red); }
.condition.put b { background: var(--red-pale); }

.console-panel {
  margin-bottom: 17px;
  border-color: #20342e;
  background: #101d19;
  color: #e4f1ed;
}
.console-panel .eyebrow { color: #72cbb5; }
.console-panel h2 { color: #fff; }
.console-actions, .book-actions { display: flex; align-items: center; gap: 8px; }
.console-copy {
  padding: 7px 10px;
  border: 1px solid #2c403a;
  border-radius: 8px;
  background: #182824;
  color: #adc0bb;
  font-weight: 750;
}
.console-copy:hover { background: #21352f; }
.console-connection, .book-feed, .backend-connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #9db4ae;
  font-size: 10px;
  font-weight: 850;
}
.console-connection::before, .book-feed::before, .backend-connection::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d69b3d;
}
.console-connection.live { color: #71cbb4; }
.console-connection.live::before {
  background: #1dc99c;
  box-shadow: 0 0 0 3px rgba(29, 201, 156, .12);
}
.strategy-console {
  height: 185px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid #293c36;
  border-radius: 9px;
  background: #0a1512;
  color: #c0ded6;
  font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

.book-panel { padding-bottom: 0; }
.book-feed { color: var(--muted); }
.book-feed.live { color: var(--green); }
.book-feed.live::before { background: #13a37f; box-shadow: 0 0 0 3px #dff4ed; }
.book-feed.error { color: var(--red); }
.book-feed.error::before { background: var(--red); }
.book-feed.fallback, .backend-connection.fallback { color: #a06a16; }
.book-feed.fallback::before, .backend-connection.fallback::before { background: #d69b3d; }
.backend-connection { color: var(--muted); }
.backend-connection.live { color: var(--green); }
.backend-connection.live::before { background: #13a37f; box-shadow: 0 0 0 3px #dff4ed; }
.backend-connection.error { color: var(--red); }
.backend-connection.error::before { background: var(--red); }
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 9px 3px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.tab.active { border-color: var(--green); color: var(--green); }
.table-wrap { min-height: 210px; overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }
th { background: #fbfcfc; color: var(--muted); font-weight: 750; }
td.empty { padding: 58px; color: var(--muted); text-align: center; }

.broker-switcher { position: relative; }
.broker-button {
  min-width: 145px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}
.broker-button-dot { width: 8px; height: 8px; border-radius: 50%; background: #aab4b1; }
.broker-button.connected .broker-button-dot { background: #12a47f; box-shadow: 0 0 0 4px #e2f5ef; }
.chevron { color: var(--muted); font-size: 16px; }
.broker-menu {
  position: absolute;
  top: 46px;
  right: 0;
  z-index: 12;
  width: 330px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(12, 30, 25, .16);
}
.broker-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 10px;
  border-radius: 9px;
}
.broker-menu-item:hover { background: #f5f8f7; }
.broker-menu-main { min-width: 0; display: flex; align-items: center; gap: 9px; }
.broker-logo {
  flex: 0 0 auto;
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #e8f0ff;
  color: #2760ba;
  font-weight: 900;
}
.broker-menu-main strong, .broker-menu-main small {
  display: block;
  max-width: 165px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.broker-menu-main small { color: var(--muted); font-size: 10px; }
.broker-menu-actions { display: flex; gap: 3px; }
.menu-action {
  padding: 6px;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 11px;
  font-weight: 850;
  text-decoration: none;
}
.menu-action.delete { color: var(--red); font-size: 17px; }
.add-broker-menu {
  width: 100%;
  padding: 9px;
  border: 1px dashed #bdcbc7;
  border-radius: 9px;
  background: #f8faf9;
  color: var(--green);
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 24, 20, .56);
}
.hidden { display: none !important; }
.modal {
  width: min(560px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 23px;
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .25);
}
.modal.large { width: min(900px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 15px; }
.modal-head .subtle { margin-top: 3px; font-size: 12px; }
.icon-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #eef2f1;
  color: var(--muted);
  font-size: 21px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px; margin-top: 17px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
label { display: grid; gap: 6px; color: #53605d; font-size: 12px; font-weight: 750; }
.wide { grid-column: 1 / -1; }
input, select {
  width: 100%;
  height: 41px;
  padding: 0 10px;
  border: 1px solid #d6e0dd;
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { border-color: #57a997; box-shadow: 0 0 0 3px #e4f4ef; }
.modal-actions { justify-content: flex-end; gap: 9px; margin-top: 19px; }
.callback-note {
  margin: 11px 0 0;
  padding: 9px 11px;
  border: 1px solid #d8e5e1;
  border-radius: 9px;
  background: #f7faf9;
  color: var(--muted);
  font-size: 11px;
}
.callback-note code { color: var(--green-dark); font-weight: 800; word-break: break-all; }
.alert { margin: 11px 0; padding: 10px 12px; border-radius: 9px; }
.alert.danger { background: var(--red-pale); color: var(--red); }
.alert.success { background: var(--green-pale); color: var(--green); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 10% 10%, #e1f4ed, transparent 35%), var(--bg);
}
.login-card {
  width: min(410px, 100%);
  padding: 33px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}
.login-card .brand-mark { margin-bottom: 21px; }
.login-card h1 { margin-bottom: 2px; }
.stack { display: grid; gap: 14px; margin-top: 24px; }
.stack .button { margin-top: 3px; }

@media (max-width: 940px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .strategy-card-body { align-items: flex-start; flex-direction: column; }
  .form-grid.three { grid-template-columns: repeat(2, 1fr); }
}

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

@media (max-width: 620px) {
  .topbar { padding: 0 12px; }
  .brand small, .clock { display: none; }
  .broker-button { min-width: 0; padding: 0 10px; }
  .shell { width: min(100% - 22px, 1320px); padding-top: 20px; }
  .hero-row { align-items: stretch; flex-direction: column; }
  .button.emergency { width: 100%; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics article { padding: 13px; }
  .metrics strong { font-size: 19px; }
  .strategy-head { align-items: flex-start; }
  .strategy-info { grid-template-columns: 1fr; }
  .strategy-info div + div { padding-left: 0; border-top: 1px solid var(--line); border-left: 0; }
  .card-actions { flex-direction: column; }
  .card-actions .button { width: 100%; }
  .candle-block { align-items: flex-start; flex-direction: column; }
  .ohlc { width: 100%; grid-template-columns: repeat(4, 1fr); }
  .console-panel .section-heading, .book-panel .section-heading { align-items: flex-start; flex-direction: column; }
  .console-actions, .book-actions { flex-wrap: wrap; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .modal { padding: 18px; }
  .broker-menu { position: fixed; top: 70px; right: 11px; left: 11px; width: auto; }
}

@media (max-width: 410px) {
  .top-actions form { display: none; }
  .metrics { grid-template-columns: 1fr; }
  .indicator-grid, .position-grid, .counter-row { grid-template-columns: 1fr; }
  .condition { grid-template-columns: 29px 1fr; }
  .condition em { grid-column: 2; text-align: left; }
}
