/*
 * Capilar Journey Design System
 * Semantic tokens and final component normalization.
 * Page-specific styles may control layout, but not invent typography,
 * controls, radii, focus states or interaction colors.
 */

:root {
  /* Typography */
  --cj-font-ui: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --cj-font-brand: "Castoro Titling", Georgia, "Times New Roman", serif;
  --cj-type-display: clamp(2.125rem, 3.2vw, 2.625rem);
  --cj-type-page-title: clamp(1.75rem, 2.6vw, 2.125rem);
  --cj-type-section-title: 1.5rem;
  --cj-type-card-title: 1.125rem;
  --cj-type-emphasis: 1rem;
  --cj-type-body: .9375rem;
  --cj-type-small: .8125rem;
  --cj-type-label: .75rem;
  --cj-weight-regular: 400;
  --cj-weight-medium: 500;
  --cj-weight-semibold: 600;
  --cj-weight-bold: 700;
  --cj-leading-tight: 1.2;
  --cj-leading-heading: 1.3;
  --cj-leading-body: 1.55;

  /* Semantic colors */
  --cj-color-brand-navy: #061633;
  --cj-color-brand-navy-hover: #0d2349;
  --cj-color-interactive: #167eed;
  --cj-color-interactive-hover: #084f9e;
  --cj-color-text: #0a1a3d;
  --cj-color-text-muted: #65718a;
  --cj-color-text-subtle: #8792a3;
  --cj-color-border: #dce4ef;
  --cj-color-border-strong: #bac6d6;
  --cj-color-surface: #ffffff;
  --cj-color-canvas: #f8fafc;
  --cj-color-success: #1e9b45;
  --cj-color-warning: #a66700;
  --cj-color-danger: #bd2833;
  --cj-color-focus: rgba(22, 126, 237, .22);

  /* Spacing */
  --cj-space-1: .25rem;
  --cj-space-2: .5rem;
  --cj-space-3: .75rem;
  --cj-space-4: 1rem;
  --cj-space-5: 1.25rem;
  --cj-space-6: 1.5rem;
  --cj-space-8: 2rem;
  --cj-space-10: 2.5rem;
  --cj-space-12: 3rem;

  /* Shape, elevation and controls */
  --cj-radius-field: .625rem;
  --cj-radius-control: .625rem;
  --cj-radius-card: 1rem;
  --cj-radius-pill: 999px;
  --cj-shadow-1: 0 2px 8px rgba(6, 22, 51, .035);
  --cj-shadow-2: 0 8px 24px rgba(6, 22, 51, .06);
  --cj-shadow-3: 0 16px 40px rgba(6, 22, 51, .10);
  --cj-control-sm: 2.375rem;
  --cj-control-md: 2.75rem;
  --cj-control-lg: 3rem;
  --cj-icon-sm: 1rem;
  --cj-icon-md: 1.25rem;
  --cj-icon-lg: 1.5rem;

  /* Compatibility aliases used by existing modules */
  --cj-navy: var(--cj-color-brand-navy);
  --cj-navy-soft: var(--cj-color-brand-navy-hover);
  --cj-blue: var(--cj-color-interactive);
  --cj-text: var(--cj-color-text);
  --cj-muted: var(--cj-color-text-muted);
  --cj-border: var(--cj-color-border);
  --cj-background: var(--cj-color-canvas);
  --cj-success: var(--cj-color-success);
  --cj-white: var(--cj-color-surface);
}

body.cj-portal-page,
.cj-app,
.cj-app button,
.cj-app input,
.cj-app select,
.cj-app textarea {
  font-family: var(--cj-font-ui);
}

.cj-app {
  color: var(--cj-color-text);
  font-size: var(--cj-type-body);
  font-weight: var(--cj-weight-regular);
  line-height: var(--cj-leading-body);
}

body.cj-portal-page .cj-app :is(p, li, dd, td, blockquote) {
  font-size: var(--cj-type-body);
  font-weight: var(--cj-weight-regular);
}

body.cj-portal-page .cj-app :is(dt, th, label) {
  font-size: var(--cj-type-small);
  font-weight: var(--cj-weight-semibold);
}

body.cj-portal-page .cj-app :is(strong, b) {
  font-weight: var(--cj-weight-semibold);
}

