/* =====================================================================
   ChainLayerTwo — user panel + activation page
   Design direction (spec §5, binding): dark ground, chain-gold accent,
   system-ui type. Shared between panel.html and activate.html.
   ===================================================================== */

:root {
  --bg: #0b0e14;
  --surface: #131722;
  --surface-2: #1a2030;
  --surface-3: #212940;
  --text: #e6e6e6;
  --muted: #9aa3b5;
  --faint: #6b7386;
  --border: #232a3a;
  --border-2: #2f3850;

  --accent: #d4a017;
  --accent-hi: #f0c04a;
  --accent-deep: #a97c0f;
  --accent-ink: #14100a;
  --accent-wash: rgba(212, 160, 23, 0.12);
  --accent-line: rgba(212, 160, 23, 0.36);

  --success: #3fb950;
  --success-wash: rgba(63, 185, 80, 0.12);
  --success-line: rgba(63, 185, 80, 0.38);

  --danger: #f85149;
  --danger-wash: rgba(248, 81, 73, 0.12);
  --danger-line: rgba(248, 81, 73, 0.38);

  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.85);
  --shadow-sm: 0 10px 26px -18px rgba(0, 0, 0, 0.75);

  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 780px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image: radial-gradient(120% 60% at 50% -10%, var(--accent-wash), transparent 55%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }
a { color: var(--accent); }
a:hover { color: var(--accent-hi); }
p { margin: 0; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 6px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ---- header ---- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; color: var(--text); }
.brand:hover { color: var(--text); }
.brand .mark { width: 26px; height: 26px; flex: none; color: var(--accent); }
.brand-sub { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.who-email { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }

/* ---- badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase;
  border: 1px solid var(--border-2); border-radius: 20px; padding: 3px 10px; color: var(--muted);
  white-space: nowrap;
}
.badge-role-admin { color: var(--accent); border-color: var(--accent-line); background: var(--accent-wash); }
.badge-role-privileged { color: var(--accent-hi); border-color: var(--accent-line); background: var(--accent-wash); }
.badge-role-user { color: var(--muted); }
.badge-status-approved { color: var(--success); border-color: var(--success-line); background: var(--success-wash); }
.badge-status-pending { color: var(--accent); border-color: var(--accent-line); background: var(--accent-wash); }
.badge-status-disabled { color: var(--danger); border-color: var(--danger-line); background: var(--danger-wash); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--sans); font-size: 0.9rem; font-weight: 600;
  cursor: pointer; border-radius: var(--radius-sm);
  padding: 10px 18px; border: 1px solid transparent;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hi); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger-line); }
.btn-danger:hover { background: var(--danger-wash); }
.btn-success { background: var(--success); color: #0a1a0c; }
.btn-success:hover { filter: brightness(1.08); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }

/* ---- main layout ---- */
.panel-main { padding: 40px 0 80px; display: flex; flex-direction: column; gap: 22px; }

/* ---- status banner (aria-live) ---- */
.status-banner {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--text);
}
.status-banner.is-error { border-color: var(--danger-line); background: var(--danger-wash); color: var(--text); }
.status-banner.is-success { border-color: var(--success-line); background: var(--success-wash); }

/* ---- cards ---- */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 26px;
}
.card + .card { margin-top: 0; }
.card-head { margin-bottom: 16px; }
.card-head h2 { font-size: 1.05rem; }
.card-head p { color: var(--muted); font-size: 0.88rem; margin-top: 6px; }

/* ---- auth card / tabs ---- */
.auth-card {
  max-width: 420px; margin: 40px auto 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  overflow: hidden;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; padding: 16px; background: transparent; border: 0; cursor: pointer;
  color: var(--muted); font-family: var(--sans); font-weight: 600; font-size: 0.92rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-form { padding: 26px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.field input {
  font: inherit; font-size: 0.94rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.field input:focus { border-color: var(--accent); }
.field-hint { font-size: 0.76rem; color: var(--faint); }
.form-error {
  font-size: 0.84rem; color: var(--danger); min-height: 1em;
}
.form-note { font-size: 0.8rem; color: var(--faint); text-align: center; margin-top: 4px; }

/* ---- identity strip ---- */
.identity-strip {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 18px 22px; box-shadow: var(--shadow-sm);
}
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: linear-gradient(150deg, var(--accent-hi), var(--accent-deep));
  color: var(--accent-ink); font-weight: 700; font-family: var(--mono);
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.identity-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.identity-email { font-weight: 600; overflow-wrap: anywhere; }
.identity-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.identity-strip .btn { margin-left: auto; }

/* ---- queue card (pending, warm not alarming) ---- */
.queue-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--accent-wash), var(--surface) 60%);
  box-shadow: var(--shadow-sm);
  padding: 30px 26px;
}
.queue-card .loader-overlay.is-ambient {
  top: -10px; right: -10px; left: auto; bottom: auto; inset: auto;
  width: 180px; height: 140px;
}
.queue-content { position: relative; max-width: 52ch; }
.queue-content h2 { font-size: 1.15rem; margin-bottom: 10px; }
.queue-content p { color: var(--text); font-size: 0.95rem; }
.queue-content p + p { margin-top: 10px; }
.queue-content strong { color: var(--accent-hi); }
.queue-content code { background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }

