:root {
  color-scheme: light;
  --bg: #eef3f5;
  --panel: #ffffff;
  --panel-soft: #f7fafb;
  --text: #172326;
  --muted: #6b7a80;
  --line: #dce5e8;
  --primary: #12b8a6;
  --primary-dark: #0a8f83;
  --blue: #2f6df6;
  --red: #d94a4a;
  --amber: #b87812;
  --green: #148c65;
  --shadow: 0 18px 45px rgba(18, 35, 38, .10);
}

body.dark {
  color-scheme: dark;
  --bg: #101417;
  --panel: #171d21;
  --panel-soft: #20282d;
  --text: #edf4f5;
  --muted: #9cadb2;
  --line: #2d383e;
  --primary: #22c9b7;
  --primary-dark: #4ad7c9;
  --blue: #74a0ff;
  --red: #ff7373;
  --amber: #e3ad4d;
  --green: #56c79b;
  --shadow: 0 18px 45px rgba(0, 0, 0, .34);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

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

.boot {
  gap: 14px;
  align-content: center;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 28px;
  background: transparent;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.boot-ring {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(18, 184, 166, .18);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}

.boot p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.login-card {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 30px;
  box-shadow: var(--shadow);
}

.login-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-title b {
  display: block;
  font-size: 22px;
}

.login-title span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 16px;
  min-width: 0;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--line);
}

.side-brand .brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 22px;
  box-shadow: none;
}

.side-brand b {
  display: block;
  line-height: 1.15;
}

.side-brand span {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding: 2px 2px 8px;
  min-width: 0;
  max-width: 100%;
  scrollbar-width: thin;
}

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

.nav-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px;
  color: var(--muted);
}

.nav-label span {
  font-size: 11px;
  font-weight: 800;
}

.nav-label em {
  font-style: normal;
  font-size: 10px;
  opacity: .72;
}

.nav button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 8px;
  align-items: center;
  text-align: left;
  padding: 6px 10px;
  position: relative;
  overflow: hidden;
}

.nav button:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.nav button.active {
  background: rgba(18, 184, 166, .12);
  color: var(--primary-dark);
  font-weight: 700;
}

.nav button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.nav button span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.nav button strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  line-height: 1.15;
}

.nav button small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav button.active strong,
.nav button.active small {
  color: var(--primary-dark);
}

.nav i,
.tiny-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
  color: var(--primary-dark);
  background: rgba(18, 184, 166, .14);
}

.side-foot {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.side-foot .btn {
  min-height: 36px;
}

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

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

.page-title b {
  display: block;
  font-size: 24px;
}

.page-title span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

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

.admin-chip {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 12px;
  white-space: nowrap;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .02);
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-head b {
  font-size: 15px;
}

.panel-body {
  padding: 16px;
  min-width: 0;
}

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

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-height: 88px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat b {
  display: block;
  font-size: 26px;
  line-height: 1.2;
  margin-top: 10px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .55fr);
  gap: 14px;
}

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

.bar {
  min-width: 0;
  display: grid;
  gap: 6px;
  align-items: end;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

.bar span {
  display: block;
  width: 100%;
  min-height: 6px;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, var(--primary), var(--blue));
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

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

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

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  padding: 8px 10px;
  outline: none;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(18, 184, 166, .12);
}

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--primary);
}

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

.btn.danger {
  color: #fff;
  border-color: var(--red);
  background: var(--red);
}

.btn.ghost {
  background: transparent;
}

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

.btn.disabled {
  opacity: .45;
  pointer-events: none;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  padding-top: 12px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  max-width: 100%;
  min-width: 0;
}

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

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

th {
  color: var(--muted);
  font-weight: 700;
  background: var(--panel-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  color: var(--text);
}

.primary-text {
  font-weight: 700;
}

.sub-text {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  max-width: 440px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.badge.ok {
  color: var(--green);
  background: rgba(20, 140, 101, .10);
  border-color: rgba(20, 140, 101, .22);
}

.badge.warn {
  color: var(--amber);
  background: rgba(184, 120, 18, .12);
  border-color: rgba(184, 120, 18, .22);
}

.badge.bad {
  color: var(--red);
  background: rgba(217, 74, 74, .12);
  border-color: rgba(217, 74, 74, .25);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.avatar.big {
  width: 52px;
  height: 52px;
  border-radius: 12px;
}

.identity {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
}

.empty,
.error {
  padding: 34px 16px;
  color: var(--muted);
  text-align: center;
}

.error {
  color: var(--red);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(520px, calc(100vw - 30px));
  background: rgba(23, 35, 38, .92);
  color: #fff;
  border-radius: 8px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
}

body.dark .toast {
  background: rgba(237, 244, 245, .94);
  color: #101417;
}

.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(9, 18, 21, .35);
  display: flex;
  justify-content: flex-end;
}

.drawer {
  width: min(560px, 100%);
  height: 100%;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.drawer.wide {
  width: min(900px, 100%);
}

.drawer-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-body {
  overflow: auto;
  padding: 16px;
}

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

.stack {
  display: grid;
  gap: 12px;
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

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

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

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.mini-stats div,
.role-card,
.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.mini-stats span,
.role-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.mini-stats b {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.detail-section {
  display: grid;
  gap: 8px;
}

.detail-section h3 {
  margin: 4px 0 0;
  font-size: 14px;
}

.detail-card p {
  margin: 8px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.role-card {
  display: grid;
  gap: 6px;
}

.role-card p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

.selected-row td {
  background: rgba(18, 184, 166, .10);
}

.settings-grid {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

@media (max-height: 920px) and (min-width: 981px) {
  .sidebar {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .side-brand {
    padding-bottom: 10px;
  }

  .side-brand .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }

  .nav {
    gap: 6px;
  }

  .nav-section {
    gap: 3px;
  }

  .nav-label em,
  .nav button small {
    display: none;
  }

  .nav button {
    min-height: 34px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .nav i,
  .tiny-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-size: 10px;
  }

  .side-foot .btn {
    min-height: 34px;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px;
    overflow: hidden;
  }

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

  .nav-section {
    display: contents;
  }

  .nav-label {
    display: none;
  }

  .nav button {
    min-height: 42px;
    grid-template-columns: 24px auto;
    gap: 7px;
    padding: 7px 10px;
    white-space: nowrap;
  }

  .nav button i {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-size: 10px;
  }

  .nav button small {
    display: none;
  }

  .nav button.active::before {
    top: auto;
    right: 10px;
    bottom: 0;
    left: 10px;
    width: auto;
    height: 3px;
    border-radius: 3px 3px 0 0;
  }

  .side-foot {
    display: none;
  }

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

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

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

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

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

  .login-card {
    padding: 22px;
  }

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

  .mini-stats,
  .role-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

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

  table {
    min-width: 0;
    table-layout: fixed;
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 12px;
    word-break: break-word;
  }
}