body.cj-portal-page .cj-app :is(h1, h2) {
  font-weight: var(--cj-weight-bold);
}

/* Eight approved typography roles */
.cj-app :is(
  .cj-welcome,
  .cj-evolution-title,
  .cj-treatment-title,
  .cj-appts-heading,
  .cj-guide-heading,
  .cj-faq-heading,
  .cj-success-heading,
  .cj-store-hero,
  .cj-alerts-heading,
  .cj-medical-heading
) h1,
.cj-app .cj-settings-page > .cj-section-heading h1 {
  color: var(--cj-color-text);
  font-size: var(--cj-type-page-title);
  font-weight: var(--cj-weight-bold);
  letter-spacing: -.025em;
  line-height: var(--cj-leading-tight);
}

.cj-app .cj-section-heading h2,
.cj-app .cj-card--progress h2,
.cj-app .cj-guide-featured h2,
.cj-app .cj-faq-recommended__heading h2 {
  font-size: var(--cj-type-section-title);
  font-weight: var(--cj-weight-bold);
  letter-spacing: -.015em;
  line-height: var(--cj-leading-heading);
}

.cj-app :is(
  .cj-medical-section,
  .cj-settings-panel,
  .cj-alert-preferences,
  .cj-alert-summary,
  .cj-evolution-info,
  .cj-treatment-hero,
  .cj-treatment-routine,
  .cj-treatment-recommendations,
  .cj-treatment-side > section,
  .cj-treatment-stages,
  .cj-appts-next,
  .cj-appts-schedule,
  .cj-appts-calendar,
  .cj-appts-clinic,
  .cj-appts-help,
  .cj-appts-prep,
  .cj-appts-history,
  .cj-faq-help,
  .cj-guide-help
) h2,
.cj-app .cj-success-card__copy h2,
.cj-app .cj-guide-card__body h2 {
  font-size: var(--cj-type-card-title);
  font-weight: var(--cj-weight-bold);
  letter-spacing: -.01em;
  line-height: var(--cj-leading-heading);
}

.cj-app :is(h1, h2, h3, h4, h5, h6, strong, b) {
  font-family: var(--cj-font-ui);
}

.cj-app h3 {
  font-size: var(--cj-type-emphasis);
  font-weight: var(--cj-weight-semibold);
  line-height: var(--cj-leading-heading);
}

.cj-app p,
.cj-app li,
.cj-app dd,
.cj-app td {
  line-height: var(--cj-leading-body);
}

.cj-app :is(
  .cj-welcome > p:last-child,
  .cj-evolution-title > p,
  .cj-treatment-title > p,
  .cj-appts-heading > p,
  .cj-guide-heading > div > p:last-child,
  .cj-faq-heading > div > p:last-child,
  .cj-success-heading > p:last-child,
  .cj-alerts-heading > div > p,
  .cj-medical-heading > div > p,
  .cj-settings-page > .cj-section-heading p
) {
  color: var(--cj-color-text-muted);
  font-size: var(--cj-type-emphasis);
  font-weight: var(--cj-weight-regular);
  line-height: var(--cj-leading-body);
}

.cj-app :is(small, figcaption, .cj-caption, .cj-meta) {
  color: var(--cj-color-text-muted);
  font-size: var(--cj-type-small);
  line-height: 1.45;
}

body.cj-portal-page .cj-app :is(
  .cj-nav a,
  .cj-header__medical-link,
  .cj-profile-popover a
) {
  font-size: var(--cj-type-body);
  font-weight: var(--cj-weight-semibold);
}

/* Legal links remain intentionally secondary inside the account popover. */
body.cj-portal-page .cj-app .cj-profile-popover__legal a {
  font-size: 10px;
  font-weight: var(--cj-weight-regular);
  line-height: 1.2;
}

body.cj-portal-page .cj-app :is(
  .cj-footer__column span,
  .cj-footer__bottom,
  .cj-confidentiality,
  .cj-settings-actions p,
  .cj-success-legal
) {
  font-size: var(--cj-type-small);
  line-height: 1.45;
}

body.cj-portal-page .cj-app .cj-footer__column h2 {
  font-size: var(--cj-type-label);
  font-weight: var(--cj-weight-semibold);
  line-height: 1.3;
}

