:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafd;
  --border: #dfe6f2;
  --ink: #132238;
  --ink-muted: #5a6c87;
  --brand: #0f4c81;
  --brand-hover: #0b3c68;
  --accent: #0ea5e9;
  --accent-soft: #e0f2fe;
  --ok: #0f766e;
  --ok-soft: #ccfbf1;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 12px 32px rgba(15, 76, 129, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); min-height: 100%; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; }

.boot-loading {
  min-height: 100vh; display: grid; place-items: center;
  color: var(--ink-muted); font-size: 14px;
}

/* Header & Navigation */
.topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 24px;
  min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px; flex: none; display: block;
  box-shadow: 0 4px 12px rgba(15, 76, 129, 0.16);
}
.brand-title {
  font-size: 16px; font-weight: 700; color: var(--brand); letter-spacing: -0.01em;
  white-space: nowrap; flex-shrink: 0; word-break: keep-all;
}
.brand-sub { font-size: 12px; color: var(--ink-muted); margin-left: 4px; white-space: nowrap; }
.nav-tabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nav-tab {
  border: 0; background: transparent; color: var(--ink-muted);
  padding: 8px 14px; border-radius: 9px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  white-space: nowrap; flex-shrink: 0; word-break: keep-all;
  transition: background .15s, color .15s;
}
.nav-tab:hover { background: var(--surface-soft); color: var(--ink); }
.nav-tab.active { background: var(--accent-soft); color: var(--brand); }
.user-cluster { display: flex; align-items: center; gap: 10px; }

/* Avatar (never stretch) */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none; flex-shrink: 0; aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; font-size: 13px; font-weight: 700;
  display: inline-grid; place-items: center; overflow: hidden; user-select: none;
}
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.lg { width: 68px; height: 68px; font-size: 24px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.page-wrap { max-width: 1240px; margin: 0 auto; padding: 28px 24px 72px; }

/* Auth / OAuth Center Screen */
.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at 20% 10%, #dceeff 0%, var(--bg) 55%);
}
.auth-card {
  width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 26px 24px; box-shadow: var(--shadow);
  display: grid; gap: 16px;
}
.auth-head { display: flex; align-items: center; gap: 12px; }
.auth-logo-btn {
  border: 0; padding: 0; background: transparent; cursor: pointer; border-radius: 11px;
  display: inline-flex; flex: none; user-select: none;
}
.auth-title { margin: 0; font-size: 20px; font-weight: 700; color: var(--ink); }
.auth-sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-muted); line-height: 1.5; }

.target-app-banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface-soft); border: 1px solid var(--border); border-radius: 12px;
}
.app-icon-box {
  width: 40px; height: 40px; border-radius: 10px; flex: none; overflow: hidden;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 16px;
  display: grid; place-items: center;
}
.app-icon-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.target-app-meta { min-width: 0; flex: 1; }
.target-app-meta strong { display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.target-app-meta small { display: block; font-size: 12px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.account-chip {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: 12px; border: 1px solid #bfdbfe;
  background: #f0f7ff; cursor: pointer; transition: border-color .15s, background .15s;
}
.account-chip:hover { background: #e0f2fe; border-color: var(--accent); }
.account-chip-text { flex: 1; min-width: 0; }
.account-chip-title { font-size: 14px; font-weight: 700; color: var(--brand); }
.account-chip-sub { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.account-chip-arrow { color: var(--brand); font-size: 16px; font-weight: 700; flex: none; }

/* Forms & Buttons */
.form-stack { display: grid; gap: 14px; }
.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px;
}
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field-span-2 { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.4; }
.field-hint { font-size: 12px; color: var(--ink-muted); line-height: 1.45; margin-top: 2px; }

.input, .textarea, .select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff; color: var(--ink);
  font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.14);
}
.input[readonly] {
  background: var(--surface-soft); color: var(--ink-muted);
}
.textarea { min-height: 82px; resize: vertical; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px; color: var(--ink-muted); padding: 2px 0; cursor: pointer;
  line-height: 1.45;
}
.switch-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; flex-shrink: 0; }
.switch-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-soft); font-size: 13px; color: var(--ink); cursor: pointer;
  line-height: 1.45;
}
.switch-card span { min-width: 0; }
.switch-card input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; flex-shrink: 0; }

