/* ==========================================================================
   Identity Design System — unified production stylesheet
   Single source of truth for tokens, typography, spacing, components & layouts.
   Light/dark switch: html.dark   ·   Language: html[lang]
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  color-scheme: light;
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --surface-2: #F1F1EE;
  --surface-3: #E9E9E5;
  --fg: #1F1F1D;
  --fg-2: #6B6B66;
  --fg-3: #92928C;
  --border: #DEDEDA;
  --border-strong: #C6C6C0;
  --hairline: #E8E8E4;
  --primary: #1F1F1D;
  --primary-hover: #2E2E2B;
  --primary-active: #111110;
  --primary-fg: #FFFFFF;
  --ok: #1E6B45;
  --ok-bg: #E8F2EC;
  --ok-border: #C2DCCC;
  --danger: #B3261E;
  --danger-bg: #FBECEA;
  --danger-border: #F0C5C1;
  --warn: #8A5A00;
  --warn-bg: #FBF3E2;
  --warn-border: #EAD6A6;
  --focus-ring: 0 0 0 3px rgba(31, 31, 29, 0.16);
  --tile-id-bg: linear-gradient(180deg, #2C2C2A 0%, #1A1A19 100%);
  --tile-id-fg: #F7F7F5;
  --tile-id-edge: rgba(255, 255, 255, 0.14);
  --tile-app-bg: #FFFFFF;
  --tile-app-border: #DCDCD8;
  --shadow-1: 0 1px 2px rgba(20, 20, 20, 0.05);
  --shadow-2: 0 10px 30px -12px rgba(20, 20, 20, 0.22), 0 2px 8px -4px rgba(20, 20, 20, 0.08);
  --overlay: rgba(20, 20, 20, 0.42);
  --font-sans: "Geist", "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r-control: 8px;
  --r-card: 12px;
  --r-tile: 16px;
  --r-chip: 6px;
  --h-lg: 48px;
  --h-md: 40px;
  --h-sm: 32px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur: 160ms;
  --dur-slow: 220ms;
  --auth-container: 1120px;
  --auth-gutter: 40px;
  --sidebar-w: 248px;
  --content-w: 880px;
  --content-w-wide: 1040px;
}

html.dark {
  color-scheme: dark;
  --bg: #141414;
  --surface: #1C1C1C;
  --surface-2: #222221;
  --surface-3: #2A2A29;
  --fg: #F0F0ED;
  --fg-2: #A3A39D;
  --fg-3: #74746F;
  --border: #2F2F2E;
  --border-strong: #42423F;
  --hairline: #252524;
  --primary: #F0F0ED;
  --primary-hover: #FFFFFF;
  --primary-active: #D9D9D4;
  --primary-fg: #141414;
  --ok: #6DCB93;
  --ok-bg: rgba(109, 203, 147, 0.12);
  --ok-border: rgba(109, 203, 147, 0.30);
  --danger: #F0756C;
  --danger-bg: rgba(240, 117, 108, 0.12);
  --danger-border: rgba(240, 117, 108, 0.32);
  --warn: #E0AA4E;
  --warn-bg: rgba(224, 170, 78, 0.12);
  --warn-border: rgba(224, 170, 78, 0.30);
  --focus-ring: 0 0 0 3px rgba(240, 240, 237, 0.22);
  --tile-id-bg: linear-gradient(180deg, #FAFAF8 0%, #E3E3DF 100%);
  --tile-id-fg: #141414;
  --tile-id-edge: rgba(255, 255, 255, 0.9);
  --tile-app-bg: #232322;
  --tile-app-border: #3A3A38;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 14px 36px -14px rgba(0, 0, 0, 0.75), 0 2px 8px -4px rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.6);
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg, video { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; color: var(--fg); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
a.link {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color var(--dur) var(--ease);
}
a.link:hover { text-decoration-color: var(--fg); }
a.link-quiet { color: var(--fg-2); }
a.link-quiet:hover { color: var(--fg); }
code, kbd, .mono { font-family: var(--font-mono); font-feature-settings: "liga" 0; }
.tnum, .tabular-nums { font-variant-numeric: tabular-nums; }
.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;
}
[hidden] { display: none !important; }
::selection { background: rgba(31, 31, 29, 0.12); }
html.dark ::selection { background: rgba(240, 240, 237, 0.18); }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-control); }

/* Title tracking: negative tracking only for Latin titles; CJK keeps 0. */
.title-xl { font-size: 30px; line-height: 1.2; font-weight: 600; }
.title-lg { font-size: 26px; line-height: 1.25; font-weight: 600; }
.title-md { font-size: 20px; line-height: 1.3; font-weight: 600; }
.title-sm { font-size: 16px; line-height: 1.4; font-weight: 600; }
html[lang="en"] .title-xl,
html[lang="en"] .title-lg { letter-spacing: -0.022em; }
html[lang="en"] .title-md { letter-spacing: -0.012em; }
.text-2 { color: var(--fg-2); }
.text-3 { color: var(--fg-3); }
.text-sm { font-size: 13px; line-height: 1.5; }
.text-xs { font-size: 12px; line-height: 1.5; }
.text-base { font-size: 15px; line-height: 1.55; }
.kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--fg-3);
  text-transform: uppercase;
}

