:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1f2937;
  --ink-2: #4b5563;
  --ink-3: #9ca3af;
  --line: #eceef1;
  --orange: #ea580c;
  --orange-deep: #9a3412;
  --orange-soft: #fff5ec;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(31, 41, 55, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ---------- 登录 ---------- */
.login-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 12% 0%, rgba(247, 146, 64, 0.22), transparent 46%),
    radial-gradient(circle at 88% 100%, rgba(154, 52, 18, 0.16), transparent 42%),
    #fbfaf8;
}

.login-card {
  width: 400px;
  max-width: 100%;
  padding: 40px 36px 28px;
  background: #fff;
  border: 1px solid #f3e7dc;
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(154, 52, 18, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(145deg, #f79240, #ea6a1e 40%, #9a3412);
  box-shadow: 0 8px 18px rgba(154, 52, 18, 0.24);
}

.brand strong {
  display: block;
  font-size: 20px;
  letter-spacing: 1px;
}

.brand small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-3);
}

.brand-lg {
  margin-bottom: 28px;
}

.brand-lg .brand-mark {
  width: 52px;
  height: 52px;
  font-size: 26px;
}

.brand-lg strong {
  font-size: 24px;
}

.login-form label {
  display: block;
  margin-bottom: 16px;
}

.login-form label span {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--ink-2);
}

input,
select {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #e3e6ea;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

input:focus,
select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.1);
}

.form-error {
  min-height: 18px;
  margin: 4px 0 12px;
  font-size: 13px;
  color: var(--bad);
}

.login-tip {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--ink-3);
  text-align: center;
}

/* ---------- 布局 ---------- */
.layout {
  display: flex;
  min-height: 100%;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 26px 18px;
  background: #fff;
  border-right: 1px solid var(--line);
}

.nav {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav a {
  display: block;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: 10px;
  transition: background 0.15s, color 0.15s;
}

.nav a:hover {
  background: #faf7f4;
  color: var(--ink);
}

.nav a.active {
  background: var(--orange-soft);
  color: var(--orange);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px 16px 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-3);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 34px 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.5px;
}

.topbar p {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--ink-3);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  color: var(--ink-2);
}

.view {
  padding: 6px 34px 40px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 18px;
  font-size: 13px;
  font-family: inherit;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}

.btn:hover {
  opacity: 0.9;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(145deg, #f2761f, #ea580c 55%, #c25318);
  box-shadow: 0 8px 18px rgba(194, 83, 24, 0.22);
}

.btn-ghost {
  color: var(--ink-2);
  background: #fff;
  border-color: #e3e6ea;
}

.btn-sm {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-danger {
  color: var(--bad);
  background: #fef2f2;
  border-color: #fecaca;
}

.btn-block {
  width: 100%;
  height: 44px;
  font-size: 14px;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- 卡片与统计 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 22px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 13px;
  color: var(--ink-3);
}

.stat-card .value {
  margin-top: 10px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.stat-card .foot {
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-3);
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.card {
  padding: 22px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
}

.card-sub {
  font-size: 12px;
  color: var(--ink-3);
}

/* 柱状趋势 */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 168px;
  padding-top: 10px;
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 8px;
}

.chart-bar {
  width: 100%;
  max-width: 46px;
  min-height: 4px;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, #f79240, #ea580c 60%, #c25318);
  transition: height 0.3s ease;
}

.chart-count {
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 600;
}

.chart-label {
  font-size: 11px;
  color: var(--ink-3);
}

/* 分布条 */
.dist-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 13px;
}

.dist-name {
  width: 44px;
  color: var(--ink-2);
}

.dist-track {
  flex: 1;
  height: 8px;
  background: #f3f4f6;
  border-radius: 999px;
  overflow: hidden;
}

.dist-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f79240, #ea580c);
}

