:root {
  color-scheme: light;
  --ink: #18201f;
  --muted: #66716f;
  --subtle: #8a9492;
  --line: #dce2e0;
  --line-strong: #cbd3d0;
  --surface: #ffffff;
  --canvas: #f3f5f4;
  --sidebar: #191d1c;
  --sidebar-muted: #9ba6a2;
  --primary: #087a5b;
  --primary-hover: #06664c;
  --primary-soft: #e7f5ef;
  --amber: #a85d0a;
  --amber-soft: #fff3df;
  --danger: #b42318;
  --danger-soft: #fff0ee;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
}
button, input, select { font: inherit; }
button { letter-spacing: 0; }

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  border-radius: 7px;
  color: #fff;
  background: var(--primary);
  font-size: 17px;
  font-weight: 750;
}
.brand-copy strong { display: block; color: inherit; font-size: 15px; }
.brand-copy span { display: block; margin-top: 2px; color: var(--sidebar-muted); font-size: 11px; }

.auth-shell { min-height: 100vh; display: grid; grid-template-rows: 64px 1fr; }
.auth-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 28px;
  color: #fff;
  background: var(--sidebar);
  border-bottom: 3px solid var(--primary);
}
.auth-main {
  display: grid;
  place-items: center;
  padding: 32px 18px;
  background: var(--canvas);
}
.auth-card {
  width: min(410px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 14px 40px rgba(27, 39, 35, 0.08);
}
.auth-card h1 { margin: 0; font-size: 22px; font-weight: 700; }
.auth-card > p { margin: 8px 0 24px; color: var(--muted); line-height: 1.6; }
.auth-card .field { margin-bottom: 14px; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-meta { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--subtle); font-size: 12px; }

.console-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #f4f7f6;
  background: var(--sidebar);
  border-right: 1px solid #2b302f;
}
.sidebar-brand { min-height: 72px; display: flex; align-items: center; gap: 10px; padding: 0 20px; border-bottom: 1px solid #2b302f; }
.tabs { display: grid; gap: 4px; padding: 18px 12px; }
.tab {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  color: #c8cfcd;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.tab:hover { color: #fff; background: #242a28; }
.tab.active { color: #fff; background: #2b3431; box-shadow: inset 3px 0 0 var(--primary); font-weight: 650; }
.sidebar-footer { margin-top: auto; padding: 14px 16px 18px; border-top: 1px solid #2b302f; }
.connection-state { display: flex; align-items: center; gap: 8px; color: #dce4e1; font-size: 12px; }
.connection-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #777f7d; }
.connection-state.online::before { background: #42c493; box-shadow: 0 0 0 3px rgba(66, 196, 147, 0.14); }
.sidebar-footer button { width: 100%; margin-top: 12px; color: #bcc5c2; border-color: #3a4240; background: transparent; }
.sidebar-footer button:hover { color: #fff; border-color: #66716e; }

.workspace { min-width: 0; }
.workspace-header {
  min-height: 72px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.workspace-header h1 { margin: 0; font-size: 20px; font-weight: 700; }
.workspace-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.updated-at { color: var(--subtle); font-size: 12px; }
.console-main { width: min(1280px, calc(100% - 48px)); margin: 24px auto 48px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  overflow: hidden;
}
.metric { min-height: 88px; padding: 15px 18px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 7px; font-size: 26px; line-height: 1; font-weight: 720; font-variant-numeric: tabular-nums; }
.metric em { display: block; margin-top: 7px; color: var(--subtle); font-size: 11px; font-style: normal; }

.panel { display: none; }
.panel.active { display: block; }
.section-head { min-height: 46px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.section-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.form-band {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(190px, 0.8fr) 120px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}
.rule-form.form-band { grid-template-columns: minmax(170px, 0.8fr) 140px minmax(260px, 1.5fr) auto; }
.field { min-width: 0; }
.field label { display: block; margin-bottom: 6px; color: #46514f; font-size: 12px; font-weight: 650; }
input, select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
input::placeholder { color: #9aa3a1; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(8, 122, 91, 0.1); }
button {
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}
button:hover { border-color: #9da8a5; background: #fafbfb; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary { color: #fff; border-color: var(--primary); background: var(--primary); font-weight: 650; }
button.primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
button.danger { color: var(--danger); border-color: #efc7c3; background: var(--danger-soft); }
button.danger:hover { border-color: #df9c95; background: #ffe5e1; }
button.quiet { background: transparent; }

.key-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 14px;
  padding: 13px 16px;
  border: 1px solid #e4c48c;
  border-radius: 6px;
  background: var(--amber-soft);
}
.key-result div { min-width: 0; }
.key-result span { display: block; color: var(--amber); font-size: 11px; font-weight: 700; }
.key-result code { display: block; margin-top: 4px; overflow: hidden; color: #55320a; font-family: Consolas, monospace; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }

.data-table { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); overflow: hidden; }
.table-head, .list-row {
  display: grid;
  grid-template-columns: minmax(190px, 1.05fr) minmax(280px, 1.8fr) 130px;
  gap: 18px;
  align-items: center;
}
.table-head { min-height: 38px; padding: 0 16px; color: var(--muted); background: #f8f9f9; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; }
.list-row { min-height: 72px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: #fbfcfc; }
.list-row strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.list-row small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.last-message { min-width: 0; color: #45504e; line-height: 1.55; overflow-wrap: anywhere; }
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.state-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.state-pill.active { color: #076047; background: var(--primary-soft); }
.state-pill.inactive { color: #8b251d; background: var(--danger-soft); }
.empty-state { padding: 46px 20px; color: var(--muted); text-align: center; }

#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(380px, calc(100% - 40px));
  padding: 12px 16px;
  border-radius: 6px;
  color: #fff;
  background: #202624;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(8px);
  transition: 160ms ease;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .console-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar-brand { min-height: 60px; }
  .tabs { display: flex; padding: 8px 12px; overflow-x: auto; border-top: 1px solid #2b302f; }
  .tab { width: auto; min-width: 104px; text-align: center; white-space: nowrap; }
  .tab.active { box-shadow: inset 0 -3px 0 var(--primary); }
  .sidebar-footer { display: none; }
  .workspace-header { min-height: 64px; padding: 0 18px; }
  .console-main { width: min(100% - 28px, 1280px); margin-top: 16px; }
}

@media (max-width: 700px) {
  .auth-header { padding: 0 18px; }
  .auth-card { padding: 24px 20px; }
  .workspace-header { align-items: flex-start; padding: 13px 14px; }
  .header-actions { align-items: flex-end; flex-direction: column; gap: 4px; }
  .updated-at { max-width: 140px; text-align: right; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .form-band, .rule-form.form-band { grid-template-columns: 1fr; align-items: stretch; }
  .form-band button { width: 100%; }
  .key-result { align-items: stretch; flex-direction: column; }
  .table-head { display: none; }
  .list-row { grid-template-columns: 1fr; gap: 8px; }
  .row-actions { justify-content: flex-start; }
}
