:root {
  --canvas: #f2f4f0;
  --surface: #ffffff;
  --surface-muted: #f7f8f5;
  --surface-strong: #edf1ef;
  --line: #d9ded8;
  --line-strong: #bdc6be;
  --text: #1e2622;
  --text-soft: #66706a;
  --text-faint: #89958e;
  --sidebar: #202723;
  --sidebar-hover: #2a332e;
  --sidebar-text: #eef4f1;
  --green: #166443;
  --green-strong: #115637;
  --green-soft: #e4f1e9;
  --blue: #2b5f88;
  --blue-strong: #235172;
  --blue-soft: #e8f1f7;
  --amber: #b35b16;
  --amber-soft: #fff0e3;
  --red: #b6383f;
  --red-strong: #972d33;
  --red-soft: #fbeaec;
  --violet: #66539b;
  --violet-soft: #f0edf8;
  --teal: #18766f;
  --teal-soft: #e6f3f1;
  --shadow: 0 1px 2px rgba(21, 34, 27, .05);
  --shadow-lg: 0 18px 55px rgba(17, 28, 22, .18);
  --radius: 6px;
  --sidebar-width: 232px;
  --topbar-height: 58px;
}

html[data-theme="dark"] {
  --canvas: #111613;
  --surface: #181f1b;
  --surface-muted: #1d2621;
  --surface-strong: #25312b;
  --line: #2c3932;
  --line-strong: #405048;
  --text: #eef3f0;
  --text-soft: #a6b1ab;
  --text-faint: #7f8c85;
  --sidebar: #0c110e;
  --sidebar-hover: #1c2822;
  --sidebar-text: #eef4f1;
  --green: #59c785;
  --green-strong: #77d79c;
  --green-soft: #173425;
  --blue: #69b8d0;
  --blue-strong: #8bcadd;
  --blue-soft: #17323a;
  --amber: #e7b65e;
  --amber-soft: #3a2f1b;
  --red: #f2777c;
  --red-strong: #f6979b;
  --red-soft: #3d2024;
  --violet: #b1a2dc;
  --violet-soft: #302a43;
  --teal: #70c9c1;
  --teal-soft: #183936;
  --shadow: none;
  --shadow-lg: 0 22px 60px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--canvas);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; letter-spacing: 0; }
h1, h2, h3, h4, strong { font-weight: 600; }
button { cursor: pointer; }
button, input, select { outline: none; }
button:focus-visible, input:focus-visible, select:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 24%, transparent); }
[hidden] { display: none !important; }
svg { display: block; }

