:root {
  color-scheme: light;
  font-family: Inter, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --brand: #1f3cff;
  --brand-hover: #1832db;
  --brand-soft: #eef2ff;
  --ink: #151b2b;
  --muted: #667085;
  --muted-2: #98a2b3;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --canvas: #f6f7f9;
  --surface: #ffffff;
  --green: #067647;
  --green-soft: #ecfdf3;
  --orange: #b54708;
  --orange-soft: #fff4e8;
  --purple: #6941c6;
  --purple-soft: #f4f0ff;
  --danger: #d92d20;
  --danger-soft: #fff1f0;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 12px 32px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  letter-spacing: 0;
}

button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.hidden { display: none !important; }

.brand-mark {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  color: #fff;
  font-size: 24px;
  font-weight: 750;
  background: linear-gradient(145deg, #1632b9 0%, #2456ff 55%, #16c2d6 100%);
  box-shadow: 0 8px 22px rgba(31, 60, 255, 0.2);
}

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

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(90deg, rgba(31, 60, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(31, 60, 255, 0.035) 1px, transparent 1px),
    #f8f9fb;
  background-size: 32px 32px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 28px 36px;
  font-size: 18px;
  font-weight: 700;
}

.login-panel {
  align-self: center;
  justify-self: center;
  width: min(440px, calc(100vw - 40px));
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow-md);
}

.login-heading { margin-bottom: 30px; }
.login-heading h1 { margin: 8px 0 8px; font-size: 30px; line-height: 1.25; }
.login-heading p { margin: 0; color: var(--muted); font-size: 15px; }
.login-kicker, .section-kicker, .breadcrumb {
  color: var(--brand);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

label, legend {
  display: block;
  margin: 0 0 8px;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
}

input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 60, 255, 0.12);
}

input::placeholder { color: var(--muted-2); }
form > label:not(:first-child), .modal-body > label:not(:first-child) { margin-top: 18px; }

.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.password-field .icon-button { position: absolute; top: 4px; right: 4px; }

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #475467;
  background: transparent;
}

.icon-button:hover { color: var(--brand); background: var(--brand-soft); }
.icon-button:focus-visible, .nav-button:focus-visible, .primary-button:focus-visible, .secondary-button:focus-visible {
  outline: 3px solid rgba(31, 60, 255, 0.2);
  outline-offset: 1px;
}
.icon-button.compact { width: 36px; height: 36px; }
.icon-button svg { width: 19px; height: 19px; stroke-width: 1.8; }

.primary-button, .secondary-button, .danger-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 6px;
  font-weight: 650;
  border: 1px solid transparent;
}

