:root {
  --canvas: #f6f5f1;
  --paper: #fffefa;
  --panel: rgba(255, 254, 250, 0.82);
  --ink: #252522;
  --muted: #747067;
  --line: rgba(37, 37, 34, 0.12);
  --accent: #62785f;
  --accent-2: #375c68;
  --warning: #9a7437;
  --danger: #a35449;
  --ok: #557b5d;
  --shadow: 0 18px 44px rgba(37, 37, 34, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(37, 37, 34, 0.025) 1px, transparent 1px),
    linear-gradient(rgba(37, 37, 34, 0.018) 1px, transparent 1px),
    var(--canvas);
  background-size: 24px 24px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.login-card {
  width: min(420px, 100%);
  padding: 30px;
}

.login-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.stack,
.form-grid {
  display: grid;
  gap: 12px;
}

.stack {
  margin-top: 22px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(255, 254, 250, 0.86);
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(98, 120, 95, 0.55);
  box-shadow: 0 0 0 3px rgba(98, 120, 95, 0.12);
}

.primary-btn,
.ghost-btn {
  min-height: 40px;
  padding: 0 13px;
  border-radius: var(--radius);
  font-weight: 900;
  white-space: nowrap;
}

.primary-btn {
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
}

.ghost-btn {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 254, 250, 0.68);
}

.primary-btn:hover {
  background: #52684f;
}

.ghost-btn:hover {
  border-color: rgba(37, 37, 34, 0.22);
  background: var(--paper);
}

.message {
  min-height: 20px;
  color: var(--danger);
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: rgba(246, 245, 241, 0.92);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--accent);
  font-weight: 900;
}

.brand strong {
  display: block;
  font-size: 19px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-nav button {
  min-height: 39px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink);
  background: transparent;
  font-weight: 900;
  text-align: left;
  padding: 0 12px;
}

.side-nav button.active,
.side-nav button:hover {
  border-color: var(--line);
  background: rgba(255, 254, 250, 0.82);
}

.sidebar-exit {
  margin-top: auto;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-input {
  width: min(340px, 40vw);
}

.user-pill {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: grid;
  gap: 16px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-head,
.table-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
}

.metric-card,
.todo-item,
.leader-card,
.distributor-card,
.table-row,
.table-header,
.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 254, 250, 0.68);
}

.metric-card {
  padding: 15px;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 25px;
  line-height: 1.2;
}

.metric-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.wide-left {
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.75fr);
}

.trend-chart {
  min-height: 190px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.trend-item {
  min-width: 0;
  display: grid;
  gap: 6px;
  justify-items: center;
}

.trend-bar {
  width: 100%;
  max-width: 44px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.trend-item strong,
.trend-item span,
.trend-item small {
  font-size: 11px;
  color: var(--muted);
}

.todo-list,
.leader-list,
.distributor-grid {
  display: grid;
  gap: 10px;
}

.todo-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 12px;
  text-align: left;
}

.todo-item strong {
  font-size: 20px;
}

.todo-item small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.todo-item.warning {
  border-color: rgba(154, 116, 55, 0.28);
}

.todo-item.danger {
  border-color: rgba(163, 84, 73, 0.32);
}

.leader-card,
.distributor-card {
  padding: 12px;
}

.leader-card {
  display: grid;
  gap: 6px;
}

.leader-card div,
.distributor-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.leader-card span,
.leader-card small,
.distributor-card small {
  color: var(--muted);
}

.leader-card p {
  margin: 0;
  font-weight: 900;
}

.form-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

.form-grid .field-wide {
  grid-column: 1 / -1;
}

.policy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)) auto;
  gap: 12px;
  align-items: stretch;
}

.toggle-row {
  min-height: 76px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 254, 250, 0.68);
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.toggle-row span,
.toggle-row strong,
.toggle-row small {
  min-width: 0;
}

.toggle-row strong {
  display: block;
  font-size: 13px;
}

.toggle-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

.compact-toggle {
  min-height: 40px;
  padding: 8px 10px;
}

.compact-toggle small {
  font-size: 11px;
}

.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-row select {
  width: auto;
  min-width: 150px;
}

.data-table {
  display: grid;
  gap: 8px;
}

.table-header,
.table-row {
  display: grid;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
}

.table-header {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  background: rgba(37, 37, 34, 0.035);
}

.table-row {
  min-height: 58px;
}

.cols-4 {
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 0.7fr) minmax(220px, 1.5fr) minmax(135px, 0.8fr);
}

.cols-5 {
  grid-template-columns: minmax(150px, 1fr) repeat(4, minmax(100px, 0.8fr));
}

.cols-6 {
  grid-template-columns: minmax(190px, 1.25fr) repeat(4, minmax(100px, 0.75fr)) minmax(130px, 0.9fr);
}

.cols-7 {
  grid-template-columns: minmax(160px, 1.05fr) repeat(5, minmax(92px, 0.66fr)) minmax(160px, 0.9fr);
}

.table-row strong,
.table-row span,
.table-row small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-row strong small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 500;
}

.table-row small {
  color: var(--muted);
}

.tag {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(37, 37, 34, 0.07);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.tag.ok {
  background: rgba(85, 123, 93, 0.12);
  color: var(--ok);
}

.tag.warning {
  background: rgba(154, 116, 55, 0.12);
  color: var(--warning);
}

.tag.danger {
  background: rgba(163, 84, 73, 0.12);
  color: var(--danger);
}

.inline-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.inline-actions button {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
}

.inline-actions button.danger-action {
  border-color: rgba(163, 84, 73, 0.42);
  color: var(--danger);
  background: rgba(163, 84, 73, 0.08);
}

.distributor-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.mini-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.mini-metrics span {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 254, 250, 0.62);
  font-size: 12px;
  font-weight: 900;
}

.code-box {
  margin: 14px 0 0;
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #f6f5f1;
  background: #242522;
  white-space: pre-wrap;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-grid,
  .wide-left {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .search-input {
    width: min(100%, 420px);
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-header {
    display: none;
  }

  .table-row,
  .cols-4,
  .cols-5,
  .cols-6,
  .cols-7 {
    grid-template-columns: 1fr;
  }
}