.side-nav {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  color: var(--sidebar-text);
  background: var(--sidebar);
  border-right: 1px solid color-mix(in srgb, var(--sidebar-text) 10%, transparent);
}
.brand-block {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  border-bottom: 1px solid color-mix(in srgb, var(--sidebar-text) 10%, transparent);
}
.brand-mark, .mobile-brand {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}
.brand-name { font-size: 15px; font-weight: 600; white-space: nowrap; }
.preview-badge {
  margin-left: auto;
  padding: 2px 5px;
  border: 1px solid color-mix(in srgb, var(--sidebar-text) 22%, transparent);
  border-radius: 4px;
  color: color-mix(in srgb, var(--sidebar-text) 68%, transparent);
  font-size: 10px;
}
.side-links { display: grid; gap: 2px; padding: 8px 10px; }
.nav-link {
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 4px;
  padding: 0 11px;
  background: transparent;
  color: color-mix(in srgb, var(--sidebar-text) 68%, transparent);
  text-align: left;
  font-weight: 600;
}
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }
.nav-link.active { color: #fff; border-left-color: #50ad77; background: #303a34; }
.side-account {
  min-height: 64px;
  margin: auto 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid #3a443e;
  border-radius: 6px;
  background: #29312d;
}
.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--sidebar-text) 12%, transparent);
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 600;
}
.avatar.small { width: 28px; height: 28px; background: var(--surface-strong); color: var(--text); }
.account-meta { min-width: 0; display: grid; line-height: 1.2; }
.account-meta strong { font-size: 13px; }
.account-meta small { margin-top: 3px; color: color-mix(in srgb, var(--sidebar-text) 58%, transparent); font-size: 10px; }
.online-dot { width: 7px; height: 7px; margin-left: auto; border-radius: 50%; background: #5bd58d; box-shadow: 0 0 0 3px rgba(91, 213, 141, .12); }

.top-bar {
  position: fixed;
  inset: 0 0 auto var(--sidebar-width);
  z-index: 25;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 26px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.top-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-title h1 { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; }
.top-title p { margin: 3px 0 0; color: var(--text-faint); font-size: 10px; }
.mobile-brand { display: none; }
.top-tools { min-width: 0; display: flex; align-items: center; gap: 8px; }
.runtime-badge {
  height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.runtime-badge.live { background: var(--green-soft); color: var(--green); }
.runtime-badge.offline { background: var(--red-soft); color: var(--red); }
.runtime-badge svg { width: 13px; height: 13px; }
.draw-clock {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.draw-clock strong { color: var(--text); font-size: 13px; }
.draw-period { max-width: 128px; overflow: hidden; text-overflow: ellipsis; }
.pulse-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.pulse-dot.large { width: 9px; height: 9px; box-shadow: 0 0 0 4px var(--green-soft); }
.pulse-dot.stopped { background: var(--text-faint); box-shadow: 0 0 0 3px var(--surface-strong); }
.icon-button, .secondary-button, .primary-button, .success-button, .danger-button, .danger-solid-button, .text-button, .user-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 6px;
  font-weight: 600;
}
.icon-button svg, .secondary-button svg, .primary-button svg, .success-button svg, .danger-button svg, .danger-solid-button svg, .text-button svg, .user-button svg { width: 16px; height: 16px; }
.icon-button { width: 36px; padding: 0; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-soft); }
.icon-button:hover, .secondary-button:hover { background: var(--surface-muted); color: var(--text); }
.secondary-button, .primary-button, .success-button, .danger-button, .danger-solid-button {
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
}
.primary-button { border-color: var(--green); background: var(--green); color: #fff; }
.primary-button:hover { border-color: var(--green-strong); background: var(--green-strong); }
.success-button { border-color: var(--green); background: var(--green); color: #fff; }
.success-button:hover { border-color: var(--green-strong); background: var(--green-strong); }
.danger-button { border-color: color-mix(in srgb, var(--red) 46%, var(--line)); color: var(--red); }
.danger-button:hover { background: var(--red-soft); }
.danger-solid-button { border-color: var(--red); background: var(--red); color: #fff; }
.danger-solid-button:hover { border-color: var(--red-strong); background: var(--red-strong); }
button:disabled { cursor: wait; opacity: .55; }
.is-busy svg { animation: spin .7s linear infinite; }
.text-button { min-height: 30px; padding: 0; border: 0; background: transparent; color: var(--blue); }
.text-button:hover { color: var(--blue-strong); }
.formula-mode-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid color-mix(in srgb, var(--green) 48%, var(--line));
  border-radius: 6px;
  background: var(--green-soft);
  color: var(--green-strong);
  font-weight: 600;
  white-space: nowrap;
}
.formula-mode-button:hover { border-color: var(--green); background: color-mix(in srgb, var(--green-soft) 78%, var(--surface)); }
.formula-mode-button svg { width: 15px; height: 15px; }
.formula-mode-button svg:last-child { width: 13px; height: 13px; }
.user-button { height: 36px; padding: 0 8px 0 4px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.user-button svg { width: 13px; height: 13px; color: var(--text-faint); }
.icon-button.spinning svg { animation: spin .42s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.small-button { min-height: 32px; padding: 0 10px; }
.full-button { width: calc(100% - 28px); margin: 12px 14px 14px; }

.main-content {
  min-width: 0;
  margin-left: var(--sidebar-width);
  padding: calc(var(--topbar-height) + 24px) 28px 48px;
}
.view { display: none; width: min(100%, 1480px); margin: 0 auto; }
.view.active { display: block; }
.page-heading {
  min-height: 82px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}
.page-heading h2 { margin: 0; font-size: 21px; font-weight: 600; }
.page-heading p { margin: 5px 0 0; color: var(--text-soft); font-size: 12px; }
.page-actions { display: flex; align-items: center; gap: 8px; }

.summary-strip {
  display: grid;
  grid-template-columns: 1.25fr repeat(3, 1fr);
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.summary-cell { min-width: 0; min-height: 96px; padding: 14px 16px; border-right: 1px solid var(--line); }
.summary-cell.primary-cell { background: color-mix(in srgb, var(--green-soft) 58%, var(--surface)); }
.summary-cell:last-child { border-right: 0; }
.summary-cell small { display: block; margin-top: 7px; overflow: hidden; color: var(--text-soft); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.metric-label { color: var(--text-soft); font-size: 11px; font-weight: 600; }
.metric-value { display: block; margin-top: 8px; font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-value.good, .positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.live-state { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.live-state strong { font-size: 16px; }

.command-panel {
  min-height: 98px;
  display: grid;
  grid-template-columns: 62px minmax(270px, 1.4fr) minmax(170px, .65fr) minmax(120px, .45fr) 36px;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--blue) 35%, var(--line));
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.command-symbol { width: 58px; height: 58px; display: grid; place-items: center; align-content: center; border-radius: 6px; background: var(--blue-soft); color: var(--blue); }
.command-symbol span { font-size: 20px; font-weight: 700; line-height: 1; }
.command-symbol small { margin-top: 5px; font-size: 9px; }
.eyebrow { color: var(--blue); font-size: 11px; font-weight: 600; }
.command-main { display: flex; align-items: baseline; gap: 7px; margin-top: 5px; font-size: 18px; font-weight: 600; }
.command-main b { font-size: 25px; font-variant-numeric: tabular-nums; }
.command-main span { color: var(--text-faint); font-weight: 400; }
.command-source { margin-top: 5px; color: var(--text-soft); font-size: 11px; }
.direction-block, .command-timing { min-width: 0; padding-left: 16px; border-left: 1px solid var(--line); }
.direction-block > div { display: flex; align-items: center; gap: 9px; margin-top: 7px; }
.direction-block > div > span { display: grid; line-height: 1.2; }
.direction-block b { font-size: 14px; }
.direction-block small, .command-timing small { margin-top: 3px; color: var(--text-faint); font-size: 10px; }
.direction-code { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 5px; font-size: 16px; }
.direction-code.normal { background: var(--green-soft); color: var(--green); }
.direction-code.reverse { background: var(--red-soft); color: var(--red); }
.direction-code.unknown { background: var(--surface-strong); color: var(--text-soft); font-size: 12px; }
.command-timing { display: grid; }
.command-timing strong { margin-top: 7px; font-size: 14px; font-variant-numeric: tabular-nums; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 12px; margin-top: 12px; }
.panel { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-header { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel-header h3 { margin: 0; font-size: 14px; }
.panel-header p { margin: 4px 0 0; color: var(--text-faint); font-size: 10px; }
.order-list { display: grid; }
.compact-orders { min-height: 0; overflow-anchor: none; }
.full-records-panel .order-list { overflow-anchor: none; }
.order-row {
  position: relative;
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(92px, .68fr) minmax(180px, 1.35fr) minmax(110px, .72fr) minmax(90px, .58fr);
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 16px;
  border-bottom: 1px solid var(--line);
}
.order-row:last-child { border-bottom: 0; }
.order-row::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--text-faint); }
.order-row.win::before { background: var(--green); }
.order-row.lose::before { background: var(--red); }
.order-row > div { min-width: 0; }
.order-period, .order-draw, .order-money { display: grid; gap: 4px; }
.order-period strong, .order-money strong { font-variant-numeric: tabular-nums; }
.order-period small, .order-draw small, .order-money small, .order-plan small { color: var(--text-faint); font-size: 10px; }
.order-plan { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.order-plan strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.order-plan small { flex-basis: 100%; margin-left: 0; }
.order-draw span { font-weight: 600; }
.draw-result { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.draw-result b { border-radius: 3px; padding: 2px 5px; background: var(--surface-strong); color: var(--text-soft); font-size: 9px; line-height: 1.2; }
.draw-result.win b { background: var(--green-soft); color: var(--green); }
.draw-result.lose b { background: var(--red-soft); color: var(--red); }
.draw-result > span { color: var(--text-faint); font-size: 10px; font-weight: 400; }
.order-money { text-align: right; }
.order-money.unavailable strong { color: var(--text-faint); }
.direction-badge, .status-badge {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.direction-badge.normal { background: var(--green-soft); color: var(--green); }
.direction-badge.reverse { background: var(--red-soft); color: var(--red); }
.direction-badge.neutral { background: var(--blue-soft); color: var(--blue); }
.status-badge svg { width: 13px; height: 13px; }
.status-badge.running, .status-badge.stable { background: var(--green-soft); color: var(--green); }
.status-badge.stopped { background: var(--surface-strong); color: var(--text-soft); }
.status-badge.pending { background: var(--amber-soft); color: var(--amber); }
.status-badge.observe { background: var(--surface-strong); color: var(--text-soft); }
.status-badge.candidate { background: var(--blue-soft); color: var(--blue); }
.status-badge.selected { background: var(--green-soft); color: var(--green); }

.selected-route { min-height: 74px; display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 10px; padding: 12px 14px; background: var(--green-soft); border-bottom: 1px solid color-mix(in srgb, var(--green) 18%, var(--line)); }
.route-version { width: 44px; height: 36px; display: grid; place-items: center; border-radius: 5px; background: var(--green); color: #fff; font-weight: 700; }
.selected-route div { display: grid; gap: 3px; min-width: 0; }
.selected-route div span { color: var(--green); font-size: 10px; font-weight: 600; }
.selected-route div strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.route-score { font-size: 20px; font-variant-numeric: tabular-nums; }
.route-list { display: grid; padding: 5px 0; }
.route-row { min-height: 34px; display: grid; grid-template-columns: 34px 1fr 40px 34px; align-items: center; gap: 8px; padding: 0 14px; color: var(--text-soft); font-size: 11px; }
.route-row > span, .route-row > strong { color: var(--text); font-variant-numeric: tabular-nums; }
.route-row small { text-align: right; }
.route-row.active { background: var(--surface-muted); }
.score-track { height: 5px; overflow: hidden; border-radius: 3px; background: var(--surface-strong); }
.score-track i { display: block; height: 100%; border-radius: 3px; background: var(--blue); }
.route-row.active .score-track i { background: var(--green); }

.formula-library-panel {
  min-height: 650px;
  overflow: hidden;
  background: var(--surface-muted);
}
.formula-library-frame {
  display: block;
  width: 100%;
  height: 650px;
  border: 0;
  background: var(--surface-muted);
}

.signal-band { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.signal-band > div { min-height: 68px; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-right: 1px solid var(--line); }
.signal-band > div:last-child { border-right: 0; }
.signal-band > div > span:last-child { display: grid; gap: 3px; }
.signal-band strong { font-size: 12px; }
.signal-band small { overflow: hidden; color: var(--text-soft); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.signal-icon, .module-icon, .connection-icon, .master-icon { display: grid; place-items: center; flex: none; border-radius: 6px; }
.signal-icon { width: 34px; height: 34px; }
.signal-icon svg { width: 17px; height: 17px; }
.signal-icon.green, .module-icon.green { background: var(--green-soft); color: var(--green); }
.signal-icon.amber, .module-icon.amber { background: var(--amber-soft); color: var(--amber); }
.signal-icon.blue, .module-icon.blue { background: var(--blue-soft); color: var(--blue); }
.module-icon.violet { background: var(--violet-soft); color: var(--violet); }
.module-icon.teal { background: var(--teal-soft); color: var(--teal); }
.module-icon.red { background: var(--red-soft); color: var(--red); }

.master-control { min-height: 90px; display: grid; grid-template-columns: 1.2fr .8fr auto; align-items: center; gap: 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.master-state { display: flex; align-items: center; gap: 12px; min-width: 0; }
.master-icon { width: 46px; height: 46px; background: var(--green-soft); color: var(--green); }
.master-icon svg { width: 22px; height: 22px; }
.master-state > div, .master-draw { display: grid; gap: 3px; min-width: 0; }
.master-state span, .master-draw span { color: var(--text-soft); font-size: 10px; }
.master-state strong { font-size: 16px; }
.master-state small, .master-draw small { color: var(--text-faint); font-size: 10px; }
.master-draw { padding-left: 18px; border-left: 1px solid var(--line); }
.master-draw strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.master-actions { display: flex; gap: 8px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 20px 2px 10px; }
.section-heading h3 { margin: 0; font-size: 15px; }
.section-heading p { margin: 4px 0 0; color: var(--text-soft); font-size: 10px; }
.section-heading > span { color: var(--text-soft); font-size: 11px; }
.module-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.module-card { min-width: 0; min-height: 176px; display: grid; grid-template-rows: auto 1fr auto; padding: 13px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.module-card.active-module { border-top: 3px solid var(--green); padding-top: 11px; }
.module-head { min-width: 0; display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; }
.module-icon { width: 38px; height: 38px; }
.module-icon svg { width: 18px; height: 18px; }
.module-head > div { min-width: 0; }
.module-head h4 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.module-head p { margin: 4px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-faint); font-size: 10px; }
.module-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-items: center; margin: 13px 0 11px; }
.module-stats div { min-width: 0; display: grid; gap: 4px; }
.module-stats span { color: var(--text-faint); font-size: 9px; }
.module-stats strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.module-foot { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
.module-foot .icon-button { width: 32px; min-height: 32px; }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; flex: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span { position: absolute; inset: 0; border-radius: 11px; background: var(--line-strong); transition: background .16s ease; }
.switch > span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .22); transition: transform .16s ease; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }

.route-matrix-panel { margin-top: 14px; }
.segmented { display: inline-flex; align-items: center; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-muted); }
.segmented button { min-width: 72px; height: 30px; border: 0; border-radius: 4px; padding: 0 10px; background: transparent; color: var(--text-soft); font-size: 11px; font-weight: 600; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(18, 28, 23, .08); }
.segmented button span { margin-left: 3px; color: var(--text-faint); }
.mini-segmented button { min-width: 52px; height: 27px; }
.matrix-table-wrap { overflow-x: auto; }
.matrix-table { width: 100%; min-width: 760px; border-collapse: collapse; table-layout: fixed; }
.matrix-table th, .matrix-table td { height: 44px; padding: 0 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.matrix-table tr:last-child td { border-bottom: 0; }
.matrix-table th { height: 38px; background: var(--surface-muted); color: var(--text-soft); font-size: 10px; font-weight: 600; }
.matrix-table td { font-size: 12px; font-variant-numeric: tabular-nums; }
.matrix-table tbody tr:hover { background: var(--surface-muted); }
.matrix-table tbody tr.selected { background: var(--green-soft); }

.record-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.search-field { width: 220px; height: 36px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.search-field svg { width: 15px; height: 15px; flex: none; color: var(--text-faint); }
.search-field input { width: 100%; min-width: 0; border: 0; background: transparent; color: var(--text); }
.search-field input::placeholder { color: var(--text-faint); }
.record-column-head { min-height: 38px; display: grid; grid-template-columns: minmax(110px, .68fr) minmax(220px, 1.35fr) minmax(130px, .72fr) minmax(110px, .58fr); align-items: center; gap: 12px; padding: 0 14px 0 16px; border-bottom: 1px solid var(--line); background: var(--surface-muted); color: var(--text-soft); font-size: 10px; font-weight: 600; }
.record-column-head span:last-child { text-align: right; }
.full-records-panel .order-row { min-height: 76px; }
.empty-state { min-height: 240px; display: grid; place-items: center; align-content: center; gap: 10px; color: var(--text-faint); }
.empty-state svg { width: 28px; height: 28px; }

.account-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wide-settings { grid-column: 1 / -1; }
.settings-panel .form-grid { padding: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { min-width: 0; display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field > span, .section-label { color: var(--text-soft); font-size: 10px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 10px; background: var(--surface); color: var(--text); }
.field input, .field select { height: 38px; }
.field textarea { min-height: 108px; padding: 9px 10px; resize: vertical; line-height: 1.5; }
.field input[readonly] { background: var(--surface-muted); color: var(--text-soft); }
.field small { color: var(--text-faint); font-size: 9px; }
.connection-row { min-height: 76px; display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 11px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.connection-icon { width: 42px; height: 42px; background: var(--blue-soft); color: var(--blue); }
.connection-icon svg { width: 20px; height: 20px; }
.connection-row > div { display: grid; gap: 4px; min-width: 0; }
.connection-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-faint); font-size: 10px; }
.channel-form { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.telegram-layout { display: grid; grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr) auto; align-items: end; gap: 12px; padding: 14px; }
.telegram-layout > button { min-width: 112px; }
.telegram-state { min-height: 38px; display: flex; align-items: center; gap: 9px; color: var(--text-soft); font-size: 11px; }
.telegram-state .online-dot { margin-left: 0; }
.target-window-section { display: grid; gap: 12px; padding: 14px; border-top: 1px solid var(--line); }
.target-window-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.target-window-heading > div { min-width: 0; display: grid; gap: 3px; }
.target-window-heading strong { font-size: 12px; }
.target-window-heading small { color: var(--text-faint); font-size: 10px; }
.target-window-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; }
.target-window-form > button { min-width: 142px; }
.target-window-result { min-height: 62px; display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-left: 3px solid var(--green); border-radius: 0 4px 4px 0; background: var(--green-soft); }
.target-window-result.loading { border-left-color: var(--blue); background: var(--blue-soft); }
.target-window-result.error { border-left-color: var(--red); background: var(--red-soft); }
.target-window-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 6px; background: var(--surface); color: var(--green); }
.target-window-result.loading .target-window-icon { color: var(--blue); }
.target-window-result.loading .target-window-icon svg { animation: spin .7s linear infinite; }
.target-window-result.error .target-window-icon { color: var(--red); }
.target-window-icon svg { width: 18px; height: 18px; }
.target-window-copy { min-width: 0; flex: 1; display: grid; gap: 4px; }
.target-window-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.target-window-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); font-size: 10px; }
.target-window-bound { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; color: var(--green-strong); font-size: 10px; font-weight: 600; white-space: nowrap; }
.target-window-bound svg { width: 15px; height: 15px; }
.setting-rows { padding: 0 14px; }
.setting-rows.two-columns { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
.setting-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.two-columns .setting-row:nth-last-child(2) { border-bottom: 0; }
.setting-row > div { min-width: 0; display: grid; gap: 4px; }
.setting-row strong { font-size: 12px; }
.setting-row small { color: var(--text-faint); font-size: 10px; line-height: 1.35; }

.dialog-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(13, 22, 17, .52); }
.config-dialog { width: min(520px, 100%); max-height: calc(100vh - 36px); display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-lg); }
.formula-mode-dialog { width: min(420px, 100%); }
.formula-auto-status { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.formula-auto-status span, .formula-auto-status small { color: var(--text-faint); font-size: 10px; }
.formula-auto-status strong { font-size: 13px; }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.dialog-header > div { display: grid; gap: 3px; }
.dialog-header span { color: var(--text-faint); font-size: 9px; }
.dialog-header h2 { margin: 0; font-size: 16px; }
.dialog-body { min-height: 0; overflow-y: auto; padding: 14px; }
.dialog-form { margin-bottom: 14px; }
.dialog-section { padding: 13px 0; border-top: 1px solid var(--line); }
.dialog-section .section-label { display: block; margin-bottom: 8px; }
.dialog-segmented { width: 100%; }
.dialog-segmented button { flex: 1; }
.direction-setting { min-height: 48px; display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; }
.direction-setting > div { display: grid; gap: 3px; }
.direction-setting small { color: var(--text-faint); font-size: 10px; }
.dialog-settings { padding: 0; border-top: 1px solid var(--line); }
.dialog-footer { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.confirm-dialog { width: min(390px, 100%); padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-lg); text-align: center; }
.confirm-icon { width: 44px; height: 44px; display: grid; place-items: center; margin: 0 auto 12px; border-radius: 50%; background: var(--red-soft); color: var(--red); }
.confirm-icon svg { width: 21px; height: 21px; }
.confirm-dialog h2 { margin: 0; font-size: 16px; }
.confirm-dialog p { margin: 8px 0 18px; color: var(--text-soft); font-size: 12px; line-height: 1.55; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.auth-gate { position: fixed; inset: 0; z-index: 180; display: grid; place-items: center; padding: 18px; background: var(--canvas); }
.auth-card { width: min(420px, 100%); padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand h1 { margin: 0; font-size: 19px; }
.auth-brand p { margin: 4px 0 0; color: var(--text-soft); font-size: 11px; }
.auth-tabs { width: 100%; margin-bottom: 16px; }
.auth-tabs button { flex: 1; }
.auth-form { display: grid; gap: 12px; }
.auth-form .field input { height: 42px; }
.auth-submit { width: 100%; min-height: 42px; margin-top: 4px; }
.auth-message { min-height: 17px; margin: 12px 0 0; color: var(--red); font-size: 11px; text-align: center; }
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 150; min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 14px; border-radius: 6px; background: var(--sidebar); color: #fff; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast svg { width: 16px; height: 16px; color: #6add96; }
.toast.error svg { color: var(--red); }
.mobile-nav, .mobile-control-bar { display: none; }

@media (max-width: 1180px) {
  :root { --sidebar-width: 76px; }
  .brand-block { justify-content: center; padding: 0; }
  .brand-name, .preview-badge, .nav-link span, .account-meta, .online-dot { display: none; }
  .side-links .nav-link { justify-content: center; padding: 0; }
  .side-account { justify-content: center; padding: 12px 0; }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1040px) and (min-width: 761px) {
  .runtime-badge { display: none; }
  .user-button [data-username] { display: none; }
  .user-button { width: 36px; padding: 0; }
}

@media (max-width: 920px) {
  .summary-strip { grid-template-columns: 1fr 1fr; }
  .summary-cell:nth-child(2) { border-right: 0; }
  .summary-cell:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .command-panel { grid-template-columns: 62px 1fr minmax(160px, .55fr) 36px; }
  .command-timing { display: none; }
  .overview-grid { grid-template-columns: 1fr; }
  .signal-band { grid-template-columns: 1fr; }
  .signal-band > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .signal-band > div:last-child { border-bottom: 0; }
  .master-control { grid-template-columns: 1fr auto; }
  .master-draw { display: none; }
}

@media (max-width: 760px) {
  :root { --topbar-height: 58px; }
  .side-nav { display: none; }
  .top-bar { left: 0; gap: 8px; padding: 0 10px; }
  .top-title { gap: 8px; }
  .mobile-brand { width: 32px; height: 32px; display: grid; }
  .top-title h1 { max-width: 86px; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
  .top-title p, .draw-period, .runtime-badge, .theme-button, .user-button { display: none; }
  .draw-clock { height: 34px; padding: 0 8px; }
  .main-content { margin-left: 0; padding: calc(var(--topbar-height) + 13px) 10px calc(126px + env(safe-area-inset-bottom)); }
  .page-heading { min-height: 0; align-items: center; justify-content: flex-end; margin-bottom: 10px; }
  .page-heading > div:first-child { display: none; }
  .page-actions .engine-stop, .page-actions .secondary-button { display: none; }
  .summary-cell { min-height: 82px; padding: 12px; }
  .metric-value { margin-top: 6px; font-size: 20px; }
  .summary-cell small { margin-top: 5px; }
  .command-panel { grid-template-columns: 52px 1fr 34px; gap: 10px; padding: 11px; }
  .command-symbol { width: 50px; height: 50px; }
  .command-main { gap: 5px; font-size: 15px; }
  .command-main b { font-size: 21px; }
  .command-source { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .direction-block { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .direction-block > div { margin-top: 0; }
  .command-config { grid-column: 3; grid-row: 1; }
  .overview-grid { margin-top: 10px; }
  .panel-header { min-height: 48px; }
  .compact-orders .order-row:nth-child(n+4) { display: none; }
  .compact-orders { min-height: 0; }
  .order-row { min-height: 86px; grid-template-columns: 1fr auto; grid-template-areas: "period money" "plan draw"; gap: 8px 12px; padding: 11px 12px 11px 15px; }
  .order-period { grid-area: period; }
  .order-plan { grid-area: plan; }
  .order-draw { grid-area: draw; text-align: right; }
  .draw-result { justify-content: flex-end; }
  .order-money { grid-area: money; }
  .order-plan strong { max-width: 160px; }
  .selected-route { min-height: 68px; }
  .formula-library-panel { min-height: 720px; }
  .formula-library-frame { height: 720px; }
  .signal-band { margin-top: 10px; }
  .master-control { min-height: 74px; display: block; padding: 12px; }
  .master-actions { display: none; }
  .module-grid { grid-template-columns: 1fr; }
  .module-card { min-height: 166px; }
  .route-matrix-panel .panel-header { align-items: flex-start; }
  .mini-segmented { flex: none; }
  .mini-segmented button { min-width: 38px; padding: 0 6px; }
  .matrix-table { min-width: 0; table-layout: auto; }
  .matrix-table th, .matrix-table td { padding: 0 9px; }
  .matrix-table th:nth-child(2), .matrix-table td:nth-child(2), .matrix-table th:nth-child(3), .matrix-table td:nth-child(3), .matrix-table th:nth-child(5), .matrix-table td:nth-child(5) { display: none; }
  .record-toolbar { align-items: stretch; flex-direction: column; }
  .record-toolbar .segmented { width: 100%; }
  .record-toolbar .segmented button { min-width: 0; flex: 1; padding: 0 5px; }
  .search-field { width: 100%; }
  .record-column-head { display: none; }
  .full-records-panel .order-row { min-height: 96px; }
  .account-layout { grid-template-columns: 1fr; }
  .wide-settings { grid-column: auto; }
  .setting-rows.two-columns { display: block; }
  .two-columns .setting-row:nth-last-child(2) { border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .telegram-layout { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
  .target-window-form { grid-template-columns: 1fr; }
  .target-window-form > button { width: 100%; }
  .target-window-result { align-items: flex-start; flex-wrap: wrap; }
  .target-window-bound { width: 100%; margin-left: 47px; }
  .mobile-control-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(63px + env(safe-area-inset-bottom));
    z-index: 45;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 10px;
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    backdrop-filter: blur(12px);
  }
  .mobile-control-bar > div { min-width: 0; display: flex; align-items: center; gap: 9px; }
  .mobile-control-bar > div > span:last-child { display: grid; gap: 1px; }
  .mobile-control-bar small { color: var(--text-faint); font-size: 9px; }
  .mobile-control-bar strong { font-size: 11px; }
  .mobile-control-bar button { min-height: 38px; }
  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 50;
    height: calc(64px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: var(--surface);
  }
  .mobile-nav .nav-link { height: 63px; justify-content: center; flex-direction: column; gap: 4px; padding: 0; border-radius: 0; color: var(--text-faint); font-size: 10px; }
  .mobile-nav .nav-link span { display: block; }
  .mobile-nav .nav-link svg { width: 19px; height: 19px; }
  .mobile-nav .nav-link:hover { background: transparent; color: var(--text); }
  .mobile-nav .nav-link.active { background: transparent; color: var(--green); }
  .dialog-backdrop { align-items: end; padding: 0; }
  .config-dialog { width: 100%; max-height: calc(100vh - 24px); border-right: 0; border-bottom: 0; border-left: 0; border-radius: 8px 8px 0 0; }
  .toast { bottom: calc(128px + env(safe-area-inset-bottom)); }
}

@media (max-width: 390px) {
  .top-title h1 { max-width: 70px; }
  .summary-cell { padding: 11px 10px; }
  .summary-cell small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-actions .primary-button { padding: 0 9px; }
  .direction-setting { grid-template-columns: 34px 1fr auto; }
  .auth-card { padding: 20px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
