/*
 * Aligner House — design foundation.
 *
 * Propshaft links every file in app/assets/stylesheets alphabetically, so this
 * file loads first: it owns the tokens, the element base, and the browser
 * surfaces. Feature stylesheets consume the --ah-* tokens; their own local
 * variables (--case-*, --dc-*, …) are aliases onto these.
 */

:root {
  color-scheme: light;

  /* Neutrals — cool with a faint teal cast, so the accent belongs to the ground. */
  --ah-bg: #eef1f2;
  --ah-surface: #ffffff;
  --ah-surface-2: #f5f7f7;
  --ah-surface-3: #ebeff0;
  --ah-sidebar: #0b1b1d;
  --ah-border: #e2e7e8;
  --ah-border-strong: #cbd3d5;
  --ah-ink: #0f1719;
  --ah-ink-2: #384446;
  --ah-ink-3: #5b6769;
  --ah-ink-4: #7c878a;
  --ah-placeholder: #6f7b7e;

  /* Accent — the house teal, deepened to carry white text at AA. */
  --ah-accent: #0d7a70;
  --ah-accent-hover: #0a6b62;
  --ah-accent-active: #085a52;
  --ah-accent-soft: #e3f4f1;
  --ah-accent-soft-2: #cce6e2;
  --ah-accent-ink: #09594f;
  --ah-focus-ring: 0 0 0 3px rgba(13, 122, 112, 0.24);

  /* Luminous accent — for dark surfaces, glows and gradient fills. */
  --ah-accent-bright: #2dd4bf;
  --ah-accent-glow: rgba(45, 212, 191, 0.35);
  --ah-accent-grad: linear-gradient(180deg, #14a291 0%, #0d7a70 100%);
  --ah-accent-grad-hover: linear-gradient(180deg, #119384 0%, #0a6b62 100%);

  /* Navigation — the dark rail. */
  --ah-nav-bg: #0b1b1d;
  --ah-nav-bg-2: #0f2427;
  --ah-nav-line: rgba(255, 255, 255, 0.07);
  --ah-nav-text: rgba(236, 244, 244, 0.66);
  --ah-nav-text-strong: #f4f8f8;
  --ah-nav-muted: rgba(236, 244, 244, 0.42);
  --ah-nav-hover: rgba(255, 255, 255, 0.06);
  --ah-nav-active: rgba(45, 212, 191, 0.12);

  /* Semantic */
  --ah-danger: #c0362c;
  --ah-danger-hover: #a52d24;
  --ah-danger-soft: #fcefee;
  --ah-danger-border: #f2c7c3;
  --ah-danger-ink: #9c2a21;
  --ah-warning: #b45d09;
  --ah-warning-soft: #fdf4e6;
  --ah-warning-border: #f3d9b0;
  --ah-success: #1f7a47;
  --ah-success-soft: #e9f5ee;
  --ah-success-border: #c3e3cf;
  --ah-info: #2a61b8;
  --ah-info-soft: #edf2fb;

  /* Workflow stages — one hue per stage, used identically everywhere. */
  --ah-stage-fresh: #8a969a;
  --ah-stage-fresh-soft: #f0f2f3;
  --ah-stage-fresh-ink: #4a5659;
  --ah-stage-segmentation: #3d6fd6;
  --ah-stage-segmentation-soft: #edf2fc;
  --ah-stage-segmentation-ink: #2c54a6;
  --ah-stage-planning: #7b5bd3;
  --ah-stage-planning-soft: #f3effc;
  --ah-stage-planning-ink: #5a3faa;
  --ah-stage-quality_review: #d7720f;
  --ah-stage-quality_review-soft: #fdf3e7;
  --ah-stage-quality_review-ink: #9c520a;
  --ah-stage-ortho_review: #0f8ea6;
  --ah-stage-ortho_review-soft: #e7f5f8;
  --ah-stage-ortho_review-ink: #0b687a;
  --ah-stage-doctor_review: #c19000;
  --ah-stage-doctor_review-soft: #fbf5df;
  --ah-stage-doctor_review-ink: #7f5f00;
  --ah-stage-modification: #d4463b;
  --ah-stage-modification-soft: #fcefee;
  --ah-stage-modification-ink: #a2322a;
  --ah-stage-approved: #2e9858;
  --ah-stage-approved-soft: #e9f5ee;
  --ah-stage-approved-ink: #1d7040;

  /* Type */
  --ah-font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ah-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ah-text-2xs: 0.6875rem;  /* 11 */
  --ah-text-xs: 0.75rem;     /* 12 */
  --ah-text-sm: 0.8125rem;   /* 13 */
  --ah-text-base: 0.875rem;  /* 14 */
  --ah-text-md: 1rem;        /* 16 */
  --ah-text-lg: 1.125rem;    /* 18 */
  --ah-text-xl: 1.375rem;    /* 22 */
  --ah-text-display: 1.875rem; /* 30 */
  --ah-text-2xl: 1.75rem;    /* 28 */
  --ah-weight-regular: 400;
  --ah-weight-medium: 500;
  --ah-weight-semibold: 600;

  /* Space — 4px grid */
  --ah-space-1: 0.25rem;
  --ah-space-2: 0.5rem;
  --ah-space-3: 0.75rem;
  --ah-space-4: 1rem;
  --ah-space-5: 1.25rem;
  --ah-space-6: 1.5rem;
  --ah-space-8: 2rem;
  --ah-space-10: 2.5rem;
  --ah-space-12: 3rem;

  /* Shape & depth — borders carry resting elevation; shadows only for things that float. */
  --ah-radius-xs: 4px;
  --ah-radius-sm: 8px;
  --ah-radius-md: 10px;
  --ah-radius-lg: 14px;
  --ah-radius-xl: 20px;
  --ah-radius-pill: 999px;
  --ah-shadow-xs: 0 1px 2px rgba(10, 26, 28, 0.06);
  --ah-shadow-card: 0 1px 1px rgba(10, 26, 28, 0.03), 0 2px 6px -1px rgba(10, 26, 28, 0.05), 0 14px 36px -14px rgba(10, 26, 28, 0.14);
  --ah-shadow-card-hover: 0 1px 1px rgba(10, 26, 28, 0.04), 0 4px 10px -2px rgba(10, 26, 28, 0.07), 0 22px 48px -16px rgba(10, 26, 28, 0.2);
  --ah-inner-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  /* Double-bezel shell: a tray the white core sits in. */
  --ah-shell-bg: rgba(10, 26, 28, 0.035);
  --ah-shell-ring: 0 0 0 1px rgba(10, 26, 28, 0.06);
  --ah-shell-pad: 5px;
  --ah-shadow-pop: 0 1px 2px rgba(15, 23, 25, 0.06), 0 10px 28px -6px rgba(15, 23, 25, 0.16);
  --ah-shadow-modal: 0 2px 6px rgba(15, 23, 25, 0.06), 0 28px 72px -12px rgba(15, 23, 25, 0.32);

  /* Motion */
  --ah-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ah-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ah-dur-1: 120ms;
  --ah-dur-2: 180ms;
  --ah-dur-3: 260ms;
  --ah-dur-4: 520ms;
  --ah-ease-spring: cubic-bezier(0.32, 0.72, 0, 1);

  /* Layout */
  --ah-sidebar-w: 15rem;
  --ah-gutter: 2rem;
  --ah-topbar-h: 3.25rem;
}

@media (max-width: 1024px) {
  :root { --ah-gutter: 1.5rem; }
}

@media (max-width: 640px) {
  :root { --ah-gutter: 1rem; }
}

/* ── Element base ─────────────────────────────────────────── */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--ah-border-strong) transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--ah-bg);
  color: var(--ah-ink);
  font-family: var(--ah-font);
  font-size: var(--ah-text-base);
  line-height: 1.5;
  font-feature-settings: "ss01" 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}

