:root {
  --sidebar-bg: #101828;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #ffffff;
  --accent: #2563eb;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e3e8f0;
  --text: #182230;
  --muted: #667085;
  --green: #16a34a;
  --orange: #d97706;
  --red: #dc2626;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

.admin-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 236px;
  flex: 0 0 236px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 38px;
}

.brand-mark.large {
  width: 52px;
  height: 52px;
  font-size: 26px;
  border-radius: 10px;
  flex-basis: 52px;
}

.brand-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.brand-text strong { color: #fff; font-size: 15px; }
.brand-text span { color: #94a3b8; font-size: 12px; }

.nav { padding: 14px 10px; overflow-y: auto; flex: 1; }
.nav-label {
  color: #7c8db5;
  font-size: 11px;
  letter-spacing: 0;
  padding: 14px 10px 6px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 2px;
  transition: background 0.15s ease;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: rgba(37, 99, 235, 0.22); color: #fff; }
.nav-item.active .nav-dot { background: #60a5fa; box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18); }

.nav-group { margin-bottom: 2px; }
.nav-group > summary { list-style: none; cursor: pointer; user-select: none; }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group.is-active > summary { background: rgba(37, 99, 235, 0.18); color: #fff; }
.nav-group.is-active > summary .nav-dot { background: #60a5fa; }

.nav-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid #94a3b8;
  border-bottom: 2px solid #94a3b8;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  flex: 0 0 8px;
  margin-left: auto;
}

.nav-group[open] .nav-chevron { transform: rotate(225deg); }

.nav-sub { padding: 2px 0 4px 22px; }
.nav-sub .nav-item {
  padding: 8px 12px;
  font-size: 13px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0 6px 6px 0;
}

.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  flex: 0 0 8px;
}

.sidebar-foot {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-mini-text { display: flex; flex-direction: column; min-width: 0; }
.user-mini-text strong { color: #fff; font-size: 13px; }
.user-mini-text span { color: #94a3b8; font-size: 12px; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex: 0 0 34px;
}

.avatar.small {
  width: 30px;
  height: 30px;
  font-size: 12px;
  flex-basis: 30px;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: 236px;
}

.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.topbar-time { color: var(--muted); font-size: 12px; }
.menu-toggle { display: none; }

.content { padding: 24px; max-width: 1440px; }

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

.page-head h2 { margin: 0 0 4px; font-size: 22px; }
.page-head p { margin: 0; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 20px;
  min-width: 0;
}

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

.panel-head h3 { margin: 0; font-size: 15px; }
.panel-hint { color: var(--muted); font-size: 12px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.stat-label { color: var(--muted); font-size: 13px; }
.stat-card strong { font-size: 28px; line-height: 1.1; }
.stat-meta { color: var(--muted); font-size: 12px; }
.stat-meta.positive { color: var(--green); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 16px;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(34px, 1fr));
  gap: 12px;
  align-items: end;
  height: 240px;
  padding-top: 10px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  min-width: 0;
}

.bar-track {
  flex: 1;
  width: 100%;
  max-width: 42px;
  background: #eef2f8;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 3px;
  background: var(--accent);
  border-radius: 4px;
}

.bar-value { font-size: 12px; color: var(--muted); }
.bar-label { font-size: 11px; color: var(--muted); }

.role-dist { display: flex; flex-direction: column; gap: 14px; }
.role-dist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.role-dist-row:last-child { border-bottom: 0; padding-bottom: 0; }
.role-dist-name { display: flex; align-items: center; gap: 8px; }
.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 10px; }

.table-scroll { overflow-x: auto; }
.layui-table { margin: 0; }
.layui-table th { white-space: nowrap; }
.empty-cell { text-align: center; color: var(--muted); padding: 28px 0 !important; }
.muted { color: var(--muted); }

.user-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.user-cell > div { display: flex; flex-direction: column; min-width: 0; }
.user-cell span { color: var(--muted); font-size: 12px; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--role-color, var(--accent));
  color: var(--role-color, var(--accent));
  background: color-mix(in srgb, var(--role-color, var(--accent)) 8%, #fff);
  font-size: 12px;
  white-space: nowrap;
}

.action-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inline-form { display: inline; }

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.filter-form .layui-inline { margin-right: 0; }
.filter-form .layui-input { width: 220px; }
.filter-form select { width: 150px; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.pagination .layui-btn + .layui-btn { margin-left: 8px; }

.form-panel { max-width: 720px; }
.form-error, .login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red);
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
}

.form-actions { padding-top: 8px; }
.color-input { padding: 4px 6px; height: 38px; width: 96px; }

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.role-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  min-width: 0;
}

.role-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.role-card-head h3 { margin: 0 0 2px; font-size: 16px; }
.role-code { color: var(--muted); font-size: 12px; }
.role-desc { color: var(--muted); min-height: 40px; margin: 0 0 12px; }
.role-meta { display: flex; gap: 16px; color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.role-actions { display: flex; gap: 8px; align-items: center; }

.perm-group-title {
  font-weight: 600;
  padding: 14px 0 8px;
  border-top: 1px solid var(--border);
  margin-top: 14px;
}

.perm-group { margin-bottom: 14px; }
.perm-group-head {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.perm-check-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.perm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  min-width: 0;
}

.perm-check small { color: var(--muted); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.perm-module { margin-bottom: 24px; }
.perm-module:last-child { margin-bottom: 0; }
.perm-module-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.perm-module-head h3 { margin: 0; font-size: 15px; }

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

.settings-tabs-panel { max-width: 960px; }
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dict-desc {
  color: var(--muted);
  margin: -8px 0 14px;
}

.dict-panel {
  max-width: 1080px;
}

.settings-tabs-panel .layui-form-label {
  width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-tabs-panel .layui-input-block { margin-left: 138px; }

.setting-group { margin-bottom: 16px; }
.setting-group-head { font-weight: 600; margin-bottom: 6px; }
.setting-desc { color: var(--muted); font-size: 12px; margin-top: 4px; }

.login-body, .standalone-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef2f7;
  padding: 24px;
}

.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 18px 40px rgba(16, 24, 40, 0.08);
}

.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-brand h1 { margin: 0; font-size: 20px; }
.login-brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.login-btn { width: 100%; margin-top: 8px; }

.captcha-row .captcha-input {
  display: flex;
  align-items: center;
  gap: 10px;
}

.captcha-row .captcha-input .layui-input {
  flex: 1;
  min-width: 0;
}

.captcha-img {
  width: 128px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  object-fit: cover;
}

.standalone-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(16, 24, 40, 0.08);
}

.standalone-card h1 { font-size: 56px; margin: 0; color: var(--red); }
.standalone-card p { color: var(--muted); margin: 8px 0 20px; }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .admin-shell.sidebar-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, 0.3); }
  .main { margin-left: 0; }
  .menu-toggle {
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font-size: 16px;
    cursor: pointer;
  }
  .topbar { padding: 0 14px; }
  .topbar-time { display: none; }
  .content { padding: 16px; }
  .page-head { flex-direction: column; align-items: stretch; }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .bar-chart { gap: 6px; }
  .filter-form .layui-input, .filter-form select { width: 100%; }
  .filter-form .layui-inline { width: 100%; }
  .pagination { flex-direction: column; align-items: flex-start; }
}
