@import url('tokens.css');
@import url('motion.css');
@import url('components/skeleton.css');
@import url('components/ai-loader.css');
@import url('components/toast.css');

/* ─── Modern CSS reset ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Enforce [hidden] over any author display declarations */
[hidden] { display: none !important; }

/* ─── Root defaults ────────────────────────────────────────────── */
html {
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-surface-elevated);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  transition: var(--theme-transition);
}

body {
  min-height: 100vh;
  background-color: var(--color-surface-elevated);
  color: var(--color-text-primary);
  transition: var(--theme-transition);
}

/* Surfaces fade smoothly when the theme flips (respecting reduced-motion). */
.card, .tile, section, aside, header, footer, .panel,
[class*="-panel"], [class*="-card"] {
  transition: var(--theme-transition);
}

/* ─── Typography baseline ──────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
}

p {
  line-height: var(--line-height-normal);
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ─── Form element reset ────────────────────────────────────────── */
button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

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

/* ─── Skip link ─────────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 400;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-primary);
  text-decoration: none;
  box-shadow: var(--shadow-lg);
  transition: top var(--duration-fast) var(--ease-out);
}

.skip-link:focus {
  top: var(--space-4);
}

/* ─── Global focus ring ─────────────────────────────────────────────
   Highly visible 2px offset ring matching the brand (REVAMP a11y §1),
   layered with a soft glow for a refined Stripe-grade focus state. */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-focus);
}

/* ─── Screen reader only ────────────────────────────────────────── */
.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;
}

/* ─── Reduced motion ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── Global form-actions (primary button bottom-right, §6) ─────── */
.form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: var(--space-3);
  margin-top: var(--space-2);
}

/* ─── In-app back button (§4) ───────────────────────────────────── */
.page-back-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-secondary, #475569);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  transition: background 150ms, color 150ms;
  min-height: 44px;
}
.page-back-btn:hover { background: var(--color-surface-subtle); color: var(--color-text-primary); }
.page-back-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* ─── Standardize old .site-nav (hidden when shell is active) ───── */
body.has-sidebar .site-nav { display: none !important; }

/* ─── Floating theme toggle (standalone pages w/o nav shell) ───── */
.theme-toggle--floating {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}
.theme-toggle--floating svg { width: 18px; height: 18px; }
.theme-toggle--floating:hover {
  color: var(--color-primary);
  border-color: var(--color-primary-border);
  background: var(--color-primary-light);
}
.theme-toggle--floating:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ─── Shared slim site footer (mounted app-wide via site-footer.js) ─── */
.site-footer {
  margin-top: var(--space-10, 2.5rem);
  padding: var(--space-5, 1.25rem) var(--space-6, 1.5rem);
  border-top: 1px solid var(--color-border, #e5e7eb);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  text-align: center;
}
.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2, 0.5rem) var(--space-4, 1rem);
}
.site-footer__links a {
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-secondary, #475569);
  text-decoration: none;
}
.site-footer__links a:hover {
  color: var(--color-primary, #2563eb);
  text-decoration: underline;
}
.site-footer__copy {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-tertiary, #94a3b8);
  margin: 0;
}

/* ─── Theme-adaptive logo utility ──────────────────────────────
   Wrap both variants inside a parent with .logo-adaptive.
   Default (light theme): show dark logo; hide light logo.
   [data-theme="dark"]:  show light logo; hide dark logo.
─────────────────────────────────────────────────────────────── */
.logo-adaptive .logo--light { display: none; }
.logo-adaptive .logo--dark  { display: block; }
[data-theme="dark"] .logo-adaptive .logo--light { display: block; }
[data-theme="dark"] .logo-adaptive .logo--dark  { display: none; }
