:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #f5f5f7;
  --surface-hi: #ececee;
  --surface-sunken: #f5f5f7;
  --border: #d2d2d7;
  --border-soft: #e5e5e7;
  --text: #1d1d1f;
  --text-dim: #6e6e73;
  --text-faint: #86868b;
  --accent: #ea580c;
  --accent-hover: #f97316;
  --accent-ink: #ffffff;
  --green: #1a7f37;
  --green-bg: #e9f9ee;
  --red: #d70015;
  --red-bg: #fff0ef;
  --beta: #ff3b30;
  --amber-bg: color-mix(in srgb, var(--accent), white 88%);
  --radius: 14px;
  --radius-sm: 10px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Dark mode: automatic via prefers-color-scheme unless overridden, or forced
   with data-theme="dark"/"light" on <html> (see supabase-config.js g3ApplyTheme,
   applied pre-paint by an inline snippet at the top of every page's <head>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-hi: #2c2c2e;
    --surface-sunken: #131315;
    --border: #38383a;
    --border-soft: #29292b;
    --text: #f5f5f7;
    --text-dim: #a1a1a6;
    --text-faint: #7c7c80;
    --accent: #ff7a33;
    --accent-hover: #ffa366;
    --accent-ink: #1a1005;
    --green: #32d74b;
    --green-bg: rgba(50, 215, 75, 0.16);
    --red: #ff453a;
    --red-bg: rgba(255, 69, 58, 0.16);
    --beta: #ff453a;
    --amber-bg: color-mix(in srgb, var(--accent), black 78%);
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-hi: #2c2c2e;
  --surface-sunken: #131315;
  --border: #38383a;
  --border-soft: #29292b;
  --text: #f5f5f7;
  --text-dim: #a1a1a6;
  --text-faint: #7c7c80;
  --accent: #ff7a33;
  --accent-hover: #ffa366;
  --accent-ink: #1a1005;
  --green: #32d74b;
  --green-bg: rgba(50, 215, 75, 0.16);
  --red: #ff453a;
  --red-bg: rgba(255, 69, 58, 0.16);
  --beta: #ff453a;
  --amber-bg: color-mix(in srgb, var(--accent), black 78%);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.47;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}

/* ---------- Small animations ---------- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(-4px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

.page-inner { animation: fadeInUp .4s ease both; }
.card, .topbar, input, textarea, select, .btn, .badge { transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .15s ease; }

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hi) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton-card { height: 96px; margin-bottom: 12px; }

.fade-item { animation: fadeInUp .35s ease both; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---------- Buttons ---------- */
button { font-family: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 980px;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn.large { padding: 15px 30px; font-size: 16px; }

.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--accent), transparent 45%); }
.btn.primary:active { transform: scale(0.98); box-shadow: none; }
.btn.primary:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn.secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface); }

.btn.link { background: none; border: none; color: var(--text-dim); font-weight: 400; padding: 8px; }
.btn.link:hover { color: var(--text); }