.dist-fill.gray {
  background: linear-gradient(90deg, #d1d5db, #9ca3af);
}

.dist-count {
  width: 30px;
  text-align: right;
  color: var(--ink-2);
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rank-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  background: #fafafa;
  border-radius: 10px;
}

.rank-item strong {
  color: var(--orange);
}

/* ---------- 表格 ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.toolbar select,
.toolbar input {
  width: 160px;
  height: 36px;
  font-size: 13px;
}

.toolbar .spacer {
  flex: 1;
}

.toolbar .total {
  font-size: 13px;
  color: var(--ink-3);
}

.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

thead th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--ink-3);
  background: #fbfbfc;
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: 13px 16px;
  color: var(--ink-2);
  border-bottom: 1px solid #f4f5f7;
}

tbody tr:hover {
  background: #fdfbf9;
}

tbody tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  font-size: 12px;
  border-radius: 999px;
  background: var(--orange-soft);
  color: var(--orange);
}

.badge.gray {
  background: #f3f4f6;
  color: #6b7280;
}

.badge.green {
  background: #ecfdf5;
  color: var(--good);
}

.badge.red {
  background: #fef2f2;
  color: var(--bad);
}

.badge.amber {
  background: #fffbeb;
  color: var(--warn);
}

.empty {
  padding: 60px 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--ink-3);
}

/* ---------- 规则 ---------- */
.rule-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.rule-item {
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: center;
}

.rule-item .name {
  font-size: 13px;
  color: var(--ink-2);
}

.rule-item .weight {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 700;
  color: var(--orange);
}

.rule-item .unit {
  font-size: 12px;
  color: var(--ink-3);
}

.threshold-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.threshold-item {
  padding: 12px 16px;
  font-size: 13px;
  background: #fafafa;
  border-radius: 10px;
  color: var(--ink-2);
}

.threshold-item strong {
  color: var(--ink);
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translate(-50%, 20px);
  padding: 11px 22px;
  font-size: 13px;
  color: #fff;
  background: rgba(31, 41, 55, 0.92);
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 99;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: rgba(185, 28, 28, 0.95);
}

.loading {
  padding: 80px 0;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .rule-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    overflow-x: auto;
    padding: 14px 18px;
  }
  .nav {
    margin-top: 0;
    flex-direction: row;
  }
  .sidebar-foot {
    display: none;
  }
  .topbar,
  .view {
    padding-left: 18px;
    padding-right: 18px;
  }
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---------- 模型配置 ---------- */
.settings-card {
  max-width: 880px;
}
.settings-form {
  margin-top: 4px;
}
.settings-form label {
  display: block;
}
.settings-form label > span {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--ink-2);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.settings-form .block {
  margin-bottom: 16px;
}
.settings-form textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  resize: vertical;
}
.settings-form textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.1);
}
.switch-row,
.inline-check {
  display: flex !important;
  align-items: center;
  gap: 9px;
}
.switch-row {
  margin-bottom: 20px;
}
.switch-row span {
  margin: 0 !important;
  font-size: 14px !important;
  color: var(--ink) !important;
}
.switch-row input,
.inline-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--orange);
}
.inline-check {
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ink-2);
}
.hint {
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-3);
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}
.test-result {
  margin-top: 16px;
  padding: 14px 16px;
  background: #fff7ef;
  border: 1px solid #f6d9c3;
  border-radius: 10px;
}
.test-result .test-label {
  margin-bottom: 6px;
  font-size: 12px;
  color: #b45309;
}
.test-result p {
  font-size: 14px;
  line-height: 1.7;
  color: #7c2d12;
}
.inline-input {
  width: 100%;
  min-width: 110px;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 13px;
  color: #374151;
  background: #fff;
  box-sizing: border-box;
}
.inline-input:focus {
  outline: none;
  border-color: #ea580c;
}
.inline-input.wide {
  min-width: 220px;
}
.inline-input.narrow {
  min-width: 70px;
  width: 70px;
}
.inline-color {
  width: 42px;
  height: 34px;
  padding: 2px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #4b5563;
  white-space: nowrap;
}
.toolbar input[type='text'] {
  min-width: 220px;
  padding: 9px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 13px;
  box-sizing: border-box;
}
.toolbar input[type='text']:focus {
  outline: none;
  border-color: #ea580c;
}
.table-wrap table td .btn + .btn {
  margin-left: 6px;
}
@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}