/* 3. Brand ----------------------------------------------------------------- */
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--fg);
  white-space: nowrap;
  user-select: none;
}
.wordmark svg { width: 20px; height: 20px; }
.wordmark:focus-visible { box-shadow: var(--focus-ring); border-radius: 6px; }

/* 4. Controls -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--h-md);
  padding: 0 14px;
  border-radius: var(--r-control);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { background: var(--surface-3); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--fg); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:active { background: var(--primary-active); border-color: var(--primary-active); }
.btn-primary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--primary); }

.btn-secondary { background: var(--surface); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); border-color: transparent; }
.btn-danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }
.btn-danger-solid:hover { filter: brightness(0.94); }

.btn-lg { height: var(--h-lg); padding: 0 18px; font-size: 15px; }
.btn-sm { height: var(--h-sm); padding: 0 10px; font-size: 13px; gap: 6px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-block { width: 100%; }

.btn.is-loading { pointer-events: none; opacity: 0.8; }
.btn.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-stack { display: flex; flex-direction: column; gap: 10px; }
.btn-stack > form { width: 100%; margin: 0; }
.btn-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form { display: inline-flex; margin: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--r-control);
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-2);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.icon-btn-text { width: auto; padding: 0 9px; font-size: 12.5px; font-weight: 500; }

/* Segmented control (theme: light / dark / system) */
.segmented {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 2px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
}
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-3);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.segmented button svg { width: 14px; height: 14px; }
.segmented button:hover { color: var(--fg); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-1); }
.segmented button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Fields & Forms */
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-row-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field-label { font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--fg); }
.field-label .optional { font-weight: 400; color: var(--fg-3); margin-left: 6px; }
.field-hint { font-size: 12px; line-height: 1.5; color: var(--fg-3); }
.field-error { font-size: 12px; line-height: 1.5; color: var(--danger); }

.input, .select, .textarea {
  display: block;
  width: 100%;
  height: var(--h-md);
  padding: 0 12px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  box-shadow: var(--shadow-1);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--fg-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--fg); box-shadow: var(--focus-ring); }
