@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Geist:wght@400;500;600&display=swap');

:root {
  --bg: #0E0E0E;
  --surface: #1A1A1A;
  --surface-alt: #202020;
  --text: #E5E1DB;
  --text-2: #8A8579;
  --text-3: #5A5650;
  --accent: #F5C600;
  --accent-h: #FFD93D;
  --accent-dim: rgba(245,198,0,0.12);
  --success: #6B9E78;
  --error: #D25847;
  --warning: #E8A838;
  --border: #2A2724;
  --subtle: #141310;
  --overlay: rgba(0,0,0,0.7);
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --sidebar: 280px;
  --tf: .15s ease;
  --tb: .25s ease;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; }
body {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; transition: color var(--tf); }
a:hover { color: var(--accent-h); }
button { font-family: inherit; cursor: pointer; border: none; background: none; font-size: inherit; color: inherit; }
input, textarea, select { font-family: inherit; font-size: 15px; color: var(--text); }
img { max-width: 100%; display: block; }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── LAYOUT ── */
.app { display: flex; min-height: 100vh; }

/* ── PIKACHU BG ── */
#pika-bg {
  position: fixed;
  bottom: -30px;
  right: -60px;
  width: 520px;
  pointer-events: none;
  opacity: 0.035;
  z-index: 0;
  filter: grayscale(0.3) brightness(1.2);
  transform: scaleX(-1);
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
}
.sidebar-top {
  padding: 24px 22px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Instrument Serif', Georgia, serif;
  font-style: italic;
  font-size: 1.65rem;
  color: var(--text);
  letter-spacing: -.02em;
  text-decoration: none;
}
.logo-bolt { color: var(--accent); font-style: normal; }
.logo-bar {
  display: block;
  width: 28px; height: 2px;
  background: var(--accent);
  border-radius: 1px;
  margin-top: 5px;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-section {
  padding: 14px 22px 6px;
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 22px;
  font-size: .92rem;
  color: var(--text-2);
  transition: background var(--tf), color var(--tf);
  min-height: 40px;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
}
.nav-item:hover { background: var(--subtle); color: var(--text); }
.nav-item.active { color: var(--accent); background: var(--accent-dim); }
.nav-item svg { flex-shrink: 0; opacity: .8; }
.nav-item.active svg { opacity: 1; }
.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 14px 22px;
  flex-shrink: 0;
}
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}
.user-name { font-size: .88rem; color: var(--text-2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout {
  font-size: .8rem;
  color: var(--text-3);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: color var(--tf), background var(--tf);
  min-height: auto;
}
.btn-logout:hover { color: var(--error); background: var(--subtle); }

/* ── CONTENT ── */
.content {
  margin-left: var(--sidebar);
  flex: 1;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.view { padding: 44px 48px; max-width: 960px; display: none; }
.view.active { display: block; }
.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 16px;
  flex-wrap: wrap;
}
.view-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 2.2rem;
  color: var(--text);
  line-height: 1.1;
}
.view-subtitle { font-size: .9rem; color: var(--text-2); margin-top: 4px; }

/* ── STATS GRID ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 36px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px;
}
.stat-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-value { font-size: 1.9rem; font-weight: 600; color: var(--text); line-height: 1; }
.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.error { color: var(--error); }

/* ── SITE CARDS ── */
.sites-list { display: flex; flex-direction: column; gap: 14px; }
.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 20px 24px;
  transition: border-color var(--tf), box-shadow var(--tb);
}
.site-card:hover { border-color: rgba(245,198,0,0.3); }
.site-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}
.site-name {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 1.25rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge-active {
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(107,158,120,0.15);
  color: var(--success);
  border: 1px solid rgba(107,158,120,0.3);
  letter-spacing: .03em;
}
.badge-inactive {
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(210,88,71,0.12);
  color: var(--error);
  border: 1px solid rgba(210,88,71,0.3);
  letter-spacing: .03em;
}
.site-actions { display: flex; gap: 6px; }
.btn-icon {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px;
  font-size: .8rem;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: all var(--tf);
  min-height: auto;
}
.btn-icon:hover { color: var(--text); border-color: var(--text-3); }
.btn-icon.danger:hover { color: var(--error); border-color: var(--error); }

.key-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.key-row { display: flex; align-items: center; gap: 10px; }
.key-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .05em;
  min-width: 80px;
}
.key-val {
  font-family: 'Geist Mono', 'Courier New', monospace;
  font-size: .8rem;
  color: var(--text-2);
  background: var(--bg);
  padding: 5px 10px;
  border-radius: var(--r-sm);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.key-val.secret { letter-spacing: .05em; filter: blur(4px); transition: filter var(--tf); cursor: pointer; }
.key-val.secret:hover { filter: none; }
.btn-copy {
  display: flex; align-items: center; gap: 4px;
  font-size: .76rem;
  color: var(--text-3);
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  min-height: auto;
  transition: all var(--tf);
  flex-shrink: 0;
}
.btn-copy:hover { color: var(--accent); border-color: var(--accent); }
.btn-copy.copied { color: var(--success); border-color: var(--success); }

.domain-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.domain-tag {
  font-size: .76rem;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 20px;
  display: flex; align-items: center; gap: 4px;
}

.site-footer {
  display: flex;
  gap: 20px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.site-stat { font-size: .8rem; color: var(--text-3); display: flex; align-items: center; gap: 5px; }
.site-stat strong { color: var(--text-2); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--r-sm);
  font-size: .88rem;
  font-weight: 500;
  transition: all var(--tf);
  min-height: auto;
  cursor: pointer;
  border: none;
}
.btn-primary { background: var(--accent); color: #0E0E0E; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--text-3); color: var(--text); }
.btn-danger { background: transparent; color: var(--error); border: 1px solid rgba(210,88,71,0.3); }
.btn-danger:hover { background: rgba(210,88,71,0.08); }

/* ── MODAL ── */
.modal-bg {
  display: none;
  position: fixed; inset: 0;
  background: var(--overlay);
  z-index: 300;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 26px 28px;
  width: 100%; max-width: 460px;
  max-height: 90vh; overflow-y: auto;
}
.modal-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 1.5rem;
  color: var(--text);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }

/* ── FORM ── */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: .74rem; font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  outline: none;
  transition: border-color var(--tf);
  resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field small { display: block; font-size: .76rem; color: var(--text-3); margin-top: 4px; }
.field-error { font-size: .8rem; color: var(--error); margin-top: 4px; display: none; }

/* ── AUTH PAGE ── */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-hero { text-align: center; margin-bottom: 32px; }
.wordmark {
  font-family: 'Instrument Serif', Georgia, serif;
  font-style: italic;
  font-size: clamp(3rem, 12vw, 5.5rem);
  color: var(--text);
  letter-spacing: -.03em;
  line-height: 1;
}
.wordmark .bolt { color: var(--accent); font-style: normal; }
.auth-sub {
  font-family: 'Instrument Serif', Georgia, serif;
  font-style: italic;
  font-size: 1.05rem;
  color: var(--text-3);
  margin-top: 6px;
}
.auth-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 8px 24px 26px;
}
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1; padding: 12px;
  font-size: .88rem; font-weight: 500;
  color: var(--text-3);
  border-bottom: 2px solid transparent;
  transition: color var(--tf), border-color var(--tf);
  text-align: center; min-height: auto;
}
.tab-btn:hover { color: var(--text-2); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.btn-auth {
  width: 100%; padding: 11px;
  background: var(--accent); color: #0E0E0E;
  border-radius: var(--r-sm);
  font-weight: 600; font-size: .95rem;
  margin-top: 6px;
  transition: all var(--tf);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-auth:hover:not(:disabled) { background: var(--accent-h); transform: translateY(-1px); }
.btn-auth:disabled { opacity: .45; cursor: not-allowed; }
.msg { font-size: .84rem; margin-top: 12px; text-align: center; padding: 8px 12px; border-radius: var(--r-sm); display: none; }
.msg.error { background: rgba(210,88,71,0.1); color: var(--error); border: 1px solid rgba(210,88,71,0.2); }
.msg.success { background: rgba(107,158,120,0.1); color: var(--success); border: 1px solid rgba(107,158,120,0.2); }

/* ── CODE BLOCK ── */
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  font-family: 'Geist Mono', 'Courier New', monospace;
  font-size: .8rem;
  color: var(--text-2);
  overflow-x: auto;
  position: relative;
  line-height: 1.7;
}
.code-block .kw { color: var(--accent); }
.code-block .str { color: var(--success); }
.code-block .cmt { color: var(--text-3); }
.code-block .num { color: #F0A17A; }
.copy-code-btn {
  position: absolute; top: 8px; right: 8px;
  font-size: .72rem; padding: 3px 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text-3); cursor: pointer;
  transition: all var(--tf);
}
.copy-code-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 56px 0;
  color: var(--text-3);
}
.empty-state svg { margin: 0 auto 16px; opacity: .4; }
.empty-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 1.3rem;
  color: var(--text-2);
  margin-bottom: 6px;
}

