:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e0e8;
  --soft: #f5f7fa;
  --panel: #ffffff;
  --primary: #176b87;
  --primary-dark: #0f5067;
  --accent: #bf6b21;
  --danger: #b42318;
  --success: #087443;
  --shadow: 0 16px 40px rgba(20, 36, 50, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #eef2f5;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(23, 107, 135, 0.88), rgba(191, 107, 33, 0.72)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1600' height='1000' viewBox='0 0 1600 1000'%3E%3Crect fill='%23e8eef2' width='1600' height='1000'/%3E%3Cg fill='none' stroke='%23bac7d2' stroke-width='2' opacity='.65'%3E%3Cpath d='M120 160h320v190H120zM520 160h280v190H520zM900 160h500v190H900zM120 440h500v230H120zM720 440h270v230H720zM1080 440h320v230h-320zM120 760h1280'/%3E%3Cpath d='M280 350v90M660 350v90M1180 350v90M440 670v90M850 670v90M1240 670v90'/%3E%3C/g%3E%3C/svg%3E") center / cover;
}

.login-panel {
  width: min(960px, 100%);
  min-height: 520px;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 40px;
  align-items: center;
  padding: 56px;
  border-radius: 8px;
  color: #fff;
  background: rgba(15, 50, 64, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.login-panel h1 {
  margin: 8px 0 18px;
  font-size: clamp(36px, 5vw, 64px);
  line-height: 1.05;
  letter-spacing: 0;
}

.login-copy {
  width: min(560px, 100%);
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.8;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

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

label {
  display: grid;
  gap: 8px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.icon-btn {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-weight: 700;
}

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

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

.secondary-btn {
  color: var(--primary);
  background: #eef8fb;
  border-color: #b9dbe5;
}

.ghost-btn {
  color: var(--ink);
  background: transparent;
  border-color: var(--line);
}

.danger-btn {
  color: var(--danger);
  border-color: #f0b8b2;
}

.icon-btn {
  width: 36px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
  font-size: 24px;
  line-height: 1;
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
}

.app-shell {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  color: #f8fafc;
  background: #1f343d;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 900;
}

.brand small {
  display: block;
  color: rgba(255, 255, 255, 0.65);
}

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

.nav button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 11px 12px;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  text-align: left;
  font-weight: 700;
}

.nav button.active,
.nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 16px 8px 4px;
  color: rgba(255, 255, 255, 0.76);
}

.sidebar-footer .ghost-btn {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.24);
}

.content {
  min-width: 0;
  padding: 26px;
}

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

.topbar h2 {
  margin: 4px 0 0;
  font-size: 30px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

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

.metric,
.content section > .side-panel,
.split > section,
.scan-box,
.matrix-editor,
.role-layout > .side-panel,
.matrix-layout > .side-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 4px 18px rgba(20, 36, 50, 0.05);
}

.metric {
  padding: 18px;
}

.metric small {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 34px;
}

.metric.danger strong {
  color: var(--danger);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.split > section {
  padding: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h3 {
  margin: 0;
  font-size: 20px;
}

.table-tools {
  margin-bottom: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #43515f;
  background: #f8fafc;
  font-size: 13px;
}

td {
  color: #26313b;
}

tr:last-child td {
  border-bottom: 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #344054;
  background: #eef2f5;
  font-size: 12px;
  font-weight: 800;
}

.tag.ok {
  color: var(--success);
  background: #e8f6ef;
}

.tag.warn {
  color: var(--danger);
  background: #fff0ed;
}

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

.row-actions button {
  min-height: 32px;
  padding: 5px 9px;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

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

.timeline-item strong {
  display: block;
}

.timeline-item small,
.muted {
  color: var(--muted);
}

.role-layout,
.matrix-layout,
.qiming-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.matrix-layout {
  grid-template-columns: 280px minmax(0, 1fr);
}

.qiming-layout {
  grid-template-columns: 280px minmax(0, 1fr);
  align-items: start;
}

.side-panel,
.matrix-editor,
.scan-box {
  padding: 18px;
}

.side-panel h3,
.matrix-editor h3,
.matrix-section h4 {
  margin-top: 0;
}

.checkbox-list,
.select-list {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow: auto;
}

.check-row,
.select-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

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

.select-row {
  justify-content: space-between;
  width: 100%;
  color: var(--ink);
  text-align: left;
}

.select-row.active {
  border-color: var(--primary);
  background: #eef8fb;
}

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

.permission-groups {
  display: grid;
  gap: 14px;
}

.permission-group {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.permission-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.permission-group-head h4 {
  margin: 0;
  font-size: 16px;
}

.permission-group-head span {
  color: var(--muted);
  font-weight: 700;
}

.permission-list {
  display: grid;
}

.permission-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

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

.permission-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.permission-item input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.permission-editor-group {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.permission-group-check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  padding: 4px 2px 6px;
  width: 100%;
}

.permission-group-check input {
  width: 16px;
  height: 16px;
}

.permission-group-check small {
  margin-left: auto;
  color: var(--muted);
  font-weight: 700;
}

.form-check-list {
  max-height: 260px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.dialog-copy {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.65;
}

.check-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding: 2px;
}

.check-list .check-row {
  align-items: flex-start;
}

.check-list small {
  color: var(--muted);
}

.simple-matrix {
  max-width: 100%;
}

.simple-matrix table {
  min-width: 980px;
}

.simple-matrix th,
.simple-matrix td {
  text-align: center;
}

.simple-matrix th:first-child,
.simple-matrix td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 150px;
  text-align: left;
  background: #fff;
}

.simple-matrix thead th:first-child {
  background: #f8fafc;
}

.matrix-system-header {
  cursor: grab;
  user-select: none;
}

.matrix-system-header.dragging {
  opacity: .45;
}

.matrix-system-header.drag-over {
  background: #dbeafe;
  box-shadow: inset 3px 0 0 #2563eb;
}

.matrix-cell input {
  width: 18px;
  height: 18px;
}

.matrix-section {
  margin-top: 18px;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.46);
}

dialog form {
  padding: 20px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head {
  margin-bottom: 18px;
}

.dialog-head h3 {
  margin: 0;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

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

.form-grid label.full {
  grid-column: 1 / -1;
}

.password-box {
  white-space: pre-wrap;
  padding: 12px;
  border-radius: 6px;
  color: #092c1e;
  background: #e8f6ef;
}

@media (max-width: 980px) {
  .app-shell,
  .login-panel,
  .split,
  .role-layout,
  .matrix-layout,
  .qiming-layout {
    grid-template-columns: 1fr;
  }

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

  .nav {
    grid-template-columns: repeat(3, 1fr);
  }

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

@media (max-width: 640px) {
  .content,
  .login-panel {
    padding: 18px;
  }

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

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