.input[aria-invalid="true"], .input.is-invalid { border-color: var(--danger); }
.input[aria-invalid="true"]:focus, .input.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-bg); }
.input:disabled { background: var(--surface-2); color: var(--fg-3); cursor: not-allowed; }
.input-lg { height: var(--h-lg); padding: 0 14px; font-size: 15px; }
.input-sm { height: var(--h-sm); padding: 0 10px; font-size: 13px; }
.input-mono { font-family: var(--font-mono); font-size: 13px; }
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.55; }
.select {
  padding-right: 34px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B6B66' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
html.dark .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A3A39D' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .input { padding-right: 44px; }
.input-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-3);
  cursor: pointer;
}
.input-toggle svg { width: 16px; height: 16px; }
.input-toggle:hover { color: var(--fg); background: var(--surface-2); }
.input-toggle:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.input-toggle .icon-hide { display: none; }
.input-toggle[aria-pressed="true"] .icon-show { display: none; }
.input-toggle[aria-pressed="true"] .icon-hide { display: inline-flex; }

/* Alerts & Flash Banners */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fg);
}
.alert svg { width: 16px; height: 16px; margin-top: 2px; flex-shrink: 0; }
.alert-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.alert-error { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.alert-ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.alert-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
.portal-flash { margin-bottom: 24px; }

/* Chips, badges, dots, avatars */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-chip);
  background: var(--surface-2);
  color: var(--fg-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.chip-mono { font-family: var(--font-mono); font-size: 11.5px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--fg-2);
  white-space: nowrap;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-3); flex-shrink: 0; }
.dot-ok { background: var(--ok); }
.dot-danger { background: var(--danger); }
.dot-warn { background: var(--warn); }
.badge-ok { color: var(--ok); }
.badge-danger { color: var(--danger); }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-fg);
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
  overflow: hidden;
  user-select: none;
  object-fit: cover;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-md { width: 40px; height: 40px; font-size: 15px; }
.avatar-lg { width: 60px; height: 60px; font-size: 22px; }

/* Account row (continue-as, consent, demo) */
.account-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
}
.account-row-text { min-width: 0; flex: 1; }
.account-row-name {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-row-meta {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--fg-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

/* Permission list (consent) */
.perm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  overflow: hidden;
}
.perm-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  border-top: 1px solid var(--hairline);
}
.perm-item:first-child { border-top: 0; }
.perm-item svg { width: 16px; height: 16px; color: var(--fg-2); flex-shrink: 0; }
.perm-item-text { min-width: 0; flex: 1; }
.perm-item-title { display: block; color: var(--fg); line-height: 1.35; }
.perm-item-sub { display: block; font-size: 12px; color: var(--fg-3); line-height: 1.4; margin-top: 1px; }
.perm-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 5px;
  flex-shrink: 0;
}

/* Key–value definition list */
.kv { margin: 0; border-top: 1px solid var(--hairline); }
.kv > div {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--hairline);
  min-width: 0;
}
.kv dt { font-size: 13.5px; color: var(--fg-2); }
.kv dd {
  margin: 0;
  font-size: 14px;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}
.kv dd .mono { font-size: 13px; }
.kv .kv-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.kv .kv-action { margin-left: auto; }
.kv-compact > div { grid-template-columns: 96px minmax(0, 1fr); padding: 9px 0; gap: 10px; }
.kv-compact dt { font-size: 12.5px; }
.kv-compact dd { font-size: 13px; }

/* Lists (editorial rows) */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--hairline);
  min-width: 0;
}
.list-item:last-child { border-bottom: 0; }
a.list-item { transition: background-color var(--dur) var(--ease); border-radius: 8px; padding: 14px 10px; margin: 0 -10px; }
a.list-item:hover { background: var(--surface-2); }
.list-main { min-width: 0; flex: 1; }
.list-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--fg);
}
.list-sub {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--fg-2);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-meta { font-size: 12.5px; color: var(--fg-3); white-space: nowrap; }
.list-actions { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }

.app-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}
.app-mark img { width: 22px; height: 22px; object-fit: contain; }
.app-mark svg { width: 17px; height: 17px; color: var(--fg-2); }

