/* ==========================================================================
   Hopewick shared UI components (Hopewick 2.0)
   Needs /assets/hopewick-tokens.css first. Class prefix: hw-
   Components: buttons, cards, inputs, chips, toggles, bottom nav, sidebar nav,
   empty states, loading states, toasts, crisis entry, theme toggle, logo.
   ========================================================================== */

/* ---------- Base helpers ---------- */
.hw-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.hw-focus:focus-visible,
.hw-btn:focus-visible, .hw-chip:focus-visible, .hw-toggle:focus-visible, .hw-tab:focus-visible,
.hw-nav-item:focus-visible, .hw-card--link:focus-visible, .hw-crisis-btn:focus-visible,
.hw-theme-toggle:focus-visible, .hw-input:focus-visible {
  outline: 3px solid var(--focus-color); outline-offset: 2px; box-shadow: none;
}

/* ---------- Logo ---------- */
.hw-logo { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text); text-decoration: none; font-family: var(--font-display); font-weight: var(--weight-bold); letter-spacing: -.01em; }
.hw-logo img { display: block; width: 36px; height: auto; flex: none; }
.hw-logo .hw-logo-name { font-size: var(--text-lg); }
.hw-tagline { color: var(--muted); font-size: var(--text-sm); }

/* ---------- Buttons ---------- */
.hw-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 10px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: var(--weight-semibold); line-height: 1.2; text-decoration: none; text-align: center;
  cursor: pointer; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}
.hw-btn:hover { background: var(--surface-2); }
.hw-btn:active { transform: translateY(1px); }
.hw-btn[disabled], .hw-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.hw-btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.hw-btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.hw-btn--secondary { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.hw-btn--secondary:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent)); }
.hw-btn--ghost { background: transparent; border-color: transparent; }
.hw-btn--danger { background: var(--danger); border-color: var(--danger); color: var(--danger-contrast); }
.hw-btn--danger:hover { filter: brightness(.95); }
.hw-btn--sm { min-height: 36px; padding: 6px 12px; font-size: var(--text-sm); border-radius: 10px; }
.hw-btn--block { width: 100%; }
.hw-btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- Cards ---------- */
.hw-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-sm); min-width: 0; color: var(--text);
}
.hw-card--raised { box-shadow: var(--shadow); }
.hw-card--tinted { background: var(--accent-soft); border-color: transparent; }
.hw-card--crisis { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.hw-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.hw-card__title { margin: 0; font-size: var(--text-md); font-weight: var(--weight-bold); line-height: var(--leading-tight); letter-spacing: -.01em; }
.hw-card__meta { margin: 0; color: var(--muted); font-size: var(--text-sm); }
.hw-card__body { margin: 0; }
.hw-card__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.hw-card--link { display: flex; align-items: center; gap: var(--space-3); text-align: left; width: 100%; font: inherit; cursor: pointer; text-decoration: none; transition: border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast); }
.hw-card--link:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.hw-card--link .hw-card__chev { margin-left: auto; color: var(--muted); flex: none; }
.hw-icon-badge { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-strong); flex: none; }
.hw-icon-badge svg { width: 20px; height: 20px; }
.hw-icon-badge--warm { background: var(--accent-warm-soft); color: var(--accent-warm); }
.hw-icon-badge--gold { background: var(--accent-gold-soft); color: var(--accent-gold); }
.hw-icon-badge--crisis { background: var(--danger-soft); color: var(--danger); }

/* ---------- Inputs ---------- */
.hw-field { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-3); }
.hw-label { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.hw-hint { font-size: var(--text-sm); color: var(--muted); }
.hw-input, .hw-select, .hw-textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit;
}
.hw-textarea { min-height: 96px; resize: vertical; line-height: var(--leading); }
.hw-input:focus, .hw-select:focus, .hw-textarea:focus { border-color: var(--accent); }
.hw-input[aria-invalid="true"] { border-color: var(--danger); }

/* ---------- Chips ---------- */
.hw-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.hw-chip {
  display: inline-flex; align-items: center; gap: var(--space-1); min-height: 36px; padding: 6px 14px;
  border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); cursor: pointer;
}
.hw-chip:hover { border-color: var(--accent); }
.hw-chip[aria-pressed="true"], .hw-chip[aria-selected="true"], .hw-chip[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.hw-chip--warm { background: var(--accent-warm-soft); border-color: transparent; color: var(--accent-warm); }

/* ---------- Toggle (use <button role="switch" aria-checked>) ---------- */
.hw-toggle { display: inline-flex; align-items: center; gap: var(--space-3); min-height: var(--tap); background: none; border: 0; padding: 0; color: var(--text); font: inherit; cursor: pointer; }
.hw-toggle__track { position: relative; width: 46px; height: 28px; border-radius: var(--radius-pill); background: var(--surface-3); border: 1px solid var(--border-strong); flex: none; transition: background var(--dur-fast); }
.hw-toggle__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); border: 1px solid var(--border-strong); transition: transform var(--dur-fast) var(--ease); }
.hw-toggle[aria-checked="true"] .hw-toggle__track,
.hw-toggle[aria-pressed="true"] .hw-toggle__track { background: var(--accent); border-color: var(--accent); }
.hw-toggle[aria-checked="true"] .hw-toggle__track::after,
.hw-toggle[aria-pressed="true"] .hw-toggle__track::after { transform: translateX(18px); }