/* ── TOAST ── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px 16px;
  font-size: .88rem; color: var(--text);
  box-shadow: var(--shadow);
  z-index: 9999; display: flex; align-items: center; gap: 8px;
  transform: translateY(80px); opacity: 0;
  transition: transform var(--tb), opacity var(--tb);
  max-width: 320px;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-color: rgba(107,158,120,0.4); }
#toast.error { border-color: rgba(210,88,71,0.4); }

/* ── SPINNER ── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── DOCS ── */
.docs-section { margin-bottom: 40px; }
.docs-section h3 {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 1.3rem;
  color: var(--text);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.endpoint-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px;
  border-radius: var(--r-sm);
  font-family: monospace; font-size: .82rem;
  margin-bottom: 10px;
}
.method-get { background: rgba(107,158,120,0.12); color: var(--success); border: 1px solid rgba(107,158,120,0.25); }
.method-post { background: rgba(245,198,0,0.1); color: var(--accent); border: 1px solid rgba(245,198,0,0.2); }
.param-table { width: 100%; border-collapse: collapse; font-size: .84rem; margin-top: 10px; }
.param-table th { text-align: left; padding: 8px 12px; color: var(--text-3); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); }
.param-table td { padding: 9px 12px; border-bottom: 1px solid rgba(42,39,36,0.5); color: var(--text-2); vertical-align: top; }
.param-table td:first-child { font-family: monospace; color: var(--accent); }
.param-required { font-size: .7rem; padding: 1px 6px; border-radius: 3px; background: rgba(210,88,71,0.1); color: var(--error); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--tb); }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; }
  .view { padding: 24px 16px; }
  .mobile-bar {
    display: flex;
    position: fixed; top: 0; left: 0; right: 0;
    height: 52px; background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 90; align-items: center; padding: 0 16px; gap: 12px;
  }
}
@media (min-width: 769px) { .mobile-bar { display: none; } }
/* ── REAL-TIME INDICATOR ── */
.realtime-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 16px;
  margin-bottom: 8px;
}
.rt-label {
  font-size: .72rem;
  color: var(--text-3);
  letter-spacing: .03em;
}
.rt-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.rt-dot.pulse {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(107,158,120,0.3);
  animation: rt-pop 0.8s ease forwards;
}
@keyframes rt-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.5); }
  100% { transform: scale(1); background: var(--text-3); box-shadow: none; }
}

/* Mobile realtime dot (top bar) */
.rt-dot-mobile {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  margin-left: auto;
  transition: background 0.3s, box-shadow 0.3s;
  flex-shrink: 0;
}
.rt-dot-mobile.pulse {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(107,158,120,0.25);
  animation: rt-pop 0.8s ease forwards;
}

/* ── STAT CARD — 5-column override ── */
/* Allows 5th stat card (taxa) to fit naturally */
@media (min-width: 900px) {
  .stats-grid { grid-template-columns: repeat(5, 1fr); }
}

/* ── REFRESH BUTTON (small) ── */
.btn-sm {
  padding: 6px 12px;
  font-size: .8rem;
  gap: 5px;
}

/* ── STAT VALUE ANIMATION ── */
.stat-value {
  transition: color 0.2s;
}
.stat-value.updating {
  opacity: 0.6;
}

/* ── OVERVIEW SITES SYNC: also update overview-sites when realtime fires ── */
