/* Medipoint Wellness — shared tokens and primitives */

:root {
  --bg: #f3f5ee;
  --bg-deep: #e8ede1;
  --surface: #fbfcf8;
  --surface-2: #f7f9f3;
  --ink: #16301f;
  --ink-2: #44594a;
  --ink-3: #6f8173;
  --line: #dde4d5;
  --line-strong: #c9d3bf;

  --green-900: #12321d;
  --green-800: #1d4a2b;
  --green-700: #275f37;
  --green-600: #2f7342;
  --green-200: #cfe2c6;
  --green-100: #e3eedb;
  --green-50: #eef4e9;

  --amber-ink: #7a4f12;
  --amber-bg: #f6ecd8;
  --red-ink: #9b2c22;
  --red-bg: #f8e4e0;

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --shadow-sm: 0 1px 2px rgb(22 48 31 / 0.06), 0 1px 1px rgb(22 48 31 / 0.04);
  --shadow-md: 0 6px 20px -8px rgb(22 48 31 / 0.18), 0 2px 6px -2px rgb(22 48 31 / 0.08);
  --shadow-lg: 0 24px 60px -20px rgb(18 50 29 / 0.35), 0 8px 20px -10px rgb(18 50 29 / 0.18);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);

  --z-sticky: 10;
  --z-overlay: 20;
  --z-toast: 30;
  --z-grain: 40;

  --container: 1240px;
  --gutter: clamp(16px, 4vw, 40px);

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: var(--scroll-offset, 96px);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

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

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--green-600);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

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

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: var(--z-toast);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--green-800);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  transition: top 200ms var(--ease-out);
}

.skip-link:focus {
  top: 16px;
}

/* Grain: breaks up the flat paper background */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-grain);
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.09 0 0 0 0 0.19 0 0 0 0 0.12 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Buttons */
.btn {
  --btn-bg: var(--surface);
  --btn-ink: var(--ink);
  --btn-line: var(--line-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--btn-line);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 200ms var(--ease-out),
    border-color 200ms var(--ease-out),
    transform 160ms var(--ease-out),
    box-shadow 200ms var(--ease-out);
}

.btn:hover {
  --btn-bg: var(--green-50);
  --btn-line: var(--green-200);
}

.btn:active {
  transform: scale(0.97);
}

.btn[disabled],
.btn[aria-busy="true"] {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  --btn-bg: var(--green-800);
  --btn-ink: #f4f8f0;
  --btn-line: var(--green-800);
  box-shadow: 0 6px 16px -8px rgb(18 50 29 / 0.6), inset 0 1px 0 rgb(255 255 255 / 0.12);
}

.btn--primary:hover {
  --btn-bg: var(--green-700);
  --btn-line: var(--green-700);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-line: transparent;
}

.btn--ghost:hover {
  --btn-bg: var(--green-100);
  --btn-line: transparent;
}

.btn--danger {
  --btn-bg: var(--red-ink);
  --btn-ink: #fff;
  --btn-line: var(--red-ink);
}

.btn--danger:hover {
  --btn-bg: #85241b;
  --btn-line: #85241b;
}

.btn--sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.875rem;
}

.btn--icon {
  width: 44px;
  padding: 0;
}

.btn--icon.btn--sm {
  width: 36px;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn[aria-busy="true"]::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 700ms linear infinite;
}

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

/* Form fields */
.field {
  display: grid;
  gap: 6px;
}

.field__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}

.field__hint {
  font-size: 0.8125rem;
  color: var(--ink-3);
}

.field__error {
  font-size: 0.8125rem;
  color: var(--red-ink);
  font-weight: 500;
}

.field__error:empty {
  display: none;
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 1rem;
  transition:
    border-color 200ms var(--ease-out),
    box-shadow 200ms var(--ease-out),
    background-color 200ms var(--ease-out);
}

.input:hover {
  border-color: var(--ink-3);
}

.input:focus {
  outline: none;
  border-color: var(--green-600);
  box-shadow: 0 0 0 4px rgb(47 115 66 / 0.14);
}

.input[aria-invalid="true"] {
  border-color: var(--red-ink);
  box-shadow: 0 0 0 4px rgb(155 44 34 / 0.1);
}

textarea.input {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}

select.input {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2344594a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

/* Switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch__track {
  position: relative;
  width: 42px;
  height: 24px;
  flex: none;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background-color 220ms var(--ease-out);
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(22 48 31 / 0.25);
  transition: transform 260ms var(--ease-spring);
}

.switch input:checked + .switch__track {
  background: var(--green-600);
}

.switch input:checked + .switch__track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch__track {
  outline: 2px solid var(--green-600);
  outline-offset: 3px;
}

/* Toasts */
.toasts {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: grid;
  gap: 8px;
  width: min(92vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--green-900);
  color: #eef4e9;
  font-size: 0.9375rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 320ms var(--ease-out);
}

.toast--error {
  background: var(--red-ink);
  color: #fff;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms, transform 200ms;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

/* Skeleton shimmer */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-deep);
  border-radius: var(--radius-xs);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.55), transparent);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

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