/* ---- tables ---- */
.table-scroll { overflow-x: auto; position: relative; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
  text-align: left; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint); padding: 8px 10px; border-bottom: 1px solid var(--border-2);
  white-space: nowrap;
}
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .mono { font-family: var(--mono); font-size: 0.85em; color: var(--muted); }
.empty-note { color: var(--faint); font-size: 0.88rem; padding: 6px 2px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.role-select {
  font: inherit; font-size: 0.82rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: 7px; padding: 5px 8px;
}

.admin-block + .admin-block { margin-top: 26px; padding-top: 26px; border-top: 1px dashed var(--border-2); }

/* ---- activate.html specific ---- */
.activate-card {
  max-width: 440px; margin: 48px auto 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  padding: 30px 28px;
  text-align: center;
}
.activate-card h1 { font-size: 1.2rem; margin-bottom: 8px; }
.activate-card .lead { color: var(--muted); font-size: 0.92rem; margin-bottom: 22px; }
.code-field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; text-align: left; }
.code-field label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.code-input {
  font-family: var(--mono); font-size: 1.7rem; letter-spacing: 0.14em; text-align: center;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  padding: 14px 10px; text-transform: uppercase;
}
.code-input:focus { border-color: var(--accent); }
.activate-actions { display: flex; gap: 12px; }
.activate-actions .btn { flex: 1; }
.activate-note { margin-top: 18px; font-size: 0.8rem; color: var(--faint); }
.activate-note a { color: var(--accent); }

.result-card { text-align: center; }
.result-icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.result-icon.is-success { background: var(--success-wash); color: var(--success); border: 1px solid var(--success-line); }
.result-icon.is-danger { background: var(--danger-wash); color: var(--danger); border: 1px solid var(--danger-line); }
.result-card h1 { font-size: 1.2rem; margin-bottom: 10px; }
.result-card p { color: var(--muted); font-size: 0.94rem; }
.signin-prompt { text-align: center; }
.signin-prompt p { color: var(--muted); font-size: 0.94rem; margin-bottom: 18px; }

footer.mini-foot {
  text-align: center; color: var(--faint); font-size: 0.78rem;
  padding: 20px 0 40px; font-family: var(--mono);
}

@media (max-width: 520px) {
  .auth-card, .activate-card { margin-top: 20px; }
  .card { padding: 20px; }
  .identity-strip .btn { margin-left: 0; width: 100%; }
}

/* ---- plan / tier card ---- */
.tier-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin: 0 0 12px;
}
.tier-grid > div {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; min-width: 0;
}
.tier-grid dt { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.tier-grid dd { margin: 4px 0 0; font-family: var(--mono); font-size: 1rem; color: var(--text); overflow-wrap: anywhere; }

/* ---- gateway keys ---- */
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1 1 220px; min-width: 0; }
.inline-form .btn { flex: none; }
#gwkeys-notice { margin-bottom: 14px; }
#gwkey-error { margin-top: 8px; }
.secret-box {
  margin: 6px 0 18px; padding: 16px;
  border: 1px solid var(--accent-line); border-radius: var(--radius-sm);
  background: var(--accent-wash);
  display: flex; flex-direction: column; gap: 10px;
}
.secret-warn { font-size: 0.9rem; }
.secret-warn strong { color: var(--accent-hi); }
.panel-main > *, .secret-box > *, .card, .table-scroll { min-width: 0; max-width: 100%; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.secret-value {
  flex: 1; min-width: 0;
  font-family: var(--mono); font-size: 0.85rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 9px 10px;
}
.snippet-label { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin-top: 4px; }
.snippet { position: relative; }
.snippet pre {
  margin: 0; padding: 12px 12px 12px 12px; padding-right: 72px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.6; color: var(--text);
  overflow-x: auto; white-space: pre;
}
.snippet .btn { position: absolute; top: 6px; right: 6px; }
.key-prefix { font-family: var(--mono); font-size: 0.85em; color: var(--muted); white-space: nowrap; }

@media (max-width: 520px) {
  .snippet { display: flex; flex-direction: column; gap: 6px; }
  .snippet .btn { position: static; align-self: flex-end; order: -1; }
  .snippet pre { padding-right: 12px; }
}

@media (max-width: 420px) {
  .wrap { padding: 0 14px; }
  .topbar-inner { gap: 8px; }
  .brand-sub, .who-email { display: none; }
  .inline-form .btn { width: 100%; }
  .tier-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 16px; }
}
