/* Shared logged-in shell. Load before the page CSS, then /theme.css last. */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --accent: #a78bfa;
  --text-primary: #f5f5f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border: #27272a;
  --bg-base: #0a0a0a;
  --bg-surface: #111111;
  --bg-elevated: #18181b;
  --font-google: 'Google Sans', 'Roboto', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-num: 'Inter', system-ui, sans-serif;
  --sidebar-width: 260px;
  --topbar-h: 64px;
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --info: var(--primary);
  --bg: var(--bg-base);
  --surface: var(--bg-surface);
  --surface-2: var(--bg-elevated);
  --text: var(--text-primary);
  --text-2: var(--text-secondary);
  --text-3: var(--text-muted);
}

html { width: 100%; max-width: 100vw; overflow-x: hidden; }
body {
  font-family: var(--font-google);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 40;
}
.overlay.active { display: block; }

body.app-shell { width: 100%; }
body.app-shell-fill {
  height: 100vh;
  height: 100dvh;
  display: flex;
  overflow: hidden;
}
body.app-shell-fill .main-content {
  flex: 1;
  display: flex;
  height: 100%;
  position: relative;
  overflow: hidden;
  width: 100%;
}
body.app-shell-page {
  min-height: 100vh;
  display: flex;
}
body.app-shell-page .sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
}
body.app-shell-page .main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.app-shell .sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
}
.app-shell .sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.app-shell .logo-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  transition: opacity 0.2s;
}
.app-shell .logo-link:hover { opacity: 0.8; }
.app-shell .logo-text {
  font-family: var(--font-google);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}
.app-shell .logo-text span { color: var(--primary); font-weight: 700; }

.app-shell .sidebar-nav {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.app-shell .sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: 0.2s;
}
.app-shell .sidebar-nav a:hover { background: var(--bg-elevated); color: var(--text-primary); }
.app-shell .sidebar-nav a.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary-hover);
  font-weight: 600;
}
.app-shell .sidebar-nav svg { width: 18px; height: 18px; }

.app-shell .history-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.app-shell .history-header { padding: 1rem; display: flex; justify-content: space-between; align-items: center; }
.app-shell .history-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.btn-new-chat-sidebar {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: var(--primary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.1);
  animation: pulse-border 2s infinite;
}
.btn-new-chat-sidebar:hover {
  background: var(--primary);
  color: white;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.6);
  transform: scale(1.1) rotate(90deg);
}
.btn-new-chat-sidebar svg { width: 18px; height: 18px; }
@keyframes pulse-border {
  0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}
.app-shell .history-list {
  padding: 0 1rem 1rem;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.app-shell .history-item {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.app-shell .history-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.app-shell .history-item.active { background: var(--bg-elevated); color: var(--primary-hover); font-weight: 600; }

.app-shell .sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}
.user-info-mini { display: flex; align-items: center; gap: 0.5rem; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--border); }
.btn-logout {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  font-weight: 500;
  padding: 0.5rem;
  border-radius: 6px;
}
.btn-logout:hover { background: rgba(248, 113, 113, 0.1); color: #f87171; }

.top-bar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--bg-base);
  flex-shrink: 0;
  width: 100%;
}
.top-left { display: flex; align-items: center; gap: 1rem; }
.mobile-menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 8px;
}
.top-title { font-weight: 500; font-size: 1rem; color: var(--text-primary); }
.top-right { display: flex; align-items: center; gap: 0.5rem; }

.status-widget {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(167, 139, 250, 0.05));
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 0.4rem 0.5rem 0.4rem 1rem;
  border-radius: 999px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
}
.status-widget::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.05), transparent);
  transform: skewX(-20deg);
  animation: shimmer 4s infinite;
}
@keyframes shimmer { 100% { left: 200%; } }
.wallet-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.credits-text {
  font-size: 1.05rem;
  color: var(--text-primary);
  font-weight: 500;
  letter-spacing: -0.04em;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums lining-nums;
  transition: color 0.3s;
}
.credits-text.flash { color: #f87171 !important; }
.btn-buy {
  background: white;
  color: #0a0a0a;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: 0.2s;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.btn-buy:hover { background: #e5e5e5; transform: scale(1.05); box-shadow: 0 0 15px rgba(255, 255, 255, 0.2); }

.page-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem 0.65rem;
  min-height: 36px;
  width: 100%;
}
.back-play,
.back-btn,
.back-link,
.topbar-btn.back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.back-play:hover,
.back-btn:hover,
.back-link:hover,
.topbar-btn.back:hover { color: var(--text-primary); }
.back-play svg,
.back-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: block;
}
.back-short { display: none; }
.header > .back-btn { margin-left: 0; }

