/* ============================================================
   Blog Scoreboard — Shared PWA Design System
   Used by: bsb_pwa_kirk.html, bsb_pwa_captain.html
   Built: 2026-06-05
   ============================================================ */

:root {
  /* Brand colors */
  --bsb-primary: #10b981;        /* scoreboard green — the dopamine color */
  --bsb-primary-dark: #059669;
  --bsb-primary-light: #d1fae5;
  --bsb-primary-50: #ecfdf5;

  /* Accent palette */
  --bsb-accent: #6366f1;         /* indigo — secondary actions */
  --bsb-amber: #f59e0b;          /* warning, drift */
  --bsb-red: #ef4444;            /* danger, churn */
  --bsb-blue: #3b82f6;           /* info */

  /* Neutral palette */
  --bsb-bg: #f8fafc;
  --bsb-surface: #ffffff;
  --bsb-surface-2: #f1f5f9;
  --bsb-border: #e2e8f0;
  --bsb-border-strong: #cbd5e1;
  --bsb-text: #0f172a;
  --bsb-text-muted: #64748b;
  --bsb-text-subtle: #94a3b8;

  /* Status colors */
  --bsb-state-trial: #f59e0b;
  --bsb-state-paying: #10b981;
  --bsb-state-locked: #6366f1;
  --bsb-state-drifting: #f97316;
  --bsb-state-churned: #94a3b8;

  /* Typography */
  --bsb-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bsb-font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;

  /* Spacing scale (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Border radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1);

  /* Transitions */
  --t-fast: 120ms ease;
  --t-base: 180ms ease;
  --t-slow: 280ms ease;
}

/* ----------------------------------------------------------
   Reset & base
   ---------------------------------------------------------- */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--bsb-font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--bsb-text);
  background: var(--bsb-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a { color: var(--bsb-primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5, h6 { font-weight: 700; line-height: 1.25; color: var(--bsb-text); }

img, svg { display: block; max-width: 100%; }

/* ----------------------------------------------------------
   App shell
   ---------------------------------------------------------- */

.bsb-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.bsb-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--sp-4);
  background: var(--bsb-surface);
  border-bottom: 1px solid var(--bsb-border);
  box-shadow: var(--shadow-sm);
}

.bsb-topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: 16px;
}

.bsb-topbar-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--bsb-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.bsb-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.bsb-main {
  flex: 1;
  padding: var(--sp-6) var(--sp-4) calc(var(--sp-16) + env(safe-area-inset-bottom));
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 900px) {
  .bsb-main { padding: var(--sp-8); }
}

/* ----------------------------------------------------------
   Bottom tab nav (mobile primary)
   ---------------------------------------------------------- */

.bsb-bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  height: 64px;
  background: var(--bsb-surface);
  border-top: 1px solid var(--bsb-border);
  box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04);
  padding-bottom: env(safe-area-inset-bottom);
}

.bsb-bottomnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--bsb-text-muted);
  transition: color var(--t-fast);
}

.bsb-bottomnav-item.is-active {
  color: var(--bsb-primary-dark);
}

.bsb-bottomnav-item .icon {
  font-size: 22px;
  line-height: 1;
}

/* ----------------------------------------------------------
   Card
   ---------------------------------------------------------- */

.bsb-card {
  background: var(--bsb-surface);
  border: 1px solid var(--bsb-border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.bsb-card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.bsb-card-h h2,
.bsb-card-h h3 {
  font-size: 16px;
  font-weight: 700;
}

.bsb-card-h .actions {
  display: flex;
  gap: var(--sp-2);
}

.bsb-card + .bsb-card { margin-top: var(--sp-4); }

/* ----------------------------------------------------------
   Buttons
   ---------------------------------------------------------- */

.bsb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.bsb-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.bsb-btn-primary {
  background: var(--bsb-primary);
  color: #fff;
}
.bsb-btn-primary:hover:not(:disabled) { background: var(--bsb-primary-dark); }

.bsb-btn-secondary {
  background: var(--bsb-surface);
  color: var(--bsb-text);
  border-color: var(--bsb-border-strong);
}
.bsb-btn-secondary:hover:not(:disabled) { background: var(--bsb-surface-2); }

.bsb-btn-ghost {
  background: transparent;
  color: var(--bsb-text-muted);
}
.bsb-btn-ghost:hover:not(:disabled) { background: var(--bsb-surface-2); color: var(--bsb-text); }

.bsb-btn-danger {
  background: var(--bsb-red);
  color: #fff;
}
.bsb-btn-danger:hover:not(:disabled) { background: #dc2626; }

.bsb-btn-lg { padding: 14px 22px; font-size: 16px; }
.bsb-btn-sm { padding: 6px 12px; font-size: 13px; }
.bsb-btn-block { width: 100%; }

/* ----------------------------------------------------------
   Form inputs
   ---------------------------------------------------------- */

.bsb-field { margin-bottom: var(--sp-4); }

.bsb-field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--bsb-text);
  margin-bottom: var(--sp-2);
}

.bsb-field-hint {
  display: block;
  font-size: 12px;
  color: var(--bsb-text-muted);
  margin-top: var(--sp-1);
}

.bsb-input,
.bsb-select,
.bsb-textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--bsb-border-strong);
  border-radius: var(--r-md);
  background: var(--bsb-surface);
  font-size: 14px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.bsb-input:focus,