/* Metrics strip (account overview) */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}
.metric-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 20px 18px 0;
  transition: color var(--dur) var(--ease);
}
.metric-cell + .metric-cell {
  padding-left: 20px;
  border-left: 1px solid var(--hairline);
}
.metric-val { font-size: 24px; font-weight: 600; line-height: 1.15; color: var(--fg); }
.metric-lbl { font-size: 12.5px; color: var(--fg-2); }
.metric-cell:hover .metric-lbl { color: var(--fg); }

/* Table */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  padding: 8px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; text-align: right; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table .td-mono { font-family: var(--font-mono); font-size: 12.5px; }
.table .td-muted { color: var(--fg-2); }
.table .td-wrap { word-break: break-word; }

/* Empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 20px 0;
  color: var(--fg-2);
  font-size: 13.5px;
}
.empty-title { font-size: 14px; font-weight: 500; color: var(--fg); }

/* Dialog (accessible confirmation modal) */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.dialog {
  width: min(420px, 100%);
  padding: 22px 22px 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}
.dialog-title { font-size: 16.5px; font-weight: 600; line-height: 1.35; }
.dialog-body { margin-top: 8px; font-size: 14px; line-height: 1.6; color: var(--fg-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Disclosure (developer details / technical details / inline expanders) */
.disclosure {
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  overflow: hidden;
}
.disclosure > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--fg-2);
  cursor: pointer;
  user-select: none;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary:hover { color: var(--fg); }
.disclosure > summary svg { width: 15px; height: 15px; transition: transform var(--dur) var(--ease); }
.disclosure[open] > summary { color: var(--fg); border-bottom: 1px solid var(--hairline); }
.disclosure[open] > summary svg { transform: rotate(180deg); }
.disclosure-body { padding: 12px 14px 14px; }

/* Code blocks & copyable credential fields (zero wrapper pre-wrap inflation!) */
.code-block {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface-2);
  white-space: normal;
  overflow: hidden;
}
.code-block pre {
  margin: 0;
  padding: 12px 48px 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
  max-height: 280px;
}
.code-block code { font-family: inherit; }
.code-block .code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
}

.copy-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 13px;
}
.copy-field code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-field .btn-sm { flex-shrink: 0; }
.copy-btn.is-copied { color: var(--ok); border-color: var(--ok-border); background: var(--ok-bg); }