h1, h2, h3, h4 {
  text-wrap: balance;
  letter-spacing: -0.015em;
}

p {
  text-wrap: pretty;
}

a {
  color: var(--ah-accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button,
a,
label,
summary,
[role="button"] {
  touch-action: manipulation;
}

input,
textarea {
  caret-color: var(--ah-accent);
}

input::placeholder,
textarea::placeholder {
  color: var(--ah-placeholder);
  opacity: 1;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--ah-accent);
}

time,
td,
.ah-num {
  font-variant-numeric: tabular-nums;
}

.ah-mono {
  font-family: var(--ah-mono);
  font-size: 0.93em;
  letter-spacing: -0.01em;
}

::selection {
  background: var(--ah-accent-soft-2);
  color: var(--ah-ink);
}

:focus-visible {
  outline: 2px solid var(--ah-accent);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--ah-border-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--ah-ink-4);
}

::-webkit-scrollbar-track {
  background: transparent;
}

.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* iOS zooms any focused field under 16px; phones get 16px fields. */
@media (max-width: 640px) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* ── Loading states ───────────────────────────────────────── */

/* Turbo navigation progress: a thin accent line, no glow. */
.turbo-progress-bar {
  height: 2px;
  background: var(--ah-accent);
}

/* Turbo marks a submitting form aria-busy; its submit control shows it. */
form[aria-busy="true"] input[type="submit"] {
  opacity: 0.6;
  cursor: progress;
  pointer-events: none;
}