.check-pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-soft);
  font-size: 12.5px; font-weight: 500; color: var(--ink); cursor: pointer;
  white-space: nowrap; flex-shrink: 0; word-break: keep-all;
  transition: border-color .15s, background .15s;
}
.check-pill:hover { border-color: var(--accent); background: #f0f9ff; }
.check-pill input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--brand); margin: 0; cursor: pointer; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; white-space: nowrap; flex-shrink: 0; word-break: keep-all;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-secondary { background: var(--surface-soft); color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #edf2f9; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.link-btn {
  border: 0; background: transparent; padding: 4px 0; color: var(--brand);
  font-size: 13px; font-weight: 600; cursor: pointer; text-align: center;
  white-space: nowrap;
}

.alert {
  padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5;
}
.alert-err { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #99f6e4; }
.alert-info { background: var(--accent-soft); color: var(--brand); border: 1px solid #bae6fd; }

/* Cards, Toolbars & Grids */
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 21px; font-weight: 700; }
.section-sub { margin: 5px 0 0; font-size: 13.5px; color: var(--ink-muted); line-height: 1.55; }

.toolbar-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar-meta { min-width: 0; }
.toolbar-title { font-size: 15.5px; font-weight: 700; color: var(--ink); }
.toolbar-sub { font-size: 12.5px; color: var(--ink-muted); margin-top: 3px; line-height: 1.5; }

.grid-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: 0 4px 16px rgba(15, 76, 129, 0.04);
}
.site-card { display: grid; gap: 14px; align-content: space-between; }
.site-card-top { display: flex; align-items: center; gap: 12px; min-width: 0; }

/* Badges & Interactive Column Pills (never wrap awkwardly) */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.3;
  white-space: nowrap; flex-shrink: 0; word-break: keep-all;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-muted { background: #e8eef7; color: var(--ink-muted); }
.badge-brand { background: var(--accent-soft); color: var(--brand); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.pill-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.3;
  white-space: nowrap; flex-shrink: 0; word-break: keep-all;
  border: 1px solid transparent; cursor: pointer;
  transition: transform .12s, box-shadow .15s, background .15s, border-color .15s;
}
.pill-btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(15, 76, 129, 0.12);
}
.pill-btn:disabled { cursor: default; opacity: 0.82; }