/* ---------- Theme toggle (light/dark) ---------- */
.hw-theme-toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; min-width: 40px; padding: 6px 10px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-sm); font-weight: var(--weight-semibold); cursor: pointer; }
.hw-theme-toggle:hover { background: var(--surface-2); }
.hw-theme-toggle .hw-icon-sun, .hw-theme-toggle .hw-icon-moon { width: 18px; height: 18px; }
.hw-theme-toggle[aria-pressed="true"] .hw-icon-sun { display: none; }
.hw-theme-toggle[aria-pressed="false"] .hw-icon-moon, .hw-theme-toggle:not([aria-pressed]) .hw-icon-moon { display: none; }

/* ---------- Crisis entry ("Get help now") - always visible, always free ---------- */
.hw-crisis-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: var(--radius-pill); border: 1px solid var(--danger); background: var(--danger); color: var(--danger-contrast);
  font: inherit; font-size: var(--text-sm); font-weight: var(--weight-bold); text-decoration: none; white-space: nowrap; cursor: pointer;
}
.hw-crisis-btn:hover { filter: brightness(.95); }
.hw-crisis-btn svg { width: 16px; height: 16px; flex: none; }

/* ---------- Bottom nav (mobile) ---------- */
.hw-bottom-nav {
  display: flex; align-items: stretch; justify-content: space-around; gap: 2px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent); border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.hw-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; padding: 6px 4px; border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--muted); font: inherit; font-size: var(--text-xs); font-weight: var(--weight-semibold); cursor: pointer;
}
.hw-tab svg { width: 22px; height: 22px; }
.hw-tab:hover { color: var(--text); background: var(--surface-2); }
.hw-tab[aria-current="page"] { color: var(--accent-strong); background: var(--accent-soft); }

/* ---------- Sidebar nav (desktop) ---------- */
.hw-sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.hw-nav-item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); font: inherit; font-weight: var(--weight-medium);
  text-align: left; text-decoration: none; cursor: pointer;
}
.hw-nav-item svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.hw-nav-item:hover { background: var(--surface-2); }
.hw-nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); font-weight: var(--weight-bold); }
.hw-nav-item[aria-current="page"] svg { color: var(--accent-strong); }
.hw-nav-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: var(--weight-bold); padding: var(--space-3) 12px var(--space-1); }

/* ---------- Empty states ---------- */
.hw-empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius-md); background: var(--surface); }
.hw-empty__title { margin: 0 0 var(--space-1); color: var(--text); font-size: var(--text-base); font-weight: var(--weight-bold); }
.hw-empty__body { margin: 0 0 var(--space-3); font-size: var(--text-sm); }
.hw-empty--inline { text-align: left; padding: var(--space-3) var(--space-4); }

/* ---------- Loading states ---------- */
.hw-spinner { display: inline-block; width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: hw-spin .8s linear infinite; }
.hw-skeleton { display: block; border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: hw-shimmer 1.4s ease infinite; min-height: 14px; }
@keyframes hw-spin { to { transform: rotate(360deg); } }
@keyframes hw-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Toasts ---------- */
.hw-toasts { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--space-2); align-items: center; z-index: 200; pointer-events: none; max-width: calc(100vw - 24px); }
.hw-toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); font-size: var(--text-sm); box-shadow: var(--shadow); }
.hw-toast--bad { background: var(--danger); color: var(--danger-contrast); }

/* ---------- Progress + stats ---------- */
.hw-progress { height: 8px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.hw-progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.hw-stat { display: flex; align-items: baseline; gap: var(--space-2); }
.hw-stat__num { font-size: var(--text-2xl); font-weight: var(--weight-bold); color: var(--accent-strong); line-height: 1; letter-spacing: -.02em; }
.hw-stat__label { color: var(--muted); font-size: var(--text-sm); }

@media (prefers-reduced-motion: reduce) {
  .hw-spinner, .hw-skeleton { animation: none; }
  .hw-btn, .hw-card--link, .hw-toggle__track, .hw-toggle__track::after { transition: none; }
}

/* ---------- Logo lockup (light / dark artwork) ----------
   Two images, one shown per theme. The dark one is the same artwork with the
   wordmark and tagline recoloured to near-white (tools/brand/build_logo_assets.py). */
.hw-lockup { display: block; margin: 0; line-height: 0; }
.hw-lockup img { display: block; width: 100%; height: auto; }
.hw-lockup picture { display: contents; }
.hw-lockup__dark { display: none !important; }
:root[data-theme="dark"] .hw-lockup__light { display: none !important; }
:root[data-theme="dark"] .hw-lockup__dark { display: block !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .hw-lockup__light { display: none !important; }
  :root:not([data-theme="light"]) .hw-lockup__dark { display: block !important; }
}