form[aria-busy="true"] button:is([type="submit"], :not([type])) {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

form[aria-busy="true"] button:is([type="submit"], :not([type]))::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  animation: ah-spin 0.7s linear infinite;
}

form[aria-busy="true"] :is(.case-btn--ghost, .case-btn--danger, .auth-btn--secondary)::after {
  border-color: var(--ah-border-strong);
  border-top-color: var(--ah-ink-2);
}

@keyframes ah-spin {
  to { transform: rotate(360deg); }
}

.ah-skeleton {
  display: block;
  border-radius: var(--ah-radius-sm);
  background: linear-gradient(90deg, var(--ah-surface-2) 25%, var(--ah-surface-3) 45%, var(--ah-surface-2) 65%);
  background-size: 300% 100%;
  animation: ah-shimmer 1.4s var(--ah-ease-in-out) infinite;
}

@keyframes ah-shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

/* ── Compact header (full-bleed workspaces, e.g. the treatment chart) ── */

.app-main {
  width: 100%;
  margin: 0;
  padding: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ah-space-4);
  height: var(--ah-topbar-h);
  padding: 0 var(--ah-gutter);
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  background:
    radial-gradient(28rem 8rem at 0% 0%, rgba(45, 212, 191, 0.12), transparent 70%),
    var(--ah-nav-bg);
  border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}

.app-header__brand {
  display: inline-flex;
  align-items: center;
  color: var(--ah-nav-text-strong);
  text-decoration: none;
}

.app-header__brand:hover {
  text-decoration: none;
  color: var(--ah-nav-text-strong);
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--ah-space-2);
}

.app-header__actions form {
  margin: 0;
}

.app-header__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  border: 1px solid var(--ah-nav-line);
  border-radius: var(--ah-radius-sm);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ah-nav-text-strong);
  font-size: var(--ah-text-sm);
  font-weight: var(--ah-weight-medium);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--ah-dur-1), border-color var(--ah-dur-1), color var(--ah-dur-1), transform var(--ah-dur-1) var(--ah-ease-out);
}

.app-header__btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--ah-nav-text);
}

.app-header__btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  text-decoration: none;
}

.app-header__btn:active {
  transform: scale(0.97);
}

@media (max-width: 640px) {
  .app-header__btn span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .app-header__btn {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
  }
}

/* ── Entrance choreography ─────────────────────────────────
   Page blocks rise into place once per navigation; list rows cascade.
   Content is visible by default — the animation only runs from a
   near-final state, so nothing is ever hidden if it fails. */

@keyframes ah-rise {
  from { opacity: 0; transform: translateY(10px); filter: blur(3px); }
}

@keyframes ah-fade {
  from { opacity: 0; }
}

.ah-reveal > * {
  animation: ah-rise var(--ah-dur-4) var(--ah-ease-spring) both;
}

.ah-reveal > *:nth-child(2) { animation-delay: 50ms; }
.ah-reveal > *:nth-child(3) { animation-delay: 100ms; }
.ah-reveal > *:nth-child(4) { animation-delay: 150ms; }
.ah-reveal > *:nth-child(5) { animation-delay: 200ms; }
.ah-reveal > *:nth-child(n+6) { animation-delay: 240ms; }

/* ── Signature surfaces ──────────────────────────────────── */

/* Double-bezel panel: a hairline tray holding a white core. */
.ah-bezel {
  padding: var(--ah-shell-pad);
  border-radius: var(--ah-radius-xl);
  background: var(--ah-shell-bg);
  box-shadow: var(--ah-shell-ring);
}

.ah-bezel__core {
  border-radius: calc(var(--ah-radius-xl) - var(--ah-shell-pad));
  background: var(--ah-surface);
  box-shadow: var(--ah-shadow-card), var(--ah-inner-highlight);
  overflow: hidden;
}

@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;
  }
}