body.cj-portal-page .cj-app :is(
  .cj-card-link,
  .cj-section-heading > a,
  .cj-medical-section > header > a,
  .cj-evolution-tip a,
  .cj-evolution-info > a:not(.cj-button),
  .cj-success-card__copy button,
  .cj-guide-card__body button
) {
  font-size: var(--cj-type-small);
  font-weight: var(--cj-weight-semibold);
  line-height: 1.4;
}

body.cj-portal-page .cj-app :is(
  .cj-guide-filters,
  .cj-faq-tabs,
  .cj-alert-filters,
  .cj-appts-tabs
) :is(button, a) {
  font-size: var(--cj-type-small);
  font-weight: var(--cj-weight-semibold);
}

body.cj-portal-page .cj-app :is(
  .cj-progress-ring,
  .cj-evolution-ring
) strong {
  font-size: var(--cj-type-display);
  font-weight: var(--cj-weight-bold);
  line-height: 1;
}

body.cj-portal-page .cj-app .cj-appts-date strong {
  font-size: var(--cj-type-section-title);
  font-weight: var(--cj-weight-bold);
}

body.cj-portal-page .cj-app :is(
  .cj-medical-table,
  .cj-appts-history__table,
  .cj-treatment-step__time,
  .cj-treatment-step__copy p,
  .cj-treatment-products small,
  .cj-treatment-stages small,
  .cj-alert-item small,
  .cj-medical-documents small
) {
  font-size: var(--cj-type-small);
}

body.cj-portal-page .cj-app :is(
  .cj-treatment-step select,
  .cj-treatment-products em,
  .cj-medical-table em,
  .cj-appts-status,
  .cj-appointment-badge
) {
  font-size: var(--cj-type-label);
  font-weight: var(--cj-weight-semibold);
}

.cj-app :is(
  .cj-eyebrow,
  .cj-guide-badge,
  .cj-appts-status,
  .cj-appointment-badge,
  .cj-alert-item__read,
  .cj-medical-table em,
  .cj-treatment-products em
) {
  font-size: var(--cj-type-label);
  font-weight: var(--cj-weight-semibold);
  line-height: 1.3;
}

/* Buttons: one typography, three approved heights */
body.cj-portal-page .cj-app .cj-button {
  border-radius: var(--cj-radius-control);
  font-family: var(--cj-font-ui);
  font-size: .875rem;
  font-weight: var(--cj-weight-semibold);
  line-height: 1.25;
  min-height: var(--cj-control-md);
  padding: .625rem 1.125rem;
}

body.cj-portal-page .cj-app :is(
  .cj-treatment-help,
  .cj-alert-preferences,
  .cj-appts-actions,
  .cj-photo-actions
) .cj-button,
body.cj-portal-page .cj-app .cj-medical-upload > summary {
  font-size: var(--cj-type-small);
  font-weight: var(--cj-weight-semibold);
  min-height: var(--cj-control-sm);
}

body.cj-portal-page .cj-app .cj-treatment-help .cj-button {
  font-size: .875rem;
  font-weight: var(--cj-weight-semibold);
  min-height: var(--cj-control-md);
  padding: .625rem 1rem;
}

body.cj-portal-page .cj-app :is(
  .cj-progress-action,
  .cj-evolution-help,
  .cj-guide-help,
  .cj-faq-help
) .cj-button {
  min-height: var(--cj-control-lg);
}

.cj-app .cj-evolution-help.cj-guide-help {
  align-items: center;
  background: #eef4ff;
  border: 1px solid #cfddf2;
  border-radius: var(--cj-radius-card);
  display: flex;
  gap: var(--cj-space-6);
  justify-content: space-between;
  margin-top: var(--cj-space-8);
  padding: 1.375rem;
}

.cj-app .cj-evolution-help.cj-guide-help > div {
  align-items: center;
  display: flex;
  gap: var(--cj-space-3);
}

.cj-app .cj-evolution-help.cj-guide-help h2 {
  font-size: var(--cj-type-card-title);
  font-weight: var(--cj-weight-bold);
  margin: 0 0 var(--cj-space-1);
}

