/*
 * Component classes — one source of truth for every reusable UI piece.
 *
 * Twelve components, in roughly the order they appear on a page:
 *   .btn          Button (3 variants: -primary, -secondary, -ghost)
 *   .card         Card (surface-1, hairline, radius-lg)
 *   .field        Form field (label + input + help)
 *   .pill         Status indicator with optional leading dot
 *   .stat-card    Eyebrow + big value + delta
 *   .table        Header in surface-1, hairlines between rows
 *   .nav-rail     Vertical sidebar
 *   .topbar       App top strip
 *   .toast        Bottom-right notification
 *   .modal        Centered overlay
 *   .kbd          Keyboard shortcut chip
 *   .empty        Centered empty state
 *
 * No JS framework. HTMX drives interactivity. Animations are CSS-only.
 */

/* -----------------------------------------------------------------------
 * 1. Button
 * --------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-0);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
  user-select: none;
  text-decoration: none;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--gradient-brand);
  color: #ffffff;
  border-color: transparent;
}
.btn-primary:hover { opacity: 0.88; }

.btn-secondary {
  border-color: var(--hairline-strong);
  color: var(--text-0);
}
.btn-secondary:hover { background: var(--surface-1); border-color: var(--text-2); }

.btn-ghost { color: var(--text-1); }
.btn-ghost:hover { background: var(--surface-1); color: var(--text-0); }

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(185,28,28,0.06); }

.btn-sm { height: 28px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn-lg { height: 44px; padding: 0 var(--space-6); font-size: var(--text-base); }
.btn-block { width: 100%; }

/* Loading state — three dots, monospace, no spinner */
.btn[data-loading="true"] {
  color: transparent;
  position: relative;
  pointer-events: none;
}
.btn[data-loading="true"]::after {
  content: '...';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent-fg);
  font-family: var(--font-mono);
  letter-spacing: 2px;
  animation: btn-dots 1.2s steps(4) infinite;
}
.btn-secondary[data-loading="true"]::after { color: var(--text-0); }
@keyframes btn-dots {
  0%   { content: '.'; }
  25%  { content: '..'; }
  50%  { content: '...'; }
  75%  { content: '..'; }
}

/* -----------------------------------------------------------------------
 * 2. Card
 * --------------------------------------------------------------------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-tight  { padding: var(--space-4); }
.card-quiet  { border: none; background: transparent; }
.card-link   { display: block; transition: border-color var(--dur) var(--ease); }
.card-link:hover { border-color: var(--hairline-strong); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.card-title {
  font-size: var(--text-lg);
  font-weight: 500;
  letter-spacing: -0.009em;
  color: var(--text-0);
}

/* -----------------------------------------------------------------------
 * 3. Field (form input + label + help)
 * --------------------------------------------------------------------- */
.field { display: block; margin-bottom: var(--space-4); }
.field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: var(--space-2);
  letter-spacing: -0.003em;
}
.field-input,
.field-textarea,
.field-select {
  display: block;
  width: 100%;
  height: 38px;
  padding: 0 var(--space-3);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-0);
  color: var(--text-0);
  font: inherit;
  font-size: var(--text-sm);
  transition: border-color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}
.field-textarea { height: auto; padding: var(--space-3); resize: vertical; min-height: 90px; }
.field-input:hover, .field-textarea:hover, .field-select:hover {
  border-color: var(--text-2);
}
.field-input:focus, .field-textarea:focus, .field-select:focus {
  outline: none;
  border-color: var(--text-0);
}
.field-input::placeholder, .field-textarea::placeholder { color: var(--text-3); }
.field-help { display: block; font-size: var(--text-xs); color: var(--text-2); margin-top: var(--space-2); }
.field-error { color: var(--danger); font-size: var(--text-xs); margin-top: var(--space-2); }

/* -----------------------------------------------------------------------
 * 4. Pill (status indicator)
 * --------------------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.002em;
  border: 1px solid var(--hairline);
  background: var(--surface-1);
  color: var(--text-1);
  line-height: 1.6;
}
.pill::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.pill-success { color: var(--success); }
.pill-warning { color: var(--warning); }
.pill-danger  { color: var(--danger); }
.pill-accent  { color: var(--accent); }
.pill-quiet::before { display: none; }

/* -----------------------------------------------------------------------
 * 5. Stat card (eyebrow + value + delta)
 * --------------------------------------------------------------------- */