/* ---------- Top bar (shared across pages, rendered by topbar.js) ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 64px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand .dot { color: var(--accent); }
.brand-logo { width: 24px; height: 24px; border-radius: 6px; display: block; }

.theme-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); cursor: pointer; flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-hi); }
.theme-toggle svg { display: block; }

.beta-tag {
  font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--beta); border: 1px solid var(--beta); border-radius: 5px; padding: 1px 6px;
}

.crumb { font-family: var(--mono); font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.crumb .sep { color: var(--text-faint); }
.crumb .current { color: var(--text); }
.crumb a { color: var(--text-dim); }
.crumb a:hover { color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: 12px; position: relative; }
.quota-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px; color: var(--text-dim);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-hi); border: 1.5px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--accent);
  cursor: pointer;
}

.account-menu {
  position: absolute; top: 46px; right: 0; width: 290px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 20px 45px -12px rgba(0,0,0,0.18);
  overflow: hidden;
  animation: popIn .16s ease both;
  transform-origin: top right;
}
.account-menu-header { padding: 18px 20px; border-bottom: 1px solid var(--border-soft); }
.account-menu-email { font-size: 14px; font-weight: 600; word-break: break-all; }
.account-menu-plan { font-family: var(--mono); font-size: 11px; color: var(--accent); margin-top: 4px; letter-spacing: 0.04em; }
.account-menu-stat { padding: 14px 20px 18px; display: flex; flex-direction: column; gap: 10px; }
.account-menu-stat-row { display: flex; justify-content: space-between; font-size: 13px; }
.account-menu-stat-row .k { color: var(--text-dim); }
.account-menu-stat-row .v { font-family: var(--mono); font-weight: 600; }
.bar-track { height: 5px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.account-menu-divider { height: 1px; background: var(--border-soft); }
.account-menu-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 20px;
  font-size: 14px; color: var(--text); cursor: pointer; background: none; border: none; width: 100%; text-align: left;
}
.account-menu-row:hover { background: var(--surface); }
.account-menu-row svg { color: var(--text-dim); flex-shrink: 0; }
.account-menu-row.danger { color: var(--text-dim); }
.quota-warning-row { padding: 10px 20px 16px; font-size: 12px; color: var(--red); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  font-family: var(--mono); font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.badge.b-pending { background: var(--amber-bg); color: var(--accent); }
.badge.b-review { background: var(--accent); color: var(--accent-ink); }
.badge.b-open { background: var(--green-bg); color: var(--green); }
.badge.b-merged { background: var(--green-bg); color: var(--green); }
.badge.b-closed { background: var(--surface-hi); color: var(--text-dim); }
.badge.b-rejected { background: var(--surface-hi); color: var(--text-dim); }
.badge.b-error { background: var(--red-bg); color: var(--red); }

.repo-avatar { width: 34px; height: 34px; border-radius: 8px; background: var(--surface-hi); flex-shrink: 0; }
.repo-avatar.sm { width: 20px; height: 20px; border-radius: 5px; }

.dot-pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .4; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }

/* ---------- Cards / layout ---------- */
.card { background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius); }
.page { flex: 1; width: 100%; }
.page-inner { max-width: 900px; margin: 0 auto; width: 100%; padding: 48px 32px 90px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); margin: 20px 0 8px; }
input[type="text"], input[type="url"], input[type="email"], input[type="password"], textarea {
  width: 100%; padding: 13px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 80%);
}
textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
.field-hint { color: var(--text-faint); font-size: 12.5px; margin-top: 6px; }

/* ---------- Messages ---------- */
.msg { margin-top: 16px; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; background: var(--surface); border-left: 3px solid var(--accent); }
.msg.error { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.msg.ok { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.msg.hidden { display: none; }
.hidden { display: none !important; }

/* ---------- Misc ---------- */
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-state { text-align: center; padding: 90px 24px; }
.hint { color: var(--text-dim); font-size: 14px; text-align: center; }

.site-footer { border-top: 1px solid var(--border-soft); color: var(--text-faint); font-size: 12.5px; text-align: center; padding: 26px 24px; }

/* ---------- Provider picker (new.html) ---------- */
.provider-picker { display: flex; flex-direction: column; gap: 8px; }
.provider-option {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 15px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  cursor: pointer; background: var(--bg);
}
.provider-option:hover { border-color: var(--text-faint); }
.provider-option.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent), transparent 92%); }
.provider-option-left { display: flex; align-items: center; gap: 10px; font-size: 14.5px; font-weight: 500; }
.provider-option-radio {
  width: 17px; height: 17px; border-radius: 50%; border: 1.5px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.provider-option.selected .provider-option-radio { border-color: var(--accent); }
.provider-option.selected .provider-option-radio::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

/* ---------- Settings page ---------- */
.settings-section { padding: 28px 30px; margin-bottom: 20px; }
.settings-section h2 { font-size: 16.5px; font-weight: 600; margin: 0 0 4px; }
.settings-section .settings-desc { color: var(--text-dim); font-size: 13.5px; margin: 0 0 22px; line-height: 1.5; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 14px 0; border-top: 1px solid var(--border-soft);
}
.settings-row:first-of-type { border-top: none; padding-top: 0; }
.settings-row-label { font-size: 14px; font-weight: 500; }
.settings-row-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.settings-row-value { font-family: var(--mono); font-size: 13px; color: var(--text-dim); text-align: right; }

.theme-picker { display: flex; gap: 8px; }
.theme-picker button {
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text-dim); font-size: 13px; cursor: pointer; font-family: inherit;
}
.theme-picker button.active { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent), transparent 92%); }

.gh-connect-card { display: flex; align-items: center; gap: 14px; }
.gh-connect-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-hi); }

.wallet-packages { display: flex; flex-direction: column; gap: 10px; }
.wallet-package {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
