:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f0f3f7;
  --border: #d9e0e8;
  --border-soft: #edf0f4;
  --text: #17202a;
  --muted: #657384;
  --primary: #1f6feb;
  --primary-dark: #174ea6;
  --danger: #b42318;
  --success: #067647;
  --warning: #b54708;
  --sidebar: #111827;
  --sidebar-muted: #9ca3af;
  --radius: 8px;
  --font: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  overflow: auto;
  background: var(--sidebar);
  color: #fff;
}

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

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

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.drawer-header h3,
.drawer-header p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  margin-top: 3px;
  color: var(--sidebar-muted);
  font-size: 13px;
}

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

.nav-group-title {
  padding: 0 10px;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.nav-group-items {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius);
  color: #d1d5db;
  background: transparent;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  color: #fff;
  background: var(--primary);
}

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

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

.topbar h2 {
  font-size: 28px;
  line-height: 1.2;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

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

input,
textarea,
select {
  width: 100%;
  min-height: 38px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
}

textarea {
  min-height: 140px;
  resize: vertical;
  font-family: Consolas, "Microsoft YaHei", monospace;
}

.toolbar input {
  width: 220px;
}

.button {
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  white-space: nowrap;
}

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

.button-primary:hover {
  background: var(--primary-dark);
}

.button-secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.button-danger {
  color: #fff;
  background: var(--danger);
}

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

.button-small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.notice {
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid #b7dfc9;
  border-radius: var(--radius);
  color: var(--success);
  background: #ecfdf3;
}

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

.hidden {
  display: none !important;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.metric-card {
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
}

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

.metric-value {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 700;
}

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

.workspace {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.section-card {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
}

.section-header,
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.section-title {
  margin: 0;
  font-size: 16px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.toolbar-left,
.toolbar-right,
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.row-check {
  width: 16px;
  min-height: 16px;
  height: 16px;
  padding: 0;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  background: #fbfcfd;
  font-weight: 600;
}

tr:hover td {
  background: #fafbfc;
}

.empty-cell {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 12px;
}

.badge.ok {
  color: var(--success);
  background: #ecfdf3;
}

.badge.warn {
  color: var(--warning);
  background: #fffaeb;
}

.muted {
  color: var(--muted);
}

.summary-text {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
}

.tab {
  min-height: 34px;
  padding: 7px 11px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

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

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

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

.field {
  display: grid;
  gap: 6px;
}

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

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

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr min(520px, 100%);
}

.drawer-backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.drawer-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  height: 100vh;
  background: var(--surface);
  box-shadow: -16px 0 40px rgba(15, 23, 42, 0.16);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--border-soft);
}

.drawer-header h3 {
  font-size: 18px;
}

.drawer-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.drawer-form {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  overflow: auto;
}

pre {
  margin: 0;
  padding: 12px;
  border-radius: var(--radius);
  color: #d1d5db;
  background: #111827;
  overflow: auto;
  font-size: 12px;
}

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

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

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

  .topbar,
  .section-header,
  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .main {
    padding: 18px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .toolbar input,
  .search-input {
    width: 100%;
  }

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

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

  .drawer-backdrop {
    display: none;
  }
}