.pill-brand { background: #e0f2fe; color: #0b4a7a; border-color: #bae6fd; }
.pill-brand:not(:disabled):hover { background: #bae6fd; border-color: #7dd3fc; }
.pill-ok { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.pill-ok:not(:disabled):hover { background: #a7f3d0; border-color: #6ee7b7; }
.pill-warn { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.pill-warn:not(:disabled):hover { background: #fde68a; border-color: #fcd34d; }
.pill-danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.pill-danger:not(:disabled):hover { background: #fecaca; border-color: #fca5a5; }
.pill-muted { background: #f1f5f9; color: #475569; border-color: #dbe4ef; }
.pill-muted:not(:disabled):hover { background: #e2e8f0; border-color: #cbd5e1; color: var(--ink); }

.pill-dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0;
}
.pill-hint { font-size: 10.5px; opacity: 0.68; }

.tag-chip {
  display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 600; line-height: 1.3;
  background: #eef3fa; color: var(--ink-muted); border: 1px solid var(--border);
  white-space: nowrap; flex-shrink: 0; word-break: keep-all;
}

.mono-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px;
  background: #f1f5f9; color: var(--ink); border: 1px solid var(--border);
  white-space: nowrap; flex-shrink: 0;
}
button.mono-pill { cursor: pointer; }
button.mono-pill:hover { background: #e2e8f0; border-color: #cbd5e1; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.stat-num { font-size: 26px; font-weight: 700; color: var(--brand); }
.stat-label { font-size: 13px; color: var(--ink-muted); margin-top: 4px; }

/* Tables */
.card.table-card, .card.table-wrap { padding: 0; overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th, table.data-table td {
  text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--border);
  vertical-align: middle; line-height: 1.5;
}
table.data-table th {
  white-space: nowrap; padding: 12px 16px; font-size: 12.5px;
  color: var(--ink-muted); font-weight: 600; background: var(--surface-soft);
}
table.data-table tbody tr:last-child td { border-bottom: 0; }
table.data-table tbody tr:hover { background: #f8fbff; }

.cell-user { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.cell-user-title { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.cell-user-name { font-weight: 700; color: var(--ink); white-space: nowrap; }
.cell-user-sub {
  display: flex; align-items: center; gap: 8px; margin-top: 3px;
  font-size: 12px; color: var(--ink-muted); flex-wrap: nowrap;
}
.inline-action-link {
  border: 0; background: transparent; padding: 0 2px; color: var(--brand);
  font-size: 11.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.inline-action-link:hover { text-decoration: underline; }
.grant-list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 220px; }

.subtabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.subtab {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-muted);
  padding: 8px 15px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
  white-space: nowrap; flex-shrink: 0; word-break: keep-all;
  transition: background .15s, border-color .15s, color .15s;
}
.subtab:hover { border-color: #bfd0e6; color: var(--ink); }
.subtab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.list-stack { display: grid; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

.app-row-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.app-row-meta { display: flex; align-items: center; gap: 12px; min-width: 260px; flex: 1; }
.app-row-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; font-size: 15px; }
.app-row-sub {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--ink-muted); margin-top: 4px;
}
.app-row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.info-meta-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  font-size: 12.5px; color: var(--ink-muted); margin: 6px 0;
}
.info-meta-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.code-box {
  background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  overflow-x: auto; line-height: 1.6;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.48);
  display: grid; place-items: center; padding: 18px; z-index: 60;
}
.modal-box {
  width: min(460px, 100%); background: var(--surface); border-radius: 16px;
  padding: 24px 26px; box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25); display: grid; gap: 16px;
  max-height: 90vh; overflow-y: auto;
}
.modal-box.modal-md { width: min(540px, 100%); }
.modal-box.modal-lg { width: min(660px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; color: var(--ink); }
.modal-close-btn {
  border: 1px solid var(--border); background: var(--surface-soft); color: var(--ink-muted);
  padding: 5px 11px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
}
.modal-close-btn:hover { background: #edf2f9; color: var(--ink); }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding-top: 8px; border-top: 1px solid var(--border);
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 80; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* Collapsible Project Accordions */
.proj-accordion {
  padding: 0;
  overflow: hidden;
}
.proj-acc-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--surface-soft);
  border-bottom: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.proj-acc-head:hover {
  background: #eef4fc;
}
.proj-accordion.is-open .proj-acc-head {
  border-bottom-color: var(--border);
}
.proj-acc-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  flex-wrap: wrap;
}
.proj-chevron {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  background: #e2eaf6;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.proj-acc-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}
.proj-acc-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.proj-acc-body {
  padding: 0;
}
.proj-acc-empty {
  padding: 18px 20px;
  font-size: 13px;
  color: var(--ink-muted);
}

.subapp-perm-list {
  display: grid;
  gap: 6px;
  min-width: 270px;
}
.subapp-perm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fbfdff;
}
.subapp-perm-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.subapp-perm-win {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .topbar-inner { padding: 10px 16px; }
  .page-wrap { padding: 20px 16px 52px; }
  .brand-sub { display: none; }
}

@media (max-width: 620px) {
  .form-grid { grid-template-columns: 1fr; }
}