.bsb-select:focus,
.bsb-textarea:focus {
  outline: none;
  border-color: var(--bsb-primary);
  box-shadow: 0 0 0 3px var(--bsb-primary-light);
}

.bsb-textarea { min-height: 96px; resize: vertical; }

/* ----------------------------------------------------------
   Tables
   ---------------------------------------------------------- */

.bsb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.bsb-table th,
.bsb-table td {
  text-align: left;
  padding: var(--sp-3) var(--sp-3);
  border-bottom: 1px solid var(--bsb-border);
}

.bsb-table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bsb-text-muted);
}

.bsb-table tbody tr {
  transition: background var(--t-fast);
}

.bsb-table tbody tr:hover {
  background: var(--bsb-surface-2);
  cursor: pointer;
}

/* ----------------------------------------------------------
   Badge
   ---------------------------------------------------------- */

.bsb-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bsb-surface-2);
  color: var(--bsb-text-muted);
}

.bsb-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.bsb-badge-trial { background: #fef3c7; color: #92400e; }
.bsb-badge-paying { background: #d1fae5; color: #065f46; }
.bsb-badge-locked { background: #e0e7ff; color: #3730a3; }
.bsb-badge-drifting { background: #ffedd5; color: #9a3412; }
.bsb-badge-churned { background: #f1f5f9; color: #475569; }
.bsb-badge-pending { background: #dbeafe; color: #1e40af; }
.bsb-badge-publishing { background: #ddd6fe; color: #5b21b6; }
.bsb-badge-published { background: #d1fae5; color: #065f46; }
.bsb-badge-failed { background: #fee2e2; color: #991b1b; }

/* ----------------------------------------------------------
   Stat tile
   ---------------------------------------------------------- */

.bsb-stat-grid {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 700px) {
  .bsb-stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.bsb-stat {
  background: var(--bsb-surface);
  border: 1px solid var(--bsb-border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.bsb-stat-label {
  font-size: 12px;
  color: var(--bsb-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.bsb-stat-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 6px;
  color: var(--bsb-text);
}

.bsb-stat-delta {
  font-size: 12px;
  color: var(--bsb-primary-dark);
  margin-top: 4px;
  font-weight: 600;
}

.bsb-stat-delta.is-down { color: var(--bsb-red); }

/* ----------------------------------------------------------
   Scoreboard graph
   ---------------------------------------------------------- */

.bsb-sb-card {
  background: linear-gradient(135deg, #064e3b 0%, #047857 50%, #10b981 100%);
  color: #fff;
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
}

.bsb-sb-card .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  font-weight: 600;
}

.bsb-sb-card .value {
  font-size: 48px;
  font-weight: 800;
  margin-top: var(--sp-1);
  line-height: 1;
}

.bsb-sb-card .target {
  font-size: 14px;
  opacity: 0.85;
  margin-top: var(--sp-2);
}

.bsb-sb-graph {
  margin-top: var(--sp-4);
  height: 120px;
  width: 100%;
}

/* ----------------------------------------------------------
   Toast
   ---------------------------------------------------------- */

.bsb-toast-zone {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.bsb-toast {
  background: var(--bsb-text);
  color: #fff;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: bsb-toast-in var(--t-base) both, bsb-toast-out var(--t-base) 3s both;
  max-width: 90vw;
  pointer-events: auto;
}

@keyframes bsb-toast-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: none; }
}

@keyframes bsb-toast-out {
  to { opacity: 0; transform: translateY(20px); }
}

/* ----------------------------------------------------------
   Modal / sheet
   ---------------------------------------------------------- */

.bsb-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: bsb-fade-in var(--t-base);
}

@media (min-width: 700px) {
  .bsb-modal-backdrop { align-items: center; }
}

.bsb-modal {
  background: var(--bsb-surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--sp-6);
  animation: bsb-slide-up var(--t-base);
}

@media (min-width: 700px) {
  .bsb-modal { border-radius: var(--r-xl); }
}

.bsb-modal-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.bsb-modal-h h2 {
  font-size: 18px;
  font-weight: 700;
}

.bsb-modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: var(--bsb-surface-2);
  color: var(--bsb-text-muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes bsb-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes bsb-slide-up {
  from { transform: translateY(100%); }
  to { transform: none; }
}

/* ----------------------------------------------------------
   Empty state
   ---------------------------------------------------------- */

.bsb-empty {
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  color: var(--bsb-text-muted);
}

.bsb-empty .icon { font-size: 48px; opacity: 0.5; margin-bottom: var(--sp-3); }
.bsb-empty h3 { color: var(--bsb-text); font-size: 16px; margin-bottom: var(--sp-2); }

/* ----------------------------------------------------------
   Page header
   ---------------------------------------------------------- */

.bsb-pageh {
  margin-bottom: var(--sp-6);
}

.bsb-pageh h1 {
  font-size: 24px;
  font-weight: 800;
}

.bsb-pageh .subtitle {
  font-size: 14px;
  color: var(--bsb-text-muted);
  margin-top: var(--sp-1);
}

/* ----------------------------------------------------------
   Utility
   ---------------------------------------------------------- */

.bsb-muted { color: var(--bsb-text-muted); }
.bsb-subtle { color: var(--bsb-text-subtle); }
.bsb-mono { font-family: var(--bsb-font-mono); font-variant-numeric: tabular-nums; }
.bsb-money { font-variant-numeric: tabular-nums; }
.bsb-num { font-variant-numeric: tabular-nums; }

.bsb-flex { display: flex; }
.bsb-flex-col { display: flex; flex-direction: column; }
.bsb-items-center { align-items: center; }
.bsb-justify-between { justify-content: space-between; }
.bsb-gap-1 { gap: var(--sp-1); }
.bsb-gap-2 { gap: var(--sp-2); }
.bsb-gap-3 { gap: var(--sp-3); }
.bsb-gap-4 { gap: var(--sp-4); }

.bsb-mt-2 { margin-top: var(--sp-2); }
.bsb-mt-3 { margin-top: var(--sp-3); }
.bsb-mt-4 { margin-top: var(--sp-4); }
.bsb-mt-6 { margin-top: var(--sp-6); }

.bsb-hide-mobile { display: none; }
@media (min-width: 700px) { .bsb-hide-mobile { display: initial; } }

.bsb-hide-desktop { display: initial; }
@media (min-width: 700px) { .bsb-hide-desktop { display: none; } }

/* ----------------------------------------------------------
   Demo persona switcher (kirk app only)
   ---------------------------------------------------------- */

.bsb-persona-switch {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-2);
  background: var(--bsb-surface-2);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
  overflow-x: auto;
}

.bsb-persona-switch button {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--bsb-text-muted);
  background: transparent;
  transition: all var(--t-fast);
}

.bsb-persona-switch button.is-active {
  background: var(--bsb-surface);
  color: var(--bsb-text);
  box-shadow: var(--shadow-sm);
}

/* ----------------------------------------------------------
   PIN gate (captain app)
   ---------------------------------------------------------- */

.bsb-pingate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-6);
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.bsb-pingate-card {
  background: var(--bsb-surface);
  border-radius: var(--r-xl);
  padding: var(--sp-8) var(--sp-6);
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow-xl);
}

.bsb-pingate-card h1 {
  font-size: 22px;
  margin-bottom: var(--sp-2);
}

.bsb-pingate-card p {
  color: var(--bsb-text-muted);
  font-size: 14px;
  margin-bottom: var(--sp-6);
}

.bsb-pingate-input {
  text-align: center;
  letter-spacing: 0.5em;
  font-size: 24px;
  font-weight: 700;
  font-family: var(--bsb-font-mono);
}