.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.stat-label { font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.stat-value {
  font-size: var(--text-3xl);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-0);
  margin-top: var(--space-2);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-xs);
  color: var(--text-2);
  margin-top: var(--space-2);
}
.stat-delta-up   { color: var(--success); }
.stat-delta-down { color: var(--danger); }

/* -----------------------------------------------------------------------
 * 6. Table
 * --------------------------------------------------------------------- */
.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
table.t thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-1);
}
table.t tbody tr {
  border-bottom: 1px solid var(--hairline);
  transition: background-color var(--dur-fast) var(--ease);
}
table.t tbody tr:last-child { border-bottom: none; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t td { padding: var(--space-3) var(--space-4); color: var(--text-1); }
table.t td.tnum { text-align: right; color: var(--text-0); }

/* -----------------------------------------------------------------------
 * 7. Nav rail (sidebar)
 * --------------------------------------------------------------------- */
.nav-rail {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--rail-w);
  background: var(--surface-1);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-3);
  z-index: 40;
  transition: width var(--dur) var(--ease);
}
.nav-rail-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-2) var(--space-6);
}
.nav-rail-group { margin-top: var(--space-5); }
.nav-rail-group-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 var(--space-3) var(--space-2);
}
.nav-rail-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: var(--text-sm);
  text-decoration: none;
  position: relative;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-rail-item:hover { background: var(--surface-2); color: var(--text-0); }
.nav-rail-item[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text-0);
  font-weight: 500;
}
.nav-rail-item[aria-current="page"]::before {
  content: '';
  position: absolute;
  left: -3px;
  top: 4px; bottom: 4px;
  width: 2px;
  background: var(--brand);
  border-radius: 2px;
}
.nav-rail-foot {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

@media (max-width: 1024px) {
  .nav-rail { width: var(--rail-w-mini); padding-left: var(--space-2); padding-right: var(--space-2); }
  .nav-rail .nav-label, .nav-rail .nav-rail-group-label { display: none; }
  .nav-rail-item { justify-content: center; padding: var(--space-3); }
}

/* -----------------------------------------------------------------------
 * 8. Topbar
 * --------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface-0) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  z-index: 30;
}
.topbar-search {
  flex: 1;
  max-width: 480px;
  height: 32px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  background: var(--surface-1);
  color: var(--text-2);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease);
}
.topbar-search:hover { border-color: var(--hairline-strong); color: var(--text-1); }

/* -----------------------------------------------------------------------
 * 9. Toast
 * --------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  z-index: 100;
  pointer-events: none;
}
.toast {
  min-width: 280px;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-overlay);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-0);
  pointer-events: auto;
  animation: toast-in var(--dur) var(--ease-out);
  position: relative;
  overflow: hidden;
}
.toast-success { border-left: 2px solid var(--success); }
.toast-warning { border-left: 2px solid var(--warning); }
.toast-error   { border-left: 2px solid var(--danger); }
.toast-progress {
  position: absolute;
  left: 0; top: 0;
  height: 1px;
  background: var(--text-2);
  animation: toast-progress 4s linear forwards;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-progress {
  from { width: 100%; }
  to   { width: 0; }
}

/* -----------------------------------------------------------------------
 * 10. Modal / drawer
 * --------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 10, 10, 0.6);
  backdrop-filter: blur(2px);
  z-index: 80;
  animation: fade-in var(--dur) var(--ease);
}
.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - var(--space-8)));
  background: var(--surface-0);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  z-index: 81;
  animation: modal-in var(--dur) var(--ease-out);
}
@keyframes modal-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* -----------------------------------------------------------------------
 * 11. Kbd
 * --------------------------------------------------------------------- */
kbd, .kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--hairline-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-1);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1;
}