.primary-button { color: #fff; background: var(--brand); box-shadow: var(--shadow-sm); }
.primary-button:hover { background: var(--brand-hover); }
.secondary-button { color: #344054; background: #fff; border-color: var(--line-strong); }
.secondary-button:hover { background: #f9fafb; }
.danger-button { color: var(--danger); background: #fff; border-color: #fecdca; }
.danger-button:hover { background: var(--danger-soft); }
.primary-button svg, .secondary-button svg { width: 17px; height: 17px; }
.login-button { width: 100%; margin-top: 22px; }

.form-error { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 13px; }
.field-hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.login-footer { padding: 22px; text-align: center; color: var(--muted-2); font-size: 12px; }

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

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: #fff;
}

.sidebar-brand {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand > div { min-width: 0; display: grid; gap: 2px; }
.sidebar-brand strong { font-size: 16px; white-space: nowrap; }
.sidebar-brand span:not(.brand-mark) { color: var(--muted); font-size: 11px; }
.sidebar-close { display: none; margin-left: auto; }

.sidebar-nav { min-height: 0; overflow-y: auto; padding: 16px 10px; }
.nav-button {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: #475467;
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 560;
}
.nav-button svg { width: 19px; height: 19px; stroke-width: 1.7; }
.nav-button:hover { color: var(--ink); background: #f2f4f7; }
.nav-button.active { color: var(--brand); background: var(--brand-soft); font-weight: 700; }

.sidebar-user {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border-top: 1px solid var(--line);
}
.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--brand);
  background: var(--brand-soft);
  font-weight: 750;
}
.sidebar-user-copy { min-width: 0; display: grid; gap: 2px; flex: 1; }
.sidebar-user-copy strong, .sidebar-user-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-copy strong { font-size: 13px; }
.sidebar-user-copy span { color: var(--muted); font-size: 11px; }

.sidebar-scrim { display: none; }
.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}
.topbar-leading, .topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-leading h2 { margin: 3px 0 0; font-size: 20px; line-height: 1.2; }
.topbar #sidebar-toggle { display: none; }
.environment-badge {
  padding: 5px 9px;
  border: 1px solid #b2ddff;
  border-radius: 999px;
  color: #175cd3;
  background: #eff8ff;
  font-size: 11px;
  font-weight: 650;
}

.content { width: min(1440px, 100%); margin: 0 auto; padding: 28px; outline: none; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-heading h1 { margin: 5px 0 5px; font-size: 28px; line-height: 1.25; }
.page-heading p { margin: 0; color: var(--muted); font-size: 14px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card, .panel, .empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.metric-card { min-height: 126px; padding: 19px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; }
.metric-icon svg { width: 18px; height: 18px; }
.metric-icon.blue { color: var(--brand); background: var(--brand-soft); }
.metric-icon.green { color: var(--green); background: var(--green-soft); }
.metric-icon.orange { color: var(--orange); background: var(--orange-soft); }
.metric-icon.purple { color: var(--purple); background: var(--purple-soft); }
.metric-copy { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.metric-copy strong { font-size: 28px; line-height: 1; }
.metric-copy span { color: var(--muted); font-size: 13px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr); gap: 14px; margin-top: 14px; }
.panel { overflow: hidden; }
.panel-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 16px; }
.panel-header span { color: var(--muted); font-size: 12px; }
.attention-list { padding: 4px 18px; }
.attention-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid #f0f1f3; }
.attention-row:last-child { border-bottom: 0; }
.attention-row span { color: #475467; font-size: 13px; }
.attention-row strong { font-size: 15px; }
.permission-summary { padding: 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.role-chip, .status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}
.role-chip { color: #344054; background: #f2f4f7; }
.role-chip svg { width: 14px; height: 14px; }
.status-chip.active { color: var(--green); background: var(--green-soft); }
.status-chip.revoked, .status-chip.not_granted { color: var(--muted); background: #f2f4f7; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.search-box { position: relative; width: min(360px, 100%); }
.search-box svg { position: absolute; top: 12px; left: 12px; width: 18px; height: 18px; color: var(--muted-2); }
.search-box input { padding-left: 39px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #f9fafb; font-size: 11px; font-weight: 700; text-transform: uppercase; }
td { color: #344054; font-size: 13px; }
.user-column { width: 30%; }
.role-column { width: 25%; }
.status-column, .account-column, .actions-column { width: 15%; }
.actions-column { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
.user-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-cell-copy { min-width: 0; display: grid; gap: 3px; }
.user-cell-copy strong, .user-cell-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-cell-copy span { color: var(--muted); font-size: 11px; }
.table-actions { display: flex; justify-content: flex-end; gap: 4px; }
.table-empty { padding: 48px 20px; text-align: center; color: var(--muted); }

.empty-state { min-height: 360px; display: grid; place-items: center; padding: 32px; text-align: center; }
.empty-state > div { max-width: 420px; }
.empty-icon { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 14px; border-radius: 8px; color: var(--brand); background: var(--brand-soft); }
.empty-icon svg { width: 24px; height: 24px; }
.empty-state h2 { margin: 0 0 8px; font-size: 20px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 14px; }

.audit-list { display: grid; }
.audit-row { display: grid; grid-template-columns: 150px minmax(160px, 0.5fr) minmax(240px, 1fr) 150px; gap: 16px; align-items: center; min-height: 58px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 12px; }
.audit-row:last-child { border-bottom: 0; }
.audit-row time, .audit-row .audit-ip { color: var(--muted); }
.audit-actor { display: grid; gap: 2px; }
.audit-actor span { color: var(--muted); font-size: 11px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 24, 40, 0.48);
}
.modal {
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.24);
}
.small-modal { width: min(480px, 100%); }
.modal-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); background: #fff; }
.modal-header h2 { margin: 4px 0 0; font-size: 20px; }
.modal-body { padding: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.role-fieldset { margin: 22px 0 0; padding: 0; border: 0; }
.role-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.role-option { min-height: 58px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; }
.role-option:hover { border-color: #b7c1ff; background: #fafbff; }
.role-option input { width: 17px; height: 17px; padding: 0; box-shadow: none; }
.role-option span { font-size: 13px; font-weight: 600; }
.access-status-row { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; }
.access-status-row > div { display: grid; gap: 4px; }
.access-status-row strong { font-size: 13px; }
.access-status-row span { color: var(--muted); font-size: 11px; }
.switch { margin: 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 42px; height: 24px; display: block; padding: 3px; border-radius: 999px; background: #d0d5dd; transition: background 150ms ease; }
.switch span::after { content: ''; width: 18px; height: 18px; display: block; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 150ms ease; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin: 24px -22px -22px; padding: 16px 22px; border-top: 1px solid var(--line); background: #f9fafb; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 80; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 420px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: var(--shadow-md); font-size: 13px; }
.toast.success { border-color: #abefc6; color: var(--green); }
.toast.error { border-color: #fecdca; color: var(--danger); }

.skeleton { position: relative; overflow: hidden; background: #eaecf0; }
.skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .audit-row { grid-template-columns: 130px 1fr; }
  .audit-row .audit-ip { display: none; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; width: min(286px, 86vw); transform: translateX(-101%); transition: transform 180ms ease; box-shadow: var(--shadow-md); }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-close { display: inline-grid; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 15; border: 0; background: rgba(16, 24, 40, 0.35); }
  .app-shell.sidebar-open .sidebar-scrim { display: block; }
  .topbar { min-height: 64px; padding: 10px 16px; }
  .topbar #sidebar-toggle { display: inline-grid; }
  .environment-badge { display: none; }
  .content { padding: 18px 14px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 24px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { min-height: 112px; padding: 15px; }
  .metric-copy { display: grid; }
  .metric-copy strong { font-size: 24px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .form-grid, .role-options { grid-template-columns: 1fr; }
  .login-panel { padding: 28px 22px; }
  .login-brand { padding: 20px; }
  .audit-row { grid-template-columns: 1fr; gap: 4px; padding: 12px 14px; }
  table { min-width: 760px; }
}

@media (max-width: 420px) {
  .metric-grid { grid-template-columns: 1fr; }
  .topbar-actions { gap: 2px; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { max-height: 92vh; border-radius: 8px 8px 0 0; }
}
