: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: 1120px; margin: 0 auto; padding: 0 20px;
  min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.brand-group { display: flex; align-items: center; gap: 10px; }
.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; }
.brand-sub { font-size: 12px; color: var(--ink-muted); margin-left: 4px; }
.nav-tabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nav-tab {
  border: 0; background: transparent; color: var(--ink-muted);
  padding: 8px 13px; border-radius: 9px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  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: 26px; height: 26px; font-size: 11px; }
.avatar.lg { width: 68px; height: 68px; font-size: 24px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.page-wrap { max-width: 1120px; margin: 0 auto; padding: 26px 20px 64px; }

/* 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: 12px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink); }
.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);
}
.textarea { min-height: 82px; resize: vertical; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; color: var(--ink-muted); padding: 2px 0; cursor: pointer;
}
.switch-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); 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; 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 11px; 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;
}

.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 & Grids */
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.section-sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-muted); }

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

.badge {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
}
.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); }

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

.table-wrap { 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: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
table.data-table th { font-size: 12px; color: var(--ink-muted); font-weight: 600; background: var(--surface-soft); }

.subtabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.subtab {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-muted);
  padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.subtab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

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

.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: 22px 24px; box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25); display: grid; gap: 14px;
  max-height: 90vh; overflow-y: auto;
}

.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);
}

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