:root {
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #202124;
  background: #f4f6f8;
  font-size: 14px;
  --border: #dfe3e7;
  --muted: #687078;
  --blue: #1967d2;
  --blue-soft: #e8f0fe;
  --green: #137333;
  --red: #b3261e;
  --sidebar: #20242a;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 980px; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { border: 1px solid #c9ced4; border-radius: 5px; min-height: 34px; padding: 0 13px; background: #fff; color: #292d32; cursor: pointer; }
button:hover { background: #f0f2f4; }
button.primary { border-color: var(--blue); background: var(--blue); color: #fff; }
button.primary:hover { background: #1558b0; }
button.danger { border-color: #e5bbb7; color: var(--red); }
input, select, textarea { border: 1px solid #c9ced4; border-radius: 5px; background: #fff; color: #202124; }
input, select { min-height: 36px; padding: 0 10px; }
textarea { padding: 10px; resize: vertical; font: 12px/1.55 Consolas, "SFMono-Regular", monospace; }
input:focus, select:focus, textarea:focus { outline: 2px solid #aecbfa; border-color: var(--blue); }

.app-shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: grid; grid-template-rows: auto 1fr auto; background: var(--sidebar); color: #fff; }
.brand { display: flex; align-items: center; gap: 11px; padding: 22px 18px; border-bottom: 1px solid #363b42; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; background: #8ab4f8; color: #172033; font-weight: 800; }
.brand div { display: grid; gap: 2px; min-width: 0; }
.brand strong { font-size: 13px; white-space: nowrap; }
.brand small { color: #9aa0a6; font-size: 10px; text-transform: uppercase; }
nav { padding: 14px 10px; }
.nav-item { width: 100%; justify-content: flex-start; margin-bottom: 4px; border: 0; background: transparent; color: #bdc1c6; text-align: left; }
.nav-item:hover { background: #2d3239; color: #fff; }
.nav-item.active { background: #384454; color: #fff; box-shadow: inset 3px 0 #8ab4f8; }
.server-state { display: flex; align-items: center; gap: 8px; padding: 16px 18px; border-top: 1px solid #363b42; color: #bdc1c6; font-size: 12px; }
#health-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa0a6; }
#health-dot.online { background: #66bb6a; }
#health-dot.offline { background: #ef5350; }

.workspace { min-width: 0; }
.topbar { height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 28px; border-bottom: 1px solid var(--border); background: #fff; }
.topbar h1 { margin: 0 0 5px; font-size: 20px; letter-spacing: 0; }
.topbar p { margin: 0; color: var(--muted); font-size: 12px; }
.metrics { display: flex; gap: 10px; }
.metrics span { min-width: 108px; padding: 8px 12px; border-left: 3px solid #9aa0a6; background: #f6f7f8; color: var(--muted); font-size: 11px; }
.metrics b { display: block; color: #202124; font-size: 16px; }
.view { display: none; }
.view.active { display: block; }
.toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) 180px auto; gap: 10px; padding: 18px 28px; border-bottom: 1px solid var(--border); background: #fafbfc; }
.toolbar.compact { grid-template-columns: minmax(180px, 1fr) auto; padding: 14px 16px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; table-layout: fixed; }
th { height: 42px; padding: 0 14px; border-bottom: 1px solid var(--border); background: #f8f9fa; color: #5f6368; font-size: 11px; font-weight: 600; text-align: left; }
td { height: 58px; padding: 8px 14px; border-bottom: 1px solid #eceff1; vertical-align: middle; }
th:nth-child(1) { width: 190px; }
th:nth-child(2) { width: 45%; }
th:nth-child(3) { width: 110px; }
th:nth-child(4) { width: 80px; }
th:nth-child(5) { width: 150px; }
th:nth-child(6) { width: 88px; }
.method { display: inline-block; min-width: 42px; margin-right: 8px; color: var(--green); font: 700 11px Consolas, monospace; }
.path { overflow: hidden; color: #2f3439; font: 12px Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; padding: 3px 7px; border-radius: 10px; background: #eef0f2; color: #5f6368; font-size: 10px; }
.badge.live { background: #e6f4ea; color: var(--green); }
.muted { color: var(--muted); font-size: 12px; }
.empty { padding: 44px 20px; color: var(--muted); text-align: center; }

.visual-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 28px; border-bottom: 1px solid var(--border); background: #fafbfc; }
.visual-toolbar strong { font-size: 14px; }
.source-note { margin-left: 12px; color: var(--muted); font-size: 11px; }
.visual-toolbar-actions { display: flex; gap: 8px; }
.preview-banner { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 24px 30px; border-bottom: 1px solid #d6e2f2; background: #edf4fd; }
.preview-banner h2 { margin: 6px 0 4px; font-size: 24px; font-weight: 650; }
.preview-banner p { margin: 0; color: #596776; font-size: 12px; }
.eyebrow { color: #6d7d8d; font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.preview-filters { display: flex; align-items: end; gap: 12px; }
.preview-filters label { display: grid; gap: 5px; color: #56616d; font-size: 11px; font-weight: 600; }
.preview-filters input { width: 190px; background: #fff; }
.status-pill { padding: 9px 11px; border: 1px solid #b8d0ef; border-radius: 4px; background: #fff; color: #1967d2; font-size: 11px; white-space: nowrap; }
.visual-content { padding: 22px 30px 48px; background: #f4f6f8; }
.panel { border: 1px solid var(--border); background: #fff; }
.account-strip { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.avatar-preview { display: grid; flex: 0 0 48px; place-items: center; width: 48px; height: 48px; overflow: hidden; border: 1px solid #c8d9ef; border-radius: 50%; background: #d7e6fa; color: #1967d2; font-weight: 700; }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.account-copy { display: grid; gap: 4px; min-width: 220px; }
.account-copy input { border: 0; padding: 0; background: transparent; }
.account-name { font-size: 16px; font-weight: 650; }
.account-title { color: var(--muted); font-size: 11px; }
.avatar-url-field { display: grid; flex: 1 1 320px; gap: 5px; min-width: 180px; color: var(--muted); font-size: 10px; }
.avatar-url-field input { width: 100%; min-height: 34px; font-size: 11px; }
.account-meta { display: grid; gap: 5px; margin-left: auto; padding-left: 22px; border-left: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.account-meta + .account-meta { margin-left: 0; }
.account-meta strong { color: #3d444c; font-size: 12px; }
.green-text { color: var(--green) !important; }
.visual-section { margin-top: 20px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px 12px; }
.section-heading h3 { margin: 4px 0 0; font-size: 15px; }
.section-binding { color: #83909c; font: 10px Consolas, monospace; }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; padding: 0 18px 18px; }
.metric-card { display: grid; gap: 8px; min-width: 0; padding: 15px 13px 13px; border: 1px solid #e0e4e8; border-radius: 5px; background: #fff; }
.metric-card > span { color: var(--muted); font-size: 11px; }
.metric-card strong { display: flex; align-items: baseline; gap: 4px; color: #1f2933; font-size: 21px; }
.metric-card input { width: 100%; min-width: 0; padding: 0; border: 0; border-bottom: 1px dashed #aeb8c2; border-radius: 0; background: transparent; font-size: inherit; font-weight: 650; }
.metric-card input:focus { outline: 0; border-bottom-color: var(--blue); }
.metric-card small { color: var(--muted); font-size: 11px; font-weight: 400; }
.metric-card em { color: #8a949d; font-size: 10px; font-style: normal; }
.metric-card.accent { border-color: #b9d1f2; background: #f7faff; }
.trend-panel { padding-bottom: 18px; }
.trend-chart { display: flex; align-items: end; gap: 10px; height: 156px; margin: 0 18px; padding: 12px 10px 0; border-bottom: 1px solid #dfe3e7; background: repeating-linear-gradient(to bottom, transparent 0, transparent 38px, #edf0f3 39px); }
.trend-bar-wrap { display: flex; flex: 1; align-items: center; align-self: stretch; flex-direction: column; justify-content: end; min-width: 28px; gap: 4px; }
.trend-value { color: #75818d; font-size: 9px; white-space: nowrap; }
.trend-bar { width: min(30px, 70%); min-height: 8px; border-radius: 3px 3px 0 0; background: #6fa2e7; }
.trend-bar-wrap span { color: #7b8791; font-size: 10px; }
.trend-inputs { display: grid; grid-template-columns: repeat(6, minmax(70px, 1fr)); gap: 8px; margin: 14px 18px 0; }
.trend-inputs label, .anomaly-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; }
.trend-inputs input { min-height: 31px; padding: 0 7px; font-size: 11px; }
.visual-two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.anomaly-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 18px; }
.anomaly-grid label { position: relative; }
.anomaly-grid input { width: 100%; padding-right: 24px; }
.anomaly-grid small { position: absolute; right: 8px; bottom: 10px; color: #7c8791; }
.helper-text { margin: 13px 18px 17px; color: #8a949d; font-size: 11px; }
.status-list { display: grid; gap: 0; margin: 0 18px; border-top: 1px solid #edf0f2; }
.status-list div { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #edf0f2; color: var(--muted); font-size: 11px; }
.status-list strong { color: #39434c; font-size: 12px; }
.table-scroll { overflow-x: auto; }
.visual-table { table-layout: auto; }
.visual-table th, .visual-table td { height: 46px; padding: 7px 14px; }
.visual-table input { width: 100%; min-width: 70px; min-height: 30px; border-color: transparent; background: transparent; font-size: 12px; }
.visual-table input:hover, .visual-table input:focus { border-color: #c9ced4; background: #fff; }
.visual-table td > span { color: var(--muted); font-size: 11px; }
.visual-table .rank { width: 50px; color: var(--blue); font-weight: 700; }
.product-table th:nth-child(1) { width: 50px; }
.product-table th:nth-child(2) { min-width: 190px; }
.product-table th:nth-child(n+3) { min-width: 130px; }

.split-layout { display: grid; grid-template-columns: minmax(340px, 40%) minmax(520px, 60%); min-height: calc(100vh - 82px); }
.rule-list-pane { border-right: 1px solid var(--border); background: #f8f9fa; }
.rule-list { background: #fff; }
.rule-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 14px 16px; border-bottom: 1px solid #e6e9ec; cursor: pointer; }
.rule-row:hover, .rule-row.selected { background: #edf3fc; }
.rule-row strong { display: block; margin-bottom: 5px; font-size: 13px; }
.rule-row code { color: #5f6368; font-size: 11px; }
.rule-row input { min-height: auto; accent-color: var(--blue); }
.editor-pane { padding: 22px 26px 30px; background: #fff; }
.editor-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.editor-heading span { color: var(--blue); font-size: 10px; font-weight: 700; }
.editor-heading h2 { margin: 5px 0 0; font-size: 18px; }
.toggle-label { display: flex; align-items: center; gap: 8px; color: #4b5156; }
.toggle-label input, .inline-check input { accent-color: var(--blue); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.form-grid label, .settings-band > label { display: grid; gap: 6px; color: #4b5156; font-size: 12px; font-weight: 600; }
.form-grid .wide { grid-column: 1 / -1; }
.editor-actions { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-top: 18px; }
#editor-message { color: var(--muted); font-size: 12px; }

.settings-view { padding-bottom: 40px; }
.settings-band { padding: 24px 30px; border-bottom: 1px solid var(--border); background: #fff; }
.settings-band h2 { margin: 0 0 18px; font-size: 16px; }
.settings-band > label { max-width: 620px; margin: 13px 0; }
.inline-check { display: flex !important; grid-template-columns: auto 1fr; align-items: center; }
.setting-actions { display: flex; gap: 10px; margin-top: 16px; }

dialog { width: min(1100px, calc(100vw - 60px)); max-height: calc(100vh - 60px); padding: 0; border: 1px solid #c9ced4; border-radius: 7px; box-shadow: 0 16px 48px #20212433; }
dialog::backdrop { background: #20212466; }
dialog header { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
dialog header span { color: var(--green); font: 700 11px Consolas, monospace; }
dialog h2 { max-width: 930px; margin: 5px 0 0; overflow-wrap: anywhere; font: 14px Consolas, monospace; }
#close-dialog { width: 34px; min-height: 34px; padding: 0; border: 0; font-size: 24px; }
.detail-meta { display: flex; gap: 18px; padding: 10px 22px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.detail-grid { display: grid; grid-template-columns: 40% 60%; min-height: 430px; }
.detail-grid section { min-width: 0; padding: 18px 20px; }
.detail-grid section + section { border-left: 1px solid var(--border); }
.detail-grid h3 { margin: 0 0 10px; font-size: 12px; }
pre, #detail-response { width: 100%; height: 380px; margin: 0; overflow: auto; border: 1px solid #e2e5e8; border-radius: 4px; padding: 12px; background: #f7f8fa; white-space: pre-wrap; overflow-wrap: anywhere; font: 11px/1.55 Consolas, monospace; }
dialog footer { display: flex; align-items: center; justify-content: flex-end; gap: 14px; padding: 13px 20px; border-top: 1px solid var(--border); }
#detail-message { margin-right: auto; color: var(--muted); font-size: 12px; }
#toast { position: fixed; right: 22px; bottom: 22px; max-width: 420px; padding: 11px 14px; border-radius: 5px; background: #202124; color: #fff; opacity: 0; transform: translateY(8px); transition: .18s ease; pointer-events: none; }
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 190px minmax(0, 1fr); }
  .split-layout { grid-template-columns: 360px minmax(520px, 1fr); }
  .metrics { display: none; }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 800px) {
  body { min-width: 0; }
  .app-shell { display: block; }
  .sidebar { position: sticky; z-index: 10; top: 0; height: auto; grid-template-columns: auto 1fr auto; grid-template-rows: auto; align-items: stretch; }
  .brand { min-width: 180px; padding: 10px 12px; border-right: 1px solid #363b42; border-bottom: 0; }
  .brand small { display: none; }
  nav { display: flex; align-items: stretch; padding: 6px; overflow-x: auto; }
  .nav-item { width: auto; min-width: 84px; margin: 0 2px; padding: 0 8px; text-align: center; }
  .nav-item.active { box-shadow: inset 0 -3px #8ab4f8; }
  .server-state { padding: 10px 12px; border-top: 0; border-left: 1px solid #363b42; }
  #health-text { display: none; }
  .topbar { height: auto; min-height: 72px; padding: 14px 18px; }
  .visual-toolbar { align-items: flex-start; flex-direction: column; padding: 13px 18px; }
  .visual-toolbar-actions { width: 100%; }
  .visual-toolbar-actions button { flex: 1; }
  .preview-banner { align-items: stretch; flex-direction: column; padding: 20px 18px; }
  .preview-filters { align-items: stretch; flex-direction: column; }
  .preview-filters input { width: 100%; }
  .visual-content { padding: 16px 18px 36px; }
  .account-strip { align-items: flex-start; flex-wrap: wrap; }
  .account-copy { min-width: 0; flex: 1; }
  .account-meta { margin-left: 56px; padding-left: 0; border-left: 0; }
  .account-meta + .account-meta { margin-left: 0; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding-right: 12px; padding-left: 12px; }
  .section-heading { padding-right: 14px; padding-left: 14px; }
  .trend-inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-right: 14px; margin-left: 14px; }
  .visual-two-col { grid-template-columns: 1fr; gap: 0; }
  .visual-section { margin-top: 16px; }
  .anomaly-grid { padding-right: 14px; padding-left: 14px; }
  .helper-text { margin-right: 14px; margin-left: 14px; }
  .toolbar { grid-template-columns: 1fr; padding: 14px 16px; }
  .table-wrap { overflow-x: hidden; }
  table { min-width: 0; }
  th, td { padding-right: 8px; padding-left: 8px; }
  th:nth-child(1) { width: 132px; }
  th:nth-child(2) { width: auto; }
  th:nth-child(3), th:nth-child(4), th:nth-child(5), td:nth-child(3), td:nth-child(4), td:nth-child(5) { display: none; }
  th:nth-child(6) { width: 68px; }
  td:nth-child(6) button { min-width: 48px; padding: 0 6px; white-space: nowrap; }
  .method { display: block; margin: 0 0 4px; }
  .path { display: block; width: 100%; }
  .split-layout { display: block; min-height: 0; }
  .rule-list-pane { max-height: 340px; overflow: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .editor-pane { padding: 20px 18px 28px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid section + section { border-top: 1px solid var(--border); border-left: 0; }
  dialog { width: calc(100vw - 20px); max-height: calc(100vh - 20px); }
}

@media (max-width: 520px) {
  .sidebar { grid-template-columns: 1fr auto; }
  .brand { display: none; }
  nav { padding: 4px 2px; }
  .nav-item { min-width: 76px; margin: 0 1px; padding: 0 4px; font-size: 11px; }
  .server-state { padding: 10px 9px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: 1; }
  .editor-actions { grid-template-columns: auto 1fr; }
  .editor-actions .primary { grid-column: 1 / -1; }
  .settings-band { padding: 20px 18px; }
  .source-note { display: block; margin: 6px 0 0; }
  .metric-grid { gap: 8px; padding-right: 10px; padding-left: 10px; }
  .metric-card { padding: 12px 10px; }
  .metric-card strong { font-size: 17px; }
  .trend-inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-binding { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .account-strip { align-items: flex-start; flex-wrap: wrap; }
  .avatar-url-field { flex-basis: calc(100% - 66px); }
  .account-meta { margin-left: 0; }
}
