/* ==========================================================================
   Nico Delgado — design-system components + global base.
   Plain CSS classes; no Tailwind utilities needed. Page-specific CSS lives
   with its page: landing → public/landing.html <style>, intake → intake.css.
   public/styles/nd.css must stay byte-identical (test-enforced) — edit here,
   then copy.
   ========================================================================== */

/* ---------- Global base ---------- */
::selection {
  background: var(--accent-fill);
  color: var(--text-on-red);
}
/* Base rules are scoped with :where() so they carry ZERO extra specificity
   (0,0,1): pages that mix .nd-app with Tailwind utilities (admin) can always
   override them with a single utility class. */
:where(.nd-app) a {
  color: inherit;
  text-decoration: none;
}
/* Keyboard focus for text links — the dark canvas washes out the UA default.
   (Buttons carry their own --ring; this only targets real <a> elements.) */
:where(.nd-app) a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: var(--r-xs);
}
:where(.nd-app) h1,
:where(.nd-app) h2,
:where(.nd-app) h3,
:where(.nd-app) h4 {
  font-family: var(--font-display);
  letter-spacing: var(--ls-snug);
  margin: 0;
  text-wrap: balance;
}
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
::-webkit-scrollbar-track {
  background: var(--ink-1000);
}
::-webkit-scrollbar-thumb {
  background: var(--ink-500);
  border-radius: var(--r-pill);
  border: 3px solid var(--ink-1000);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--ink-400);
}

.nd-app {
  background: var(--surface-canvas);
  color: var(--text-primary);
  font-family: var(--font-body);
}
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* Reveal — hidden start state only when motion is allowed */
@media (prefers-reduced-motion: no-preference) {
  [data-reveal] {
    opacity: 0;
    transform: translateY(26px);
    transition: opacity 0.7s var(--ease-out), transform 0.7s var(--ease-out);
  }
  [data-reveal].is-in {
    opacity: 1;
    transform: none;
  }
}

/* Reduced motion — neutralize the looping + entrance animations the JS-gated
   Reveal doesn't cover (status pulse, chat dot, typing, message rise, voice
   orb/wave, success pop, mini-pulse). Content stays put and fully visible;
   only the movement is removed. Honors WCAG 2.3.3 / the user's OS setting. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ==========================================================================
   DESIGN-SYSTEM COMPONENTS
   ========================================================================== */

/* Logo / wordmark */
.nd-logo {
  display: inline-flex;
  align-items: baseline;
  gap: 0.06em;
  font-family: var(--font-display);
  font-weight: var(--w-extra);
  letter-spacing: var(--ls-tight);
  color: var(--text-primary);
  line-height: 1;
  user-select: none;
}
.nd-logo__tick {
  display: inline-block;
  width: 0.42em;
  height: 0.12em;
  background: var(--accent);
  transform: translateY(-0.04em);
  border-radius: 1px;
}
@keyframes nd-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0.25; } }
@media (prefers-reduced-motion: no-preference) {
  .nd-logo--blink .nd-logo__tick { animation: nd-blink 1.4s steps(1) infinite; }
}

