:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --ink: #17201a;
  --muted: #617067;
  --line: #dce3e1;
  --primary: #176b55;
  --primary-strong: #0f513f;
  --primary-soft: #e4f3ed;
  --accent: #a45f14;
  --danger: #b42318;
  --danger-soft: #fff1ef;
  --warn: #946200;
  --warn-soft: #fff7df;
  --ok: #16724d;
  --ok-soft: #e7f6ee;
  --shadow: 0 18px 48px rgba(23, 32, 26, 0.08);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    linear-gradient(135deg, rgba(23, 107, 85, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(164, 95, 20, 0.08), transparent 30%),
    var(--bg);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.login-panel {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.brand-line h1,
.page-title h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand-line p,
.page-title p,
.muted {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.input,
.select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 9px 12px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.textarea {
  resize: vertical;
  min-height: 112px;
  line-height: 1.5;
}

.input:focus,
.select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 85, 0.14);
}

.btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 150ms ease, border-color 150ms ease, transform 100ms ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible,
.nav button:focus-visible {
  outline: 3px solid rgba(23, 107, 85, 0.2);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-strong);
}

.btn.secondary {
  background: #fff;
  color: var(--primary);
  border-color: #bcd7cc;
}

.btn.secondary:hover {
  background: var(--primary-soft);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #ffc9c1;
}

.btn.full {
  width: 100%;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(14px);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 24px;
}

.nav button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
}

.nav button:hover,
.nav button.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.main {
  min-width: 0;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
}

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

.admin-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(23, 32, 26, 0.05);
}

.command-panel {
  background: rgba(255, 255, 255, 0.86);
}

.pad {
  padding: 16px;
}

.metric span,
.panel-title span,
.section-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

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

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title h2 {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.3;
}

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

.section-head.compact {
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.3;
}

.section-head p {
  max-width: 720px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.ops-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.mini-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 160px 140px auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.compact-toolbar {
  grid-template-columns: minmax(180px, 1fr) 150px 128px auto;
  margin-bottom: 0;
}

.guard-toolbar {
  grid-template-columns: minmax(160px, 1fr) 120px minmax(112px, auto);
}

.create-panel {
  margin-bottom: 0;
}

.create-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.create-grid .field {
  margin-bottom: 0;
}

.create-grid .wide {
  grid-column: span 3;
}

.create-grid .full {
  grid-column: 1 / -1;
}

.create-grid textarea[name="models"],
.create-grid textarea[name="keys"] {
  min-height: 160px;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 18, 0.46);
  backdrop-filter: blur(6px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(980px, calc(100vw - 32px));
  max-height: min(86vh, 780px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid rgba(220, 227, 225, 0.9);
  border-radius: var(--radius);
  box-shadow: 0 28px 80px rgba(23, 32, 26, 0.24);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
}

.modal-head span,
.model-summary > div:first-child > span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.modal-head h2 {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.3;
}

.modal-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.modal-form {
  padding: 16px;
}

.model-summary {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.model-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
  line-height: 1.35;
}

.model-pills {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 560px;
}

.model-pills span {
  max-width: 180px;
  min-height: 28px;
  padding: 5px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 999px;
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 700;
}

.advanced-block {
  grid-column: 1 / -1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.advanced-block summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.advanced-block summary::marker {
  color: var(--primary);
}

.advanced-block small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.advanced-block textarea[name="models"] {
  min-height: 132px;
  border-width: 1px 0 0;
  border-radius: 0;
}

.check-row {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.create-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 980px;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}

.table td {
  padding: 12px;
  border-bottom: 1px solid #edf0e8;
  vertical-align: middle;
}

.table tr:hover td {
  background: var(--surface-2);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--mono);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.off {
  background: #eef0ea;
  color: #5a645b;
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.progress {
  width: 150px;
  height: 8px;
  border-radius: 999px;
  background: #e9ede5;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: var(--primary);
}

.progress.warn span {
  background: var(--accent);
}

.progress.danger span {
  background: var(--danger);
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-actions .input {
  width: 92px;
  min-height: 36px;
  padding: 7px 9px;
}

.inline-actions .btn {
  min-height: 36px;
  padding: 7px 10px;
}

.empty,
.notice {
  padding: 16px;
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line);
}

.notice.error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #ffc9c1;
}

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

.toast.error {
  background: var(--danger);
}

.loading {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--muted);
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .metrics,
  .cols-2 {
    grid-template-columns: 1fr;
  }

  .section-head {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .ops-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .compact-toolbar,
  .guard-toolbar {
    grid-template-columns: 1fr;
  }

  .create-grid {
    grid-template-columns: 1fr;
  }

  .create-grid .wide {
    grid-column: span 1;
  }

  .create-grid .full,
  .model-summary,
  .advanced-block {
    grid-column: span 1;
  }

  .modal-layer {
    align-items: end;
    padding: 12px;
  }

  .modal-panel {
    width: 100%;
    max-height: calc(100dvh - 24px);
  }

  .modal-head,
  .model-summary {
    flex-direction: column;
  }

  .model-pills {
    justify-content: flex-start;
    max-width: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .main,
  .sidebar {
    padding: 16px;
  }

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

  .login-panel {
    padding: 20px;
  }
}
