:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e8eaf0;
  --text: #1a1d26;
  --muted: #5c6478;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --font: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.5rem 1.25rem;
  font-weight: 600;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.brand-text {
  font-size: 1rem;
}

.nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-group-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 1rem 0.5rem 0.35rem;
}

.nav-item {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}

.nav-item:hover {
  background: var(--accent-soft);
  text-decoration: none;
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
}

.user-mini {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0 0.25rem;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.main {
  padding: 2rem 2.5rem 3rem;
  max-width: 1200px;
  width: 100%;
}

.page-head {
  margin-bottom: 1.5rem;
}

.page-title {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

.page-desc {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card-title {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stack.tight {
  gap: 0.35rem;
}

.stack.narrow {
  max-width: 420px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.65rem;
}

.field.inline.grow {
  flex: 1;
}

.field-label {
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 3rem;
}

.input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  background: #fff;
  width: 100%;
}

.input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--accent);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font: inherit;
  cursor: pointer;
  background: #e8eaef;
  color: var(--text);
}

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

.btn.sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.btn.full {
  width: 100%;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}

.link-btn.danger {
  color: var(--danger);
}

.toolbar {
  margin-bottom: 1rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.grid {
  display: grid;
  gap: 1rem;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: 1.5rem;
}

.stat-card {
  min-height: 110px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 0.25rem;
}

.stat-card.accent .stat-meta {
  font-size: 0.95rem;
  margin-top: 0.35rem;
  color: var(--muted);
}

.prose {
  font-size: 0.95rem;
  color: var(--muted);
}

.prose h2,
.prose h3 {
  color: var(--text);
  margin-top: 0;
}

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

.table-detailed {
  font-size: 0.875rem;
}

.table-detailed th,
.table-detailed td {
  vertical-align: top;
}

.col-id {
  white-space: nowrap;
  width: 4rem;
}

.col-thumb {
  width: 88px;
  text-align: center;
}

.thumb-link {
  display: inline-block;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  line-height: 0;
}

.thumb-img {
  display: block;
  width: 80px;
  height: 52px;
  object-fit: cover;
  background: #f1f5f9;
}

.cell-main {
  font-weight: 500;
  max-width: 140px;
}

.cell-wrap {
  max-width: 220px;
  word-break: break-word;
}

.cell-summary {
  max-width: 420px;
  font-size: 0.82rem;
  color: var(--muted);
}

.col-actions {
  width: 4rem;
}

.col-pos {
  max-width: 10rem;
}

.col-change {
  max-width: 14rem;
}

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}

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

.small {
  font-size: 0.85rem;
}

.tiny {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
}

.center {
  text-align: center;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
}

.pill.ok {
  background: #ecfdf3;
  color: #15803d;
}

.pill.warn {
  background: #fef3c7;
  color: #b45309;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 1rem 0;
}

.pager-link {
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.pager-link.is-current {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.pager-full {
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
}

.pager-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.pager-summary {
  flex: 1;
  min-width: 200px;
}

.pager-edge.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-brand {
  font-size: 1.35rem;
  font-weight: 700;
}

.auth-sub {
  margin: 0.25rem 0 1.25rem;
  color: var(--muted);
}

.flash {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.flash-warn {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.user-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.user-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.user-email {
  font-weight: 600;
}

.user-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.role-grid,
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.35rem 0.75rem;
}

.perm-block {
  margin-bottom: 1rem;
}

.perm-module {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.role-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.perm-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.inline-form {
  display: inline;
}

.inline-code {
  background: #f1f5f9;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.block-code {
  display: block;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  word-break: break-all;
  font-size: 0.85rem;
}

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

.checkbox-cell {
  width: 2rem;
}

.table-link {
  font-weight: 600;
  color: var(--accent);
}

.nowrap {
  white-space: nowrap;
}

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

.btn.danger-outline:hover {
  background: #fef2f2;
}

.injury-layout {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.injury-doll {
  width: 140px;
  height: auto;
  flex-shrink: 0;
}

.injury-doll--compact {
  width: 52px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.col-doll {
  width: 4.5rem;
  vertical-align: middle;
}

.cell-doll {
  text-align: center;
}

.cell-doll .tiny {
  display: block;
  margin-top: 0.15rem;
  max-width: 4.5rem;
}

.injury-meta {
  flex: 1;
  min-width: 200px;
  font-size: 0.95rem;
}

.screenshot-frame {
  margin-top: 0.75rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-width: 960px;
  background: #0f172a;
}

.screenshot-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.screenshot-link {
  word-break: break-all;
  font-size: 0.85rem;
}

.back-row {
  margin: 0 0 0.5rem;
}

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

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar-footer {
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 0 0 0 1rem;
    margin: 0 0 0 auto;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }

  .nav-group-label {
    width: 100%;
  }

  .main {
    padding: 1.25rem;
  }
}