/* Passkey conditional block (only rendered when PASSKEY_ENABLED=true) */
.passkey-login { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.passkey-feedback { font-size: 13px; color: var(--danger); text-align: left; }

/* Admin policy & inline actions */
.policy-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
}
.user-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-cell-name { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.admin-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.inline-reset { position: relative; display: inline-block; }
.inline-reset > summary { list-style: none; }
.inline-reset > summary::-webkit-details-marker { display: none; }
.inline-reset-form {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  width: 260px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

/* 5. Auth layout ----------------------------------------------------------- */
.auth-page { min-height: 100dvh; display: flex; flex-direction: column; }
.auth-header { flex-shrink: 0; height: 68px; padding-top: env(safe-area-inset-top, 0px); }
.auth-header-inner {
  width: min(var(--auth-container), 100% - 2 * var(--auth-gutter));
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.util { display: inline-flex; align-items: center; gap: 6px; }
.auth-main {
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px var(--auth-gutter) calc(56px + env(safe-area-inset-bottom, 0px));
}

/* Standard Login: open two-column composition on 1120px grid */
.login-grid {
  width: min(var(--auth-container), 100%);
  display: grid;
  grid-template-columns: minmax(0, 11fr) minmax(0, 9fr);
  column-gap: 96px;
  align-items: center;
}
.login-visual { display: flex; align-items: center; justify-content: center; }
.login-sculpture { width: 320px; height: 320px; position: relative; }
.login-sculpture svg { width: 100%; height: 100%; }
.sculpture-dark { display: none; }
html.dark .sculpture-light { display: none; }
html.dark .sculpture-dark { display: block; }
.login-col { width: min(400px, 100%); }
.auth-title { margin-bottom: 24px; }
.auth-subtitle { margin: -12px 0 22px; font-size: 14px; line-height: 1.55; color: var(--fg-2); }
.auth-aux { margin-top: 20px; font-size: 13.5px; color: var(--fg-2); }
.auth-aux a { color: var(--fg); font-weight: 500; border-bottom: 1px solid transparent; transition: border-color var(--dur) var(--ease); }
.auth-aux a:hover { border-bottom-color: var(--fg); }
.auth-alert { margin-bottom: 16px; }

/* Compact centered auth (OIDC login, continue, consent, register, logout, demo, error) */
.auth-compact { width: min(400px, 100%); text-align: center; }
.auth-compact .form,
.auth-compact .btn-stack,
.auth-compact .perm-list,
.auth-compact .disclosure,
.auth-compact .kv,
.auth-compact .account-row,
.auth-compact .alert { text-align: left; }
.auth-compact .auth-title { margin-bottom: 20px; }
.auth-compact .section-label {
  display: block;
  text-align: left;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg-2);
  margin: 0 0 7px;
}
.auth-block { margin-bottom: 16px; }
.auth-block:last-child { margin-bottom: 0; }
.auth-note { margin-top: 16px; font-size: 12px; line-height: 1.6; color: var(--fg-3); }
.auth-disclosure { margin-top: 24px; }

/* Bridge: Identity ··· App */
.bridge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}
.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: var(--r-tile);
  flex-shrink: 0;
  overflow: hidden;
}
.tile-identity {
  background: var(--tile-id-bg);
  color: var(--tile-id-fg);
  box-shadow: inset 0 1px 0 var(--tile-id-edge), var(--shadow-1);
}
.tile-identity svg { width: 28px; height: 28px; }
.tile-app {
  background: var(--tile-app-bg);
  border: 1px solid var(--tile-app-border);
  color: var(--fg);
  font-size: 24px;
  font-weight: 600;
  box-shadow: var(--shadow-1);
}
.tile-app img { width: 34px; height: 34px; object-fit: contain; }
.tile-app svg { width: 26px; height: 26px; }
.connector {
  position: relative;
  width: 44px;
  height: 0;
  border-top: 1px dashed var(--border-strong);
  margin: 0 8px;
}
.connector.is-connected { border-top-style: solid; border-top-color: var(--ok); }
.tile-status { background: var(--surface); border: 1px solid var(--border); color: var(--fg); }
.tile-status svg { width: 24px; height: 24px; }
.tile-status.is-danger { color: var(--danger); }
.tile-status.is-ok { color: var(--ok); }