/* Page-level DB fetches. Do not use on the chat typing indicator. */
.skeleton-loader {
  display: block;
  background: var(--bg-elevated);
  border-radius: 8px;
  pointer-events: none;
  animation: skeleton-pulse 1.35s ease-in-out infinite;
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.42; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-loader { animation: none; opacity: 0.65; }
}
.skeleton-loader.sk-sm { height: 10px; width: 32%; }
.skeleton-loader.sk-md { height: 14px; width: 55%; }
.skeleton-loader.sk-lg { height: 2.6rem; width: 44%; }
.skeleton-loader.sk-full { height: 10px; width: 100%; border-radius: 999px; }
.skeleton-loader.sk-chart { height: 220px; width: 100%; }
.skeleton-loader.sk-btn { height: 32px; width: 72px; flex-shrink: 0; border-radius: 8px; }

.skeleton-usage { display: grid; gap: 1rem; margin-bottom: 1rem; }
/* [hidden] must win over the display rules above, otherwise setting
   skeleton.hidden = true (JS) has no effect and the shimmer boxes never clear. */
.skeleton-usage[hidden],
.skeleton-usage-cards[hidden],
.skeleton-usage-card[hidden],
.skeleton-usage-chart[hidden] { display: none !important; }
.skeleton-usage-cards {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1rem;
}
.skeleton-usage-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.35rem 1.4rem;
  min-height: 148px;
}
.skeleton-usage-card .skeleton-loader.sk-lg { margin: 0.85rem 0 0.55rem; }
.skeleton-usage-chart {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.15rem 1.3rem 1rem;
}
.skeleton-usage-chart .skeleton-loader.sk-md { margin-bottom: 0.9rem; width: 7.5rem; }
@media (max-width: 1100px) {
  .skeleton-usage-cards { grid-template-columns: 1fr; }
}

.skeleton-key-row { pointer-events: none; }
.skeleton-key-row:hover { border-color: var(--border); }
.skeleton-key-row .key-info { flex: 1; min-width: 0; }
.skeleton-key-row .skeleton-loader.sk-md { width: 48%; }
.skeleton-key-row .skeleton-loader.sk-sm { width: 72%; margin-top: 0.35rem; }

.app-shell .history-list .skeleton-history-line {
  height: 12px;
  margin: 0.7rem 0.4rem;
  flex-shrink: 0;
  max-width: 100%;
}
.app-shell .history-list .skeleton-history-line:nth-child(1) { width: 86%; }
.app-shell .history-list .skeleton-history-line:nth-child(2) { width: 70%; }
.app-shell .history-list .skeleton-history-line:nth-child(3) { width: 78%; }
.app-shell .history-list .skeleton-history-line:nth-child(4) { width: 62%; }
.app-shell .history-list .skeleton-history-line:nth-child(5) { width: 74%; }

@media (max-width: 768px) {
  .app-shell .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
  }
  .app-shell .sidebar.open { transform: translateX(0); }
  .app-shell .mobile-menu-btn { display: flex; align-items: center; justify-content: center; }
  body.app-shell-page .main-content { margin-left: 0; }
  .top-bar { padding: 0 1rem; gap: 0.5rem; }
  .wallet-label { display: none; }
  .credits-text { font-size: 0.9rem; }
  .btn-buy { padding: 0.3rem 0.7rem; font-size: 0.75rem; }
  .header > .back-btn { margin-left: 0; }
  .back-full { display: none; }
  .back-short { display: inline; }
}