.cj-app .cj-evolution-help.cj-guide-help p {
  color: var(--cj-color-text-muted);
  font-size: var(--cj-type-body);
  margin: 0;
}

.cj-app .cj-evolution-help.cj-guide-help .cj-button {
  white-space: nowrap;
}

.cj-app .cj-evolution-info--weeks li {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cj-app .cj-button:disabled,
.cj-app .cj-button.is-disabled {
  cursor: not-allowed;
  opacity: .5;
}

/* Inputs and labels */
.cj-app :is(.cj-portal-form, .cj-personal-form, .cj-password-form) label > span,
.cj-app .cj-field-label {
  color: #344866;
  font-size: var(--cj-type-small);
  font-weight: var(--cj-weight-semibold);
  line-height: 1.35;
}

body.cj-portal-page .cj-app :is(
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="date"],
  input[type="number"],
  input[type="search"],
  select,
  textarea
) {
  border-color: var(--cj-color-border-strong);
  border-radius: var(--cj-radius-field);
  color: var(--cj-color-text);
  font-size: var(--cj-type-body);
  font-weight: var(--cj-weight-regular);
  line-height: 1.35;
  min-height: var(--cj-control-md);
}

body.cj-portal-page .cj-app :is(
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="date"],
  input[type="number"],
  input[type="search"],
  select,
  textarea
):focus {
  border-color: var(--cj-color-interactive);
  box-shadow: 0 0 0 3px var(--cj-color-focus);
  outline: 0;
}

.cj-app input::placeholder,
.cj-app textarea::placeholder {
  color: var(--cj-color-text-subtle);
  font-size: inherit;
}

.cj-app input[type="file"],
.cj-app input[type="file"]::file-selector-button {
  font-family: var(--cj-font-ui);
  font-size: var(--cj-type-small);
}

/* Cards and surfaces */
.cj-app :is(
  .cj-card,
  .cj-settings-panel,
  .cj-medical-section,
  .cj-alert-preferences,
  .cj-alert-summary
) {
  border-color: var(--cj-color-border);
  border-radius: var(--cj-radius-card);
  box-shadow: var(--cj-shadow-1);
}

/* Interactive text */
.cj-app a:not(.cj-button),
.cj-app button:not(.cj-button) {
  transition: color .18s ease, background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.cj-app :is(
  .cj-card-link,
  .cj-section-heading > a,
  .cj-medical-section > header > a,
  .cj-evolution-tip a,
  .cj-evolution-info > a,
  .cj-success-card__copy button,
  .cj-guide-card__body button
):hover,
.cj-app :is(
  .cj-card-link,
  .cj-section-heading > a,
  .cj-medical-section > header > a,
  .cj-evolution-tip a,
  .cj-evolution-info > a,
  .cj-success-card__copy button,
  .cj-guide-card__body button
):focus-visible {
  color: var(--cj-color-interactive-hover);
}

.cj-app :is(a, button, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--cj-color-focus);
  outline-offset: 3px;
}

/* Icon scale: 16, 20 or 24 px only */
.cj-app .cj-lucide-icon {
  height: var(--cj-icon-md);
  width: var(--cj-icon-md);
}

.cj-app :is(.cj-button, small, .cj-caption, .cj-meta) .cj-lucide-icon {
  height: var(--cj-icon-sm);
  width: var(--cj-icon-sm);
}

.cj-app :is(.cj-nav, .cj-header__actions, .cj-alerts-heading__icon) .cj-lucide-icon {
  height: var(--cj-icon-lg);
  width: var(--cj-icon-lg);
}

@media (max-width: 680px) {
  :root {
    --cj-type-page-title: 1.75rem;
    --cj-type-section-title: 1.3125rem;
    --cj-type-card-title: 1.0625rem;
  }

  body.cj-portal-page .cj-app .cj-button {
    min-height: var(--cj-control-md);
  }

  .cj-app .cj-evolution-help.cj-guide-help,
  .cj-app .cj-evolution-help.cj-guide-help > div:last-child {
    align-items: stretch;
    flex-direction: column;
  }

  .cj-app .cj-evolution-help.cj-guide-help .cj-button {
    width: 100%;
  }

  .cj-app .cj-evolution-info--weeks li {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cj-app *,
  .cj-app *::before,
  .cj-app *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
