:root {
  --bg: #12100e;
  --surface: #1c1915;
  --surface-2: #241f1a;
  --line: rgba(243, 239, 232, 0.09);
  --text: #f4efe7;
  --muted: #9a9084;
  --gold: #d4a25a;
  --gold-2: #e0b56d;
  --green: #6fbf8a;
  --red: #e06b5c;
  --sans: "DM Sans", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(900px 420px at 8% -20%, rgba(212,162,90,.14), transparent 55%),
    radial-gradient(700px 320px at 100% 0%, rgba(90,70,40,.08), transparent 50%),
    linear-gradient(180deg, #17140f 0%, var(--bg) 45%, #0e0c0a 100%);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--gold); text-decoration: none; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Auth */
body:not(.app-body) {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px;
}
.auth-card h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: .06em;
  font-weight: 700;
}
.sub { color: var(--muted); margin: 6px 0 18px; font-size: 13px; }
.err { color: var(--red); min-height: 1.2em; font-size: 13px; margin-bottom: 6px; }
.links { text-align: center; margin-top: 16px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 12px; }
.field label, label {
  display: block;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .04em;
}
input, select, button {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #151210;
  color: var(--text);
  padding: 10px 12px;
}
input:focus, select:focus {
  outline: none;
  border-color: rgba(212,162,90,.55);
  box-shadow: 0 0 0 3px rgba(212,162,90,.14);
}
button { cursor: pointer; font-weight: 600; }
.primary, .auth-card button {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #1a1208;
  border: none;
  margin-top: 8px;
}
.primary.soft { margin-top: 10px; padding: 9px 12px; }
.primary:hover { filter: brightness(1.05); }
.danger-btn, .ghost-btn.danger {
  background: transparent;
  border: 1px solid rgba(224,107,92,.45);
  color: var(--red);
  margin-top: 10px;
}
.ghost-btn {
  width: auto;
  margin: 0;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  border-radius: 999px;
}

/* One page shell */
.app-body { min-height: 100dvh; }
.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}
.brand-name {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: .05em;
  line-height: 1;
}
.brand-sub { margin-top: 4px; color: var(--muted); font-size: 12px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.clock { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.badge.on {
  color: var(--green);
  border-color: rgba(111,191,138,.35);
  background: rgba(111,191,138,.1);
}
.badge.off { color: var(--muted); }

.slot-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  justify-content: center;
}
.slot-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
}
.slot-tabs::-webkit-scrollbar { display: none; }
.slot-tab {
  width: auto;
  margin: 0;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  flex: 0 0 auto;
}
.slot-tab.active {
  border-color: rgba(212,162,90,.55);
  background: rgba(212,162,90,.14);
  color: var(--gold);
}

.kpi {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.kpi-item {
  background: rgba(28,25,21,.96);
  padding: 11px 12px;
  min-width: 0;
}
.kpi-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 5px;
}
.kpi-item b {
  display: block;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto auto;
  align-items: stretch;
  gap: 10px;
}
.box {
  background: rgba(28,25,21,.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
.box-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 10px;
  flex: 0 0 auto;
}
/* 两行三列：上行策略/镜像/参数，下行 API + 日志（占两列） */
.control { grid-column: 1; grid-row: 1; }
.mirror  { grid-column: 2; grid-row: 1; }
.params  { grid-column: 3; grid-row: 1; }
.api     { grid-column: 1; grid-row: 2; }
.logs    { grid-column: 2 / 4; grid-row: 2; }

.status-line {
  font-size: 13px;
  margin-bottom: 4px;
}
.status-line.muted, .note {
  color: var(--muted);
  font-size: 11px;
}
.dot { color: var(--muted); margin: 0 4px; }
.note { margin-top: 10px; line-height: 1.4; }

.rows {
  display: grid;
  gap: 0;
  flex: 1 1 auto;
}
.rows > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.rows > div:last-child { border-bottom: none; }
.rows span { color: var(--muted); }
.rows b { font-weight: 600; text-align: right; }

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: 1 1 auto;
  align-content: start;
}
.fields label { margin: 0; }
.fields input, .fields select {
  margin-top: 4px;
  padding: 8px 10px;
  font-size: 13px;
}

.api-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1 1 auto;
}
.api-form input, .api-form select, .api-form button { margin: 0; }
.api-form .primary,
.params .primary,
.params .btn-pair,
.control .primary,
.api .danger-btn {
  margin-top: auto;
}
.btn-pair {
  display: flex;
  gap: 8px;
  margin-top: auto;
}
.btn-pair .primary,
.btn-pair .ghost-btn {
  margin-top: 0;
  flex: 1;
}
.ghost-btn.wide {
  width: auto;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
}
.params.locked input,
.params.locked select {
  opacity: 0.72;
  cursor: not-allowed;
  background: #100e0c;
}
#apiPass[hidden], #apiPass.hidden { display: none !important; }

#logs {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 7.2em; /* 约 4 行 */
  max-height: 12em;
  overflow: auto;
}
#logs li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.35;
}
#logs .log-time {
  font-family: var(--mono);
  color: var(--muted);
  margin-right: 6px;
  font-size: 10px;
}
#logs .log-warn { color: var(--gold-2); }
#logs .log-error { color: var(--red); }
.empty { color: var(--muted); font-size: 12px; padding: 8px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  z-index: 50;
  font-size: 13px;
  max-width: min(92vw, 360px);
  box-shadow: 0 12px 36px rgba(0,0,0,.35);
}

@media (min-width: 980px) {
  .app-body { overflow: auto; }
}

@media (max-width: 979px) {
  .top {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .slot-bar { justify-content: flex-start; }
  .top-right { justify-content: space-between; }
  .kpi { grid-template-columns: repeat(3, 1fr); }
  .grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }
  .control { grid-column: 1; grid-row: auto; }
  .mirror  { grid-column: 2; grid-row: auto; }
  .params  { grid-column: 1; grid-row: auto; }
  .api     { grid-column: 2; grid-row: auto; }
  .logs    { grid-column: 1 / -1; grid-row: auto; }
  #logs { min-height: 7.2em; max-height: 11em; }
}

@media (max-width: 560px) {
  .kpi { grid-template-columns: repeat(2, 1fr); }
  .kpi-item b { font-size: 15px; }
  .grid { grid-template-columns: 1fr; }
  .control, .mirror, .params, .api, .logs {
    grid-column: 1;
  }
  .fields { grid-template-columns: 1fr; }
  .brand-name { font-size: 22px; }
}
