:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #d9e1ee;
  --text: #142033;
  --sub: #5c6b83;
  --primary: #1257e5;
  --danger: #c92a2a;
  --soft: #eef3ff;
  --input-bg: #ffffff;
  --menu-hover-bg: #eef3ff;
  --menu-hover-text: #1743a5;
  --table-header-bg: #f5f8ff;
  --stat-gradient: linear-gradient(180deg, #ffffff, #f6f9ff);
  --stat-text: #14377d;
  --guard-bg: #fff5f5;
  --guard-border: #ffd5d5;
  --editor-bg: #f8fbff;
  --editor-border: #b8c7e6;
}

/* 暗黑模式 */
[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --line: #334155;
  --text: #f1f5f9;
  --sub: #94a3b8;
  --primary: #3b82f6;
  --danger: #ef4444;
  --soft: #1e3a5f;
  --input-bg: #0f172a;
  --menu-hover-bg: #1e3a5f;
  --menu-hover-text: #93c5fd;
  --table-header-bg: #1e293b;
  --stat-gradient: linear-gradient(180deg, #1e293b, #0f172a);
  --stat-text: #93c5fd;
  --guard-bg: #2d1f1f;
  --guard-border: #7f1d1d;
  --editor-bg: #1e293b;
  --editor-border: #475569;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}

.login-card h1 { margin-top: 0; font-size: 22px; }

label {
  display: block;
  margin: 10px 0 6px;
  color: var(--sub);
  font-size: 13px;
}

input, textarea, select, button {
  width: 100%;
  border-radius: 8px;
  font-size: 14px;
}

input, textarea, select {
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: var(--input-bg);
  color: var(--text);
}

input.field-error, textarea.field-error, select.field-error {
  border-color: var(--danger);
  background: var(--guard-bg);
}

button {
  margin-top: 10px;
  border: 0;
  padding: 8px 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.danger { background: var(--danger); }
button.secondary { background: #7b8798; }
button.small { width: auto; margin-top: 0; padding: 5px 9px; font-size: 12px; }

.msg { min-height: 20px; color: var(--danger); }
.hint { color: var(--sub); font-size: 12px; }
.inline-note { color: var(--sub); font-size: 12px; display: inline-flex; align-items: center; }
.muted { color: var(--sub); font-size: 13px; }

.app-wrap { min-height: 100vh; }

.app-header {
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.app-header .sub { margin-left: 8px; color: var(--sub); font-size: 13px; }
.app-header button { width: auto; margin-top: 0; margin-left: 8px; }

.guard {
  margin: 12px;
  padding: 12px;
  border: 1px solid var(--guard-border);
  border-radius: 10px;
  background: var(--guard-bg);
}
.guard h2 { margin-top: 0; font-size: 18px; }
.guard .hint {
  margin: 8px 0 12px;
  color: var(--sub);
  font-size: 13px;
}

.app-main {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 56px);
}

.side {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
}

.menu {
  width: 100%;
  text-align: left;
  margin-top: 0;
  margin-bottom: 8px;
  background: var(--menu-hover-bg);
  color: var(--menu-hover-text);
}
.menu.active {
  background: var(--primary);
  color: #fff;
}

.content { padding: 12px; }

.tab {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.tab.active { display: block; }

.row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.row button { margin-top: 0; }
h2, h3 { margin-top: 0; }

.editor {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px dashed var(--editor-border);
  border-radius: 10px;
  background: var(--editor-bg);
}


table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}
th, td {
  border: 1px solid var(--line);
  padding: 8px;
  font-size: 13px;
  text-align: left;
}
th { background: var(--table-header-bg); }
td .small { margin-right: 6px; }

.cell-sub {
  margin-top: 4px;
  color: var(--sub);
  font-size: 12px;
}

pre {
  margin-top: 12px;
  background: #0f172a;
  color: #dbe7ff;
  border-radius: 8px;
  padding: 10px;
  min-height: 80px;
  overflow: auto;
}

pre.output-error {
  background: #3b0d17;
  color: #ffd9df;
}

pre.output-success {
  background: #0f2a1f;
  color: #d8ffea;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--stat-gradient);
  padding: 12px;
}

.stat-card span {
  display: block;
  color: var(--sub);
  font-size: 12px;
  margin-bottom: 6px;
}

.stat-card strong {
  font-size: 22px;
  color: var(--stat-text);
}

@media (max-width: 1200px) {
  .row, .row-3, .row-4, .row-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .app-main { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .row, .row-3, .row-4, .row-5 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
}

/* 主题切换按钮 */
.theme-toggle {
  width: auto;
  min-width: 36px;
  padding: 5px 9px;
  font-size: 16px;
}
.theme-toggle:hover {
  background: var(--soft);
}