/* Mark (brand symbol) */
.nd-mark { display: block; flex: none; }
.nd-mark__tile { fill: #15151b; }
.nd-mark__edge { stroke: rgba(255, 255, 255, 0.07); }
.nd-mark__slash { stroke: var(--accent); }

/* ChatBubble */
.nd-bubble {
  max-width: 100%;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.55;
  padding: 13px 17px;
  border-radius: var(--r-lg);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}
.nd-bubble--ai {
  background: var(--surface-card);
  color: var(--text-primary);
  border: 1px solid var(--hairline);
  border-top-left-radius: var(--r-xs);
}
.nd-bubble--user {
  background: var(--accent-fill);
  color: var(--text-on-red);
  font-weight: 500;
  border-top-right-radius: var(--r-xs);
  /* The user's own line breaks survive (their text renders as a raw string). */
  white-space: pre-line;
}
.nd-bubble--note {
  background: transparent;
  border: 1px dashed var(--border-subtle);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}
/* Block content inside bubbles (paragraphs/lists from renderMessageText). */
.nd-bubble p { margin: 0 0 0.6em; }
.nd-bubble p:last-child { margin-bottom: 0; }
.nd-bubble ul,
.nd-bubble ol { margin: 0.2em 0 0.6em; padding-left: 1.15em; }
.nd-bubble ul:last-child,
.nd-bubble ol:last-child { margin-bottom: 0; }
.nd-bubble li { margin-bottom: 0.25em; }
.nd-bubble li:last-child { margin-bottom: 0; }

/* Button */
.nd-btn {
  --_bg: var(--accent-fill);
  --_fg: var(--text-on-red);
  --_bd: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-weight: var(--w-semibold);
  font-size: var(--fs-base);
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: nowrap;
  border: 1.5px solid var(--_bd);
  background: var(--_bg);
  color: var(--_fg);
  border-radius: var(--r-sm);
  padding: 0 var(--space-5);
  height: 52px;
  cursor: pointer;
  transition: var(--t-hover);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  text-decoration: none;
}
.nd-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.nd-btn:active { transform: translateY(1px) scale(0.985); }
.nd-btn[disabled] { opacity: 0.4; cursor: not-allowed; transform: none; }
.nd-btn--sm { height: 40px; font-size: var(--fs-sm); padding: 0 var(--space-4); }
.nd-btn--lg { height: 60px; font-size: var(--fs-lg); padding: 0 var(--space-6); }
.nd-btn--primary { box-shadow: var(--shadow-sm); }
.nd-btn--primary:hover:not([disabled]) {
  --_bg: var(--accent-fill-hover);
  box-shadow: var(--glow-red);
  transform: translateY(-1px);
}
.nd-btn--primary:active:not([disabled]) { --_bg: var(--accent-fill-press); }
.nd-btn--gold { --_bg: var(--accent-2); --_fg: var(--text-on-gold); }
.nd-btn--gold:hover:not([disabled]) { --_bg: var(--accent-2-hover); transform: translateY(-1px); }
.nd-btn--soft { --_bg: var(--accent-soft); --_fg: var(--accent); --_bd: transparent; }
.nd-btn--soft:hover:not([disabled]) { --_bg: rgba(238, 59, 65, 0.2); --_fg: var(--red-300); }
.nd-btn--outline { --_bg: transparent; --_fg: var(--text-primary); --_bd: var(--border-strong); }
.nd-btn--outline:hover:not([disabled]) { --_bd: var(--accent); --_fg: var(--accent); }
.nd-btn--ghost { --_bg: transparent; --_fg: var(--text-secondary); }
.nd-btn--ghost:hover:not([disabled]) { --_bg: var(--surface-raised); --_fg: var(--text-primary); }
.nd-btn--block { width: 100%; }
.nd-btn--pill { border-radius: var(--r-pill); }

/* Avatar */
.nd-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  position: relative;
  font-family: var(--font-display);
  font-weight: var(--w-extra);
  letter-spacing: -0.03em;
  color: var(--ink-1000);
  background: var(--accent);
  border-radius: var(--r-md);
  overflow: visible;
  user-select: none;
}
.nd-avatar--circle { border-radius: var(--r-pill); }
.nd-avatar--gold { background: var(--accent-2); }
.nd-avatar--neutral { background: var(--ink-600); color: var(--text-primary); }
.nd-avatar--glow { box-shadow: var(--glow-red); }
.nd-avatar--gold.nd-avatar--glow { box-shadow: var(--glow-gold); }
.nd-avatar__img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.nd-avatar__u { opacity: 0.5; }
.nd-avatar__dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 30%;
  height: 30%;
  min-width: 8px;
  min-height: 8px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid var(--surface-canvas);
}

/* Badge + Tag */
.nd-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--w-medium);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: var(--r-xs);
  line-height: 1;
}
.nd-badge--red { background: rgba(255, 59, 59, 0.14); color: var(--red-300); }
.nd-badge--gold { background: rgba(255, 198, 64, 0.16); color: var(--gold-300); }
.nd-badge--neutral { background: var(--surface-raised); color: var(--text-secondary); }
.nd-badge--success { background: rgba(56, 217, 138, 0.16); color: var(--success); }
.nd-badge--solid { background: var(--accent-fill); color: var(--text-on-red); }
.nd-badge__dot { width: 6px; height: 6px; border-radius: var(--r-pill); background: currentColor; }
.nd-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: var(--w-medium);
  color: var(--text-secondary);
  padding: 6px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  transition: var(--t-hover);
}
.nd-tag--active { color: var(--text-on-red); background: var(--accent-fill); border-color: var(--accent-fill); }

/* Eyebrow */
.nd-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--w-medium);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--text-secondary);
}
.nd-eyebrow__line { width: 32px; height: 2px; background: var(--accent); display: inline-block; }
.nd-eyebrow--gold .nd-eyebrow__line { background: var(--accent-2); }
.nd-eyebrow__num { color: var(--accent); }
.nd-eyebrow--gold .nd-eyebrow__num { color: var(--accent-2); }

/* Meter */
.nd-meter { width: 100%; }
.nd-meter__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.nd-meter__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--text-secondary);
}
.nd-meter__val {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--w-bold);
  color: var(--accent);
}
.nd-meter__track {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--ink-600);
  overflow: hidden;
}
.nd-meter--sm .nd-meter__track { height: 5px; }
.nd-meter__fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width var(--dur-slow) var(--ease-out);
}
.nd-meter--gold .nd-meter__val { color: var(--accent-2); }
.nd-meter--gold .nd-meter__fill { background: var(--accent-2); }

