:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #172033;
  background: #f5f7fb;
  --iam-primary: #236ce5;
  --iam-primary-hover: #195bc3;
  --iam-sidebar: #0d1b35;
  --iam-sidebar-active: #1b3158;
  --iam-text: #172033;
  --iam-text-secondary: #5d6a82;
  --iam-border: #dce3ee;
  --iam-surface: #ffffff;
  --iam-danger: #b52f40;
  --iam-focus: #74a7ff;
  --iam-radius: 12px;
}

* { box-sizing: border-box; }
html { min-width: 0; }
body { margin: 0; min-width: 0; background: #f5f7fb; }
button, input, textarea { font: inherit; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

:where(button, a, input, textarea):focus-visible {
  outline: 3px solid var(--iam-focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 40;
  transform: translateY(-160%);
  border-radius: 7px;
  padding: 9px 12px;
  background: #fff;
  color: #173c76;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.skip-link:focus { transform: translateY(0); }

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

.sidebar {
  min-height: 100vh;
  padding: 0 16px 28px;
  background: var(--iam-sidebar);
  color: #fff;
}

.brand {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 4px;
  margin-bottom: 14px;
  padding: 18px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.brand-company {
  color: #8fa2c1;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .14em;
}

.brand-product {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: .02em;
}

.nav { display: grid; gap: 6px; }
.nav a {
  min-height: 46px;
  display: flex;
  align-items: center;
  position: relative;
  border-radius: 8px;
  padding: 0 14px 0 16px;
  color: #b8c5da;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .01em;
  text-decoration: none;
}
.nav a:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.nav a.active {
  color: #fff;
  background: #182f54;
  box-shadow: inset 3px 0 0 #4387ff;
  font-weight: 600;
}

.content {
  width: 100%;
  max-width: 1480px;
  min-width: 0;
  padding: 34px 42px 54px;
}

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

h1 { margin: 0; font-size: 24px; letter-spacing: .02em; }
h2 { margin: 0; }

.session {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: #4a5872;
}
.session strong { color: var(--iam-text); font-size: 14px; }
.session-role {
  padding: 4px 9px;
  border-radius: 999px;
  background: #e7f0ff;
  color: #215ebe;
  font-size: 12px;
  white-space: nowrap;
}
.session button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 8px 10px;
  background: transparent;
  color: #45536c;
  font-size: 13px;
}
.session button:hover { background: #e8edf5; color: #233654; }

.panel {
  margin-bottom: 20px;
  overflow: visible;
  border: 1px solid #e2e7f0;
  border-radius: var(--iam-radius);
  background: var(--iam-surface);
  box-shadow: 0 8px 24px rgba(20, 42, 85, .05);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 16px 22px;
  border-bottom: 1px solid #edf0f5;
}
.panel-header h2 { font-size: 16px; }
.panel-body { padding: 20px 22px; }

.primary, .secondary, .danger-solid, .text-button {
  min-height: 40px;
  border-radius: 7px;
  padding: 8px 13px;
}
.primary {
  border: 1px solid var(--iam-primary);
  background: var(--iam-primary);
  color: #fff;
}
.primary:hover { border-color: var(--iam-primary-hover); background: var(--iam-primary-hover); }
.secondary {
  border: 1px solid #c2cddd;
  background: #fff;
  color: #33425e;
}
.secondary:hover { background: #f1f4f9; }
.danger-solid {
  border: 1px solid var(--iam-danger);
  background: var(--iam-danger);
  color: #fff;
}
.danger-solid:hover { background: #942333; }
.text-button { border: 0; background: transparent; color: #315f9f; }
.text-button:hover { background: #eef4ff; }

.toolbar, .filter-grid {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
}
.toolbar label, .filter-grid label, .form-grid label, .dialog-content label, .field {
  display: grid;
  gap: 7px;
  color: #45536c;
  font-size: 13px;
}
.toolbar label > span, .filter-grid label > span, .form-grid label > span, .dialog-content label > span, .field-label { font-weight: 600; }
.toolbar input, .filter-grid input, .form-grid input, .dialog-content textarea {
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid #c8d3e2;
  border-radius: 7px;
  background: #fff;
  color: var(--iam-text);
}
.toolbar input { width: 270px; }
.filter-grid { display: grid; grid-template-columns: minmax(160px, 1fr) repeat(2, minmax(140px, .75fr)) repeat(2, minmax(145px, .75fr)) auto; }
.filter-actions { display: flex; align-items: center; gap: 6px; }

.select-field { min-width: 150px; }
.custom-select { position: relative; min-width: 0; }
.custom-select-trigger {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid #c8d3e2;
  border-radius: 7px;
  padding: 8px 11px;
  background: #fff;
  color: var(--iam-text);
  text-align: left;
}
.custom-select-trigger:hover { border-color: #9eafc7; background: #fff; }
.custom-select-trigger[aria-expanded="true"] { border-color: var(--iam-primary); box-shadow: 0 0 0 3px rgba(35, 108, 229, .14); }
.custom-select-indicator { width: 12px; height: 12px; flex: 0 0 auto; transition: transform .16s ease; }
.custom-select-trigger[aria-expanded="true"] .custom-select-indicator { transform: rotate(180deg); }
.custom-select-listbox {
  position: absolute;
  z-index: 50;
  top: calc(100% + 6px);
  left: 0;
  width: max(100%, 180px);
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid #c8d3e2;
  border-radius: 8px;
  padding: 5px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(13, 27, 53, .18);
}
.custom-select-listbox.opens-upward {
  top: auto;
  bottom: calc(100% + 6px);
}
.custom-select-option {
  width: 100%;
  min-height: 40px;
  display: block;
  border: 0;
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--iam-text);
  text-align: left;
  white-space: nowrap;
}
.custom-select-option:hover, .custom-select-option:focus-visible { background: #edf4ff; }
.custom-select-option[aria-selected="true"] { background: #e4efff; color: #174f9f; font-weight: 600; }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}
table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: #5e6c85; background: #f8faff; font-weight: 600; }
th, td { padding: 13px 10px; border-bottom: 1px solid #edf0f5; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover:not(:has(.empty-state)) { background: #fbfcff; }
td.actions { min-width: 222px; white-space: nowrap; }

.action, .danger-link {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 8px 9px;
  background: transparent;
}
.action { color: #225dbc; }
.action:hover { background: #eef4ff; }
.danger-link { color: var(--iam-danger); }
.danger-link:hover { background: #fff0f2; }

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  white-space: nowrap;
}
.tag.active, .tag.succeeded { background: #e9f8ed; color: #1f7540; }
.tag.pending { background: #fff6df; color: #87570d; }
.tag.disabled, .tag.failed { background: #fdeced; color: #a52f3d; }
.tag.rejected { background: #fff3df; color: #8b5a10; }
.tag.iam_admin { background: #e7f0ff; color: #215ebe; }
.tag.iam_auditor { background: #f0ecff; color: #6545af; }
.current-account { color: #315f9f; font-size: 12px; font-weight: 600; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-top: 16px;
  color: var(--iam-text-secondary);
  font-size: 13px;
}
.pagination > div { display: flex; gap: 8px; }

.empty-state {
  min-height: 150px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: #66738b;
  text-align: center;
}
.empty-state strong { color: #495873; font-weight: 500; }

.state-panel {
  min-height: 300px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 40px;
  text-align: center;
}
.state-panel p { margin: 0; color: var(--iam-text-secondary); }
.state-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff0f2;
  color: var(--iam-danger);
  font-size: 22px;
  font-weight: 700;
}

.loading-panel { min-height: 290px; }
.loading-card {
  align-self: start;
  margin: 12vh auto;
  padding: 22px 26px;
  border: 1px solid var(--iam-border);
  border-radius: 10px;
  background: #fff;
  color: var(--iam-text-secondary);
  box-shadow: 0 10px 28px rgba(26, 48, 88, .08);
}
.skeleton-list { display: grid; gap: 14px; padding: 28px 22px; }
.skeleton-list span {
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(90deg, #eef2f7 25%, #f8faff 50%, #eef2f7 75%);
  background-size: 200% 100%;
  animation: iam-shimmer 1.4s infinite;
}

dialog {
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: #fff;
  color: var(--iam-text);
  box-shadow: 0 24px 70px rgba(12, 27, 55, .24);
}
dialog::backdrop { background: rgba(13, 27, 53, .48); }
.confirm-dialog { width: min(500px, calc(100vw - 32px)); }
.wide-dialog { width: min(960px, calc(100vw - 32px)); padding: 0 22px 22px; }
.side-dialog {
  width: min(460px, calc(100vw - 24px));
  max-width: none;
  height: 100vh;
  max-height: 100vh;
  margin: 0 0 0 auto;
  border-radius: 14px 0 0 14px;
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 16px 22px;
  border-bottom: 1px solid #edf0f5;
}
.dialog-header h2 { font-size: 18px; }
.icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #52617a;
  font-size: 24px;
  line-height: 1;
}
.icon-button:hover { background: #eef2f7; }
.dialog-content { display: grid; gap: 18px; padding: 20px 22px; }
.dialog-content p { margin: 0; color: #4f5e77; line-height: 1.7; }
.dialog-content textarea { min-height: 100px; resize: vertical; }
.confirm-target { display: grid; gap: 6px; padding: 13px 14px; border-radius: 8px; background: #f6f8fc; }
.confirm-target span { color: #6c7890; font-size: 12px; }
.confirm-target strong { overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px 20px; border-top: 1px solid #edf0f5; }
.detail-grid { display: grid; gap: 0; margin: 0; padding: 12px 22px 28px; }
.detail-grid div { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px; padding: 16px 0; border-bottom: 1px solid #edf0f5; }
.detail-grid div:last-child { border-bottom: 0; }
.detail-grid dt { color: #6c7890; font-size: 13px; }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; color: #263652; font-size: 14px; }

.toast {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 13px 14px 13px 16px;
  border-radius: 9px;
  background: #172d52;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  font-size: 13px;
}
.toast-error { background: #7f2430; }
.toast button { min-height: 32px; border: 0; border-radius: 5px; padding: 4px 7px; background: rgba(255, 255, 255, .13); color: #fff; }

@keyframes iam-shimmer { to { background-position: -200% 0; } }

@media (max-width: 1180px) {
  .shell { grid-template-columns: 210px minmax(0, 1fr); }
  .content { padding: 28px 24px 44px; }
  .filter-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
}

@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { min-height: 0; padding: 16px; }
  .brand { min-height: 0; margin-bottom: 14px; padding: 0 4px 15px; }
  .nav { display: flex; gap: 8px; overflow-x: auto; }
  .nav a { flex: 0 0 auto; }
  .content { padding: 22px 16px 36px; }
  .topbar { align-items: flex-start; margin-bottom: 22px; }
  h1 { font-size: 21px; }
  .session { flex-wrap: wrap; gap: 7px; }
  .panel-body { padding: 16px; }
  .toolbar, .filter-grid { display: grid; grid-template-columns: 1fr; align-items: stretch; }
  .toolbar input { width: 100%; }
  .select-field, .custom-select { width: 100%; }
  .filter-submit, .filter-actions > button { width: 100%; }
  .filter-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .pagination > div { width: 100%; }
  .pagination button { flex: 1; }
  .side-dialog { width: calc(100vw - 12px); }
  .toast { right: 16px; bottom: 16px; }
}

@media (max-width: 480px) {
  .topbar { display: grid; }
  .session { justify-content: flex-start; }
  .panel-header { padding: 15px 16px; }
  .dialog-header, .dialog-content, .dialog-actions { padding-left: 16px; padding-right: 16px; }
  .detail-grid { padding-left: 16px; padding-right: 16px; }
  .detail-grid div { grid-template-columns: 1fr; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-list span { animation: none; }
  .custom-select-indicator { transition: none; }
}
