:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #dce3e8;
  --text: #172026;
  --muted: #667783;
  --blue: #2868c7;
  --blue-dark: #1f54a0;
  --green: #26745a;
  --red: #b44747;
  --amber: #9a651d;
  --radius: 8px;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

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

.login-panel {
  width: min(400px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.login-panel h1 {
  font-size: 24px;
}

.login-message {
  color: var(--red);
  font-size: 13px;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

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

.brand {
  padding: 0 8px 12px;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand p,
.muted,
.eyebrow,
.header-meta {
  color: var(--muted);
  font-size: 13px;
}

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

.nav-item,
button,
.link-button {
  min-height: 38px;
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.nav-item {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #eaf1fb;
  color: var(--blue);
  border-color: #cfe0f6;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

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

.main-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.main-header h2 {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 800;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 12px;
}

.section-head h3 {
  font-size: 18px;
  font-weight: 800;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 26px;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card,
.panel,
.tool-panel,
.data-table {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat-card {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  font-size: 28px;
  line-height: 1;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 14px;
}

.diagnostics-subsection {
  margin-top: 14px;
}

.panel {
  padding: 14px;
}

.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-list,
.summary-strip {
  display: grid;
  gap: 10px;
}

.status-item,
.summary-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.status-item span,
.summary-card span {
  color: var(--muted);
  font-size: 13px;
}

.summary-strip {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.tool-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.tool-panel h4 {
  font-size: 15px;
  font-weight: 800;
}

.user-picker {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.user-picker-results {
  display: grid;
  max-height: 230px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.user-picker-option {
  display: grid;
  width: 100%;
  min-height: 0;
  gap: 3px;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.user-picker-option:last-child {
  border-bottom: 0;
}

.user-picker-option:hover:not(:disabled),
.user-picker-option:focus-visible:not(:disabled) {
  background: #eaf1fb;
  color: var(--blue);
}

.user-picker-option small,
.user-picker-selection,
.field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.inline-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.inline-status[data-state="pending"] {
  color: #7a5200;
}

.inline-status[data-state="success"] {
  color: #17623a;
}

.inline-status[data-state="error"] {
  color: #a22b2b;
}

.user-picker-option:disabled {
  color: var(--muted);
  opacity: 1;
}

.user-picker-empty {
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
}

.invite-result {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.invite-result p {
  color: var(--muted);
  font-size: 13px;
}

.invite-code-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.invite-code-row code {
  min-width: 0;
  flex: 1 1 180px;
  overflow-wrap: anywhere;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  user-select: all;
}

.wide-panel {
  max-width: 920px;
  margin-bottom: 14px;
}

.optimization-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.optimization-editor {
  min-width: 0;
}

.compact-control {
  width: auto;
  min-width: 110px;
}

.tuning-value-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  align-items: end;
  gap: 10px;
}

.number-control {
  width: 88px;
}

.local-editor,
.preview-tools,
.profile-tools {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.tuning-inline-fields,
.profile-tools {
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  align-items: end;
}

.profile-tools {
  grid-template-columns: minmax(180px, 1fr) auto minmax(200px, 1fr) auto auto auto;
}

.override-list {
  display: grid;
  gap: 6px;
}

.override-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

input[type="file"] {
  padding: 7px 8px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(40, 104, 199, 0.18);
  border-color: var(--blue);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-width: 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid transparent;
  text-decoration: none;
}

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

.primary {
  background: var(--blue);
  color: #ffffff;
}

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

.secondary {
  background: #e7f1f0;
  color: #174f43;
  border-color: #bed8d2;
}

.ghost {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

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

.table-row {
  display: grid;
  grid-template-columns: var(--cols);
  align-items: center;
  gap: 12px;
  min-width: var(--min-width, 760px);
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.table-row:last-child {
  border-bottom: 0;
}

.table-head {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

.actions a,
.row-actions a,
.text-action {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.text-action {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
}

.text-action:hover,
.row-actions a:hover,
.actions a:hover {
  text-decoration: underline;
}

.badge,
.badge-group {
  display: inline-flex;
  align-items: center;
}

.badge {
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.badge-group {
  gap: 6px;
  flex-wrap: wrap;
}

.badge.ok {
  color: var(--green);
  background: #e9f4ef;
  border-color: #c8e0d6;
}

.badge.busy {
  color: var(--amber);
  background: #fff4df;
  border-color: #ecd2a3;
}

.badge.bad {
  color: var(--red);
  background: #fff0f0;
  border-color: #e6c4c4;
}

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

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--blue);
  transition: width 160ms ease;
}

.compact-list {
  display: grid;
  gap: 8px;
}

.compact-item {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.compact-item:last-child {
  border-bottom: 0;
}

.message {
  padding: 10px 12px;
  margin: 0 0 14px;
  border: 1px solid #c8d9e8;
  border-radius: var(--radius);
  background: #eef6ff;
  color: #234966;
  font-size: 13px;
}

audio {
  width: 100%;
  min-height: 40px;
}

.empty {
  padding: 16px;
  color: var(--muted);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}

.audit-filters {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 14px;
}

.audit-filter-actions {
  align-self: end;
  min-height: 38px;
}

.audit-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}

.audit-metadata {
  max-width: 420px;
  margin: 6px 0 0;
  padding: 8px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

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

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

  .nav-menu {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    width: auto;
    white-space: nowrap;
  }

  .sidebar-actions {
    display: flex;
    margin-top: 0;
  }

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

  .optimization-layout {
    grid-template-columns: 1fr;
  }

  .profile-tools {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 860px) {
  .main-panel {
    padding: 16px;
  }

  .main-header,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid,
  .summary-strip,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .tuning-inline-fields,
  .profile-tools,
  .tuning-value-row {
    grid-template-columns: 1fr;
  }
}

.membership-cell {
  display: grid;
  gap: 4px;
  align-content: center;
}
