:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #15181e;
  --muted: #69707d;
  --line: #dde3ea;
  --accent: #0f7b6c;
  --accent-dark: #075d52;
  --danger: #b3261e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button, input, textarea, select { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.secondary {
  color: var(--ink);
  background: #eef2f5;
}
button.secondary:hover { background: #dde5ec; }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}
.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #10201d, #edf4f2);
}
.login-card {
  width: min(420px, 100%);
  padding: 32px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.18);
}
.login-mark, .brand-mark {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #20a48f;
  color: #fff;
  font-weight: 800;
}
.login-mark { width: 48px; height: 48px; margin-bottom: 16px; }
.login-card h1 { margin: 0 0 6px; }
.login-card p { margin: 0 0 24px; color: var(--muted); }
.login-card label { display: grid; gap: 8px; margin-bottom: 14px; color: var(--muted); }
.login-card button { width: 100%; margin-top: 8px; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}
.sidebar {
  min-height: 100vh;
  padding: 24px 18px;
  background: #101820;
  color: #eef5f3;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.brand-mark { width: 42px; height: 42px; }
.brand strong, .brand small { display: block; }
.brand small, .account-card small { color: #a7b3bc; margin-top: 4px; }
.nav {
  width: 100%;
  margin-bottom: 8px;
  text-align: left;
  color: #d9e2e8;
  background: transparent;
}
.nav:hover, .nav.active { background: #22303b; }
.account-card {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid #2d3b46;
}
.account-card strong, .account-card small { display: block; }
.account-card button {
  width: 100%;
  margin-top: 14px;
  background: #33424e;
}

.app { min-width: 0; padding: 28px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar h1 { margin: 0 0 6px; font-size: 28px; }
.topbar p, .hint { margin: 0; color: var(--muted); }
.view { display: none; }
.view.active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.metric-grid.compact { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(25, 34, 45, 0.05);
}
.metric { padding: 18px; }
.metric span { display: block; color: var(--muted); margin-bottom: 10px; }
.metric strong { font-size: 30px; }
.content-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 16px;
}
.panel { padding: 18px; min-width: 0; margin-bottom: 16px; }
.panel.wide { grid-column: 1 / -1; }
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; }
.actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.bar-chart {
  display: flex;
  align-items: end;
  gap: 8px;
  height: 180px;
  padding-top: 12px;
  border-bottom: 1px solid var(--line);
}
.bar { flex: 1; min-width: 16px; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 6px; }
.bar i { display: block; width: 100%; min-height: 4px; border-radius: 4px 4px 0 0; background: var(--accent); }
.bar small { color: var(--muted); font-size: 11px; white-space: nowrap; }

.list { display: grid; gap: 10px; }
.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
.status {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  background: #edf4f2;
  color: var(--accent-dark);
}
.status.draft { background: #fff2df; color: #a45c00; }
.status.archived, .status.disabled { background: #f2f3f5; color: #606774; }
.row-actions button { padding: 7px 10px; color: var(--ink); background: #eef2f5; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-list span { padding: 8px 10px; border-radius: 8px; color: #0e4f48; background: #e3f4ef; }

.editor-panel textarea {
  width: 100%;
  min-height: 520px;
  margin-top: 12px;
  line-height: 1.5;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
}
.editor-tabs {
  display: flex;
  gap: 8px;
  margin: 4px 0 16px;
}
.editor-tab {
  color: var(--ink);
  background: #eef2f5;
}
.editor-tab.active {
  color: #fff;
  background: var(--accent);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}
.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  color: var(--ink);
}
.span-2 { grid-column: 1 / -1; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 12px;
}
.section-head h3 { margin: 0; font-size: 16px; }
.builder-list {
  display: grid;
  gap: 12px;
}
.builder-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}
.builder-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.builder-card h4 { margin: 0; }
.option-row, .rule-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 90px minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 8px;
}
.rule-grid {
  grid-template-columns: 90px 90px 1fr 120px auto;
}
.json-field {
  font-family: Consolas, "Courier New", monospace;
}
.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
}
.empty-state strong {
  display: block;
  color: var(--ink);
  margin-bottom: 6px;
}
.admin-form {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}
.role-help {
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  color: #38514d;
  background: #e8f4f1;
}
.table-title {
  max-width: 360px;
  white-space: normal;
  line-height: 1.4;
}
.table-tags {
  max-width: 520px;
  white-space: normal;
  line-height: 1.45;
}
.settings-list { display: grid; gap: 12px; }
.settings-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.settings-row span { color: var(--muted); }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 380px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #1d2630;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  .metric-grid, .metric-grid.compact, .content-grid, .form-grid, .option-row, .rule-grid { grid-template-columns: 1fr; }
  .panel.wide { grid-column: auto; }
}