/* -----------------------------------------------------------------------
 * 12. Empty state
 * --------------------------------------------------------------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  max-width: 420px;
  margin: 0 auto;
}
.empty-icon {
  width: 56px; height: 56px;
  margin-bottom: var(--space-5);
  color: var(--text-3);
}
.empty-title { font-size: var(--text-lg); font-weight: 500; color: var(--text-0); margin-bottom: var(--space-2); letter-spacing: -0.01em; }
.empty-body  { font-size: var(--text-sm); color: var(--text-2); margin-bottom: var(--space-5); line-height: 1.55; }

/* -----------------------------------------------------------------------
 * Wordmark
 * --------------------------------------------------------------------- */
.wordmark {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.028em;
  color: var(--text-0);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.wordmark::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brand);
  display: inline-block;
}

/* -----------------------------------------------------------------------
 * Page shell — used by /app/* and /admin/* layouts
 * --------------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.shell-main {
  flex: 1;
  margin-left: var(--rail-w);
  min-width: 0;
  transition: margin-left var(--dur) var(--ease);
}
@media (max-width: 1024px) {
  .shell-main { margin-left: var(--rail-w-mini); }
}
.shell-content { padding: var(--space-8) var(--space-8); max-width: var(--content-max); }

/* -----------------------------------------------------------------------
 * Theme toggle button (pinned to rail foot)
 * --------------------------------------------------------------------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--text-1);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text-0); }

/* -----------------------------------------------------------------------
 * Part 5 — Brand / Webflow-style additions
 * All rules below are ADDITIVE — no existing component is broken.
 * --------------------------------------------------------------------- */

/* Hero CTA button — gradient, larger, with a glow shadow */
.btn-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 52px;
  padding: 0 var(--space-8);
  font: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: -0.006em;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--gradient-brand);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.35);
  transition: opacity var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.btn-cta:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(79, 70, 229, 0.45);
  color: #ffffff;
}
.btn-cta:active { transform: translateY(0); }

/* Hero section — gradient background wrapper */
.hero-section {
  background: var(--gradient-hero);
  border-radius: var(--radius-lg);
  padding: var(--space-16) var(--space-10);
  border: 1px solid var(--hairline);
}

/* Post card — blog index grid card with thumbnail */
.post-card {
  display: block;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-decoration: none;
  transition: border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.post-card:hover {
  border-color: var(--hairline-strong);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
.post-card-thumb {
  aspect-ratio: 1200 / 630;
  background: var(--gradient-card);
  overflow: hidden;
  position: relative;
}
.post-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.post-card-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--brand-light);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  opacity: 0.7;
  background: var(--gradient-card);
}
.post-card-body { padding: var(--space-5); }
.post-card-title {
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-0);
  margin: 0 0 var(--space-2);
  letter-spacing: -0.009em;
  line-height: 1.4;
}
.post-card:hover .post-card-title { color: var(--brand); }
.post-card-excerpt {
  font-size: var(--text-sm);
  color: var(--text-2);
  margin: 0 0 var(--space-3);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-card-meta { font-size: var(--text-xs); color: var(--text-3); margin: 0; }

/* Featured card — first post, wider, bigger title */
.post-card-featured .post-card-title { font-size: var(--text-xl); }

/* Site avatar — coloured initials circle on dashboard site cards */
.site-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--gradient-brand);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

/* Stat-card colour accent bars — border-top only, keeps layout identical */
.stat-card-brand   { border-top: 3px solid var(--brand); }
.stat-card-success { border-top: 3px solid var(--success); }
.stat-card-warning { border-top: 3px solid var(--warning); }
.stat-card-danger  { border-top: 3px solid var(--danger); }

/* Brand pill — indigo variant for plan badges */
.pill-brand {
  color: var(--brand);
  background: var(--brand-subtle);
  border-color: rgba(79, 70, 229, 0.2);
}
.pill-brand::before { background: var(--brand); opacity: 1; }

/* CTA strip section — used in landing bottom CTA */
.cta-strip {
  background: var(--gradient-hero);
  border-radius: var(--radius-lg);
  padding: var(--space-16) var(--space-8);
  border: 1px solid var(--hairline);
  text-align: center;
}