/* 6. Account / Admin shell ------------------------------------------------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  border-right: 1px solid var(--hairline);
  background: var(--bg);
}
.sidebar-brand { display: flex; align-items: center; height: 68px; padding: 0 10px; flex-shrink: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 0; overflow-y: auto; }
.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 18px; }
.nav-group-label { padding: 0 10px 6px; font-size: 11.5px; font-weight: 500; letter-spacing: 0.02em; color: var(--fg-3); }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--fg-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link svg { width: 16px; height: 16px; color: var(--fg-3); transition: color var(--dur) var(--ease); }
.nav-link:hover { background: var(--surface-2); color: var(--fg); }
.nav-link:hover svg { color: var(--fg-2); }
.nav-link.is-active { background: var(--surface-3); color: var(--fg); }
.nav-link.is-active svg { color: var(--fg); }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 0 16px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  min-width: 0;
  transition: background-color var(--dur) var(--ease);
}
.user-card:hover { background: var(--surface-2); }
.user-card-text { min-width: 0; flex: 1; }
.user-card-name {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-card-handle {
  font-size: 12px;
  color: var(--fg-2);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-utils { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px; }

.main { min-width: 0; }
.content { width: min(var(--content-w), 100%); margin: 0 auto; padding: 48px 40px 80px; }
.content-wide { width: min(var(--content-w-wide), 100%); }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.page-header-text { min-width: 0; }
.page-title { font-size: 26px; font-weight: 600; line-height: 1.25; }
html[lang="en"] .page-title { letter-spacing: -0.022em; }
.page-desc { margin-top: 6px; font-size: 14px; line-height: 1.55; color: var(--fg-2); }
.page-actions { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }

.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--fg-2);
  margin-bottom: 10px;
}
.breadcrumb svg { width: 14px; height: 14px; color: var(--fg-3); }
.breadcrumb a { display: inline-flex; align-items: center; gap: 4px; }
.breadcrumb a:hover { color: var(--fg); }

.section { padding: 28px 0; border-bottom: 1px solid var(--hairline); }
.section:last-child { border-bottom: 0; }
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.section-title { font-size: 16px; font-weight: 600; line-height: 1.4; }
.section-desc { margin-top: 3px; font-size: 13.5px; line-height: 1.55; color: var(--fg-2); max-width: 560px; }
.section-split { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 40px; }
.section-body { min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.form-narrow { max-width: 460px; }
.form-actions { display: flex; align-items: center; gap: 8px; padding-top: 4px; }

/* Identity header on overview & profile */
.identity-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 4px 0 26px; }
.identity-head-main { display: flex; align-items: center; gap: 18px; min-width: 0; }
.identity-head-name { font-size: 24px; font-weight: 600; line-height: 1.25; }
.identity-head-meta { margin-top: 4px; font-size: 13.5px; color: var(--fg-2); display: flex; flex-wrap: wrap; gap: 4px 10px; }

/* Mobile top bar & drawer */
.mobile-bar { display: none; }
.drawer-backdrop { display: none; }

/* 7. Responsive ------------------------------------------------------------ */
@media (max-width: 1023px) {
  .login-grid { grid-template-columns: 1fr; justify-items: center; row-gap: 32px; width: min(440px, 100%); }
  .login-sculpture { width: 180px; height: 180px; }
  .login-col { width: 100%; }

  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 55;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease);
    border-right: 1px solid var(--border);
    box-shadow: none;
  }
  .shell.is-drawer-open .sidebar { transform: none; box-shadow: var(--shadow-2); }
  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-slow) var(--ease);
    z-index: 54;
  }
  .shell.is-drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
  body.is-drawer-open { overflow: hidden; }
  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--hairline);
  }
  .content { padding: 28px 24px 64px; }
  .section-split { grid-template-columns: 1fr; gap: 16px; }
  .kv > div { grid-template-columns: 1fr; gap: 3px; padding: 11px 0; }
  .kv dt { font-size: 12.5px; }
  .page-header { flex-direction: column; align-items: stretch; gap: 14px; }
  .identity-head { flex-direction: column; align-items: flex-start; }
  .policy-bar { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 639px) {
  :root { --auth-gutter: 24px; }
  .auth-header { height: 60px; }
  .auth-main { align-items: flex-start; padding: 20px var(--auth-gutter) 32px; }
  .login-grid { row-gap: 24px; }
  .login-sculpture { width: 120px; height: 120px; }
  .title-xl { font-size: 26px; }
  .input, .input-lg { font-size: 16px; }
  .auth-compact .bridge { margin-bottom: 18px; }
  .page-title { font-size: 22px; }
  .metrics-strip { grid-template-columns: 1fr; }
  .metric-cell { padding: 14px 0; }
  .metric-cell + .metric-cell { padding-left: 0; border-left: 0; border-top: 1px solid var(--hairline); }
  .field-row-2 { grid-template-columns: 1fr; }
  .list-item { flex-wrap: wrap; gap: 10px 14px; }
  .list-actions { width: 100%; justify-content: flex-start; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { width: 100%; }
  .inline-reset-form { position: static; margin-top: 8px; width: 100%; }
}

@media (max-width: 639px) and (max-height: 620px) {
  .login-visual { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