/* Field + Input */
.nd-field { display: flex; flex-direction: column; gap: var(--space-3); }
.nd-field__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--w-medium);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.nd-field__req { color: var(--accent); }
.nd-field__hint { font-size: var(--fs-sm); color: var(--text-tertiary); }
.nd-field__error { font-size: var(--fs-sm); color: var(--danger); font-weight: var(--w-medium); }
.nd-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  color: var(--text-primary);
  background: var(--ink-900);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 0 var(--space-4);
  height: 52px;
  transition: var(--t-hover);
  outline: none;
}
.nd-input::placeholder { color: var(--text-tertiary); }
.nd-input:hover { border-color: var(--border-strong); }
.nd-input:focus { border-color: var(--accent); box-shadow: var(--ring); background: var(--ink-800); }
.nd-input--ta {
  height: auto;
  padding: var(--space-4);
  line-height: var(--lh-normal);
  resize: vertical;
  min-height: 132px;
  font-family: var(--font-body);
}
.nd-input[aria-invalid="true"] { border-color: var(--danger); }
.nd-input:disabled { opacity: 0.5; cursor: not-allowed; }

/* IconButton */
.nd-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--t-hover);
  -webkit-tap-highlight-color: transparent;
}
.nd-iconbtn:hover { color: var(--text-primary); border-color: var(--accent); transform: translateY(-1px); }
.nd-iconbtn:active { transform: translateY(0) scale(0.95); }
.nd-iconbtn:focus-visible { outline: none; box-shadow: var(--ring); }
.nd-iconbtn[disabled] { opacity: 0.4; cursor: not-allowed; transform: none; }
.nd-iconbtn--sm { width: 38px; height: 38px; border-radius: var(--r-xs); }
.nd-iconbtn--solid {
  background: var(--accent-fill);
  color: var(--text-on-red);
  border-color: var(--accent-fill);
  box-shadow: var(--shadow-sm);
}
.nd-iconbtn--solid:hover { background: var(--accent-fill-hover); }
.nd-iconbtn--ghost { border-color: transparent; }
.nd-iconbtn--ghost:hover { background: var(--surface-raised); border-color: transparent; }

/* Card */
.nd-card {
  position: relative;
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-md), var(--inset-top);
  transition: var(--t-hover);
  overflow: hidden;
}
.nd-card--pad-sm { padding: var(--space-4); }
.nd-card--pad-lg { padding: var(--space-7); }
.nd-card--interactive { cursor: pointer; }
.nd-card--interactive:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lg), var(--inset-top);
}
.nd-card--accent::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 3px;
  width: 48px;
  background: var(--accent);
  transition: width var(--dur-base) var(--ease-out);
}
.nd-card--accent.nd-card--interactive:hover::before { width: 100%; }
.nd-card--gold.nd-card--accent::before { background: var(--accent-2); }

/* Data table (admin CRM) — mono headers, hairline rows, hover strip. */
.nd-table {
  width: 100%;
  border-collapse: collapse;
}
.nd-table th {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--w-semibold);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--text-tertiary);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.nd-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
  font-size: var(--fs-sm);
}
.nd-table tbody tr {
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.nd-table tbody tr:hover,
.nd-table tbody tr:focus-within { background: var(--surface-base); }

/* Confirm modal — opaque scrim (no glass), accent-barred card. */
.nd-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: var(--space-5);
}
.nd-modal__scrim {
  position: absolute;
  inset: 0;
  background: var(--surface-overlay);
}
.nd-modal__card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-xl), var(--inset-top);
  overflow: hidden;
}
.nd-modal__card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 2px;
  width: 100%;
  background: var(--accent);
}
@media (prefers-reduced-motion: no-preference) {
  .nd-modal__card { animation: nd-modal-in 0.25s var(--ease-out); }
}
@keyframes nd-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.nd-modal__title {
  font-family: var(--font-display);
  font-size: var(--fs-h4);
  font-weight: var(--w-bold);
  color: var(--text-primary);
  margin: 0 0 var(--space-3);
}
.nd-modal__body {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  line-height: 1.55;
  margin: 0 0 var(--space-5);
}
.nd-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* Toast — icon + message + dismiss; exit animation with a JS timeout
   fallback (see useToast). Color comes from utility classes (bg-success /
   bg-error) so tests and the bridge palette stay authoritative. */
.nd-toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px 10px 14px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: var(--w-medium);
}
.nd-toast > svg { flex: none; }
.nd-toast__x {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  margin-left: 2px;
  border: none;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.nd-toast__x:hover { background: rgba(255, 255, 255, 0.3); }
.nd-toast__x:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
@media (prefers-reduced-motion: no-preference) {
  .nd-toast--out { animation: nd-toast-out 0.18s var(--ease-out) forwards; }
}
@keyframes nd-toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* Skeleton — shimmer sweep (sizing/rounding via utility classes). */
.nd-skeleton {
  background: linear-gradient(100deg, var(--ink-700) 40%, var(--ink-600) 50%, var(--ink-700) 60%);
  background-size: 200% 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .nd-skeleton { animation: nd-shimmer 1.4s linear infinite; }
}
@keyframes nd-shimmer {
  to { background-position: -200% 0; }
}

/* Inline form alert (login, intake datos). */
.nd-form-alert {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* Loader (ring spinner) — a loading indicator is functional, so the spin
   stays on under reduced motion (the global reduce block would zero it;
   the !important keeps it turning). */
.nd-loader { color: var(--accent); }
.nd-loader__arc {
  transform-origin: center;
  animation: nd-spin 0.85s linear infinite !important;
}
@keyframes nd-spin {
  to { transform: rotate(360deg); }
}
