/* ==========================================================================
   TeleTonicMD Patient Portal — foundation stylesheet
   Consumes brand-tokens.css (link it BEFORE this file). Provides the shell
   (header/nav/footer), component library (cards, buttons, inputs, chips,
   list rows), and the perceived-performance kit (skeletons, toasts, empty
   states). Every portal page (login, dashboard, visit, billing, intake,
   ai-assistant, signup, reset) migrates onto these classes.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: var(--text-body);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--serif); color: var(--ink); font-weight: 500; line-height: 1.2; margin: 0; }
a { color: var(--label); text-decoration: none; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }

/* ---- App shell -------------------------------------------------------- */
.p-app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; position: relative; z-index: 1; }

.p-header {
  position: sticky; top: 0; z-index: 100;
  height: 64px; display: flex; align-items: center; gap: 1rem;
  padding: 0 clamp(1rem, 4vw, 2rem);
  background: rgba(251, 249, 244, 0.85);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--hairline);
}
.p-lockup { display: flex; align-items: center; gap: 0.6rem; }
.p-lockup .icon { width: 26px; height: 26px; color: var(--action); }
.p-wordmark { font-family: var(--serif); font-size: 1.15rem; font-weight: 500; color: var(--ink); letter-spacing: -0.01em; }
.p-header-spacer { flex: 1; }
.p-avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: var(--sage); border: 1px solid var(--hairline);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 600; color: var(--action);
}

/* ---- Layout: sidebar + content --------------------------------------- */
.p-shell { flex: 1; display: grid; grid-template-columns: 248px 1fr; gap: 0; }
.p-sidebar {
  padding: 1.5rem 1rem; border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; gap: 0.15rem;
}
.p-nav-item {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-weight: 500; font-size: 0.95rem;
  transition: background-color var(--dur-fast) var(--ease-luxe), color var(--dur-fast) ease;
}
.p-nav-item .icon { width: 20px; height: 20px; color: currentColor; }
.p-nav-item:hover { background: var(--ink-wash); color: var(--ink); }
.p-nav-item[aria-current="page"] { background: var(--sage-tint); color: var(--action); }
.p-nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--action); color: var(--cream);
  font-size: 0.7rem; font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.p-content { padding: clamp(1.5rem, 4vw, 2.5rem); max-width: 920px; }
.p-page-title { font-size: var(--text-h2); letter-spacing: -0.015em; margin-bottom: 0.35rem; }
.p-eyebrow { font-size: var(--text-xs); font-weight: 600; letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--label); margin-bottom: 0.6rem; }

/* ---- Cards ------------------------------------------------------------ */
.p-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-paper); padding: 1.5rem 1.6rem;
}
.p-card--ink { background: var(--ink); color: var(--on-ink); box-shadow: var(--shadow-lg); }
.p-card--ink h1, .p-card--ink h2, .p-card--ink h3 { color: var(--cream); }
.p-card--sage { background: var(--sage-tint); box-shadow: none; border: 1px solid var(--sage-deep); }

/* ---- Buttons ---------------------------------------------------------- */
.p-btn {
  --btn-shadow: 0 1px 2px rgba(30,59,49,.08), 0 2px 8px rgba(30,59,49,.06);
  --btn-shadow-hover: 0 2px 4px rgba(30,59,49,.12), 0 9px 22px rgba(30,59,49,.14);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font-family: var(--sans); font-size: 0.82rem; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.85rem 1.6rem; border-radius: var(--radius-pill);
  border: 1px solid transparent; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--dur-fast) var(--ease-luxe), box-shadow var(--dur-base) var(--ease-luxe), background-color var(--dur-fast) var(--ease-luxe), color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.p-btn:hover { transform: translateY(-1px); }
.p-btn:active { transform: translateY(0); transition-duration: 0.08s; }
.p-btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }
.p-btn .icon { width: 18px; height: 18px; }
.p-btn--primary { background: var(--ink); color: var(--cream); box-shadow: var(--btn-shadow); }
.p-btn--primary:hover { background: var(--action-hover); box-shadow: var(--btn-shadow-hover); }
.p-btn--ghost { background: transparent; color: var(--ink); border-color: var(--hairline-strong); box-shadow: 0 1px 1px rgba(30,59,49,.03); }
.p-btn--ghost:hover { background: var(--ink-wash); color: var(--ink); border-color: var(--ink); box-shadow: var(--btn-shadow); }
.p-btn--on-ink { background: var(--cream); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.18), 0 7px 20px rgba(0,0,0,.22); }
.p-btn--on-ink:hover { background: #fff; }
.p-btn:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }
.p-btn--full { width: 100%; }
@media (prefers-reduced-motion: reduce) {
  .p-btn { transition: background-color .2s ease, border-color .2s ease, color .2s ease; }
  .p-btn:hover, .p-btn:active { transform: none; }
}

/* ---- Inputs ----------------------------------------------------------- */
.p-field { margin-bottom: 1.25rem; }
.p-label { display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.45rem; }
.p-input, .p-select, .p-textarea {
  width: 100%; padding: 0.85rem 1rem; font-family: var(--sans); font-size: 1rem;
  color: var(--text-primary); background: var(--white);
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.p-input:focus, .p-select:focus, .p-textarea:focus {
  outline: none; border-color: var(--action); box-shadow: var(--ring-action);
}
.p-input::placeholder { color: var(--text-muted); }
.p-field-error { color: var(--error); font-size: 0.82rem; margin-top: 0.4rem; }

/* ---- Chips / status --------------------------------------------------- */
.p-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0.3rem 0.7rem; border-radius: 999px; white-space: nowrap;
}
.p-chip .icon { width: 13px; height: 13px; }
.p-chip--good { background: var(--sage-deep); color: var(--success); }
.p-chip--attention { background: var(--apricot); color: var(--apricot-text); }
.p-chip--act { background: var(--error-bg); color: var(--error-text); }
.p-chip--neutral { background: var(--sand); color: var(--text-secondary); }
.p-chip--info { background: var(--powder-tint); color: var(--info-text); }

/* ---- List rows (appointments, meds, transactions) -------------------- */
.p-row {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.1rem 0; border-bottom: 1px solid var(--hairline);
}
.p-row:last-child { border-bottom: none; }
.p-datebox {
  flex-shrink: 0; width: 56px; height: 56px; border-radius: var(--radius-sm);
  background: var(--sage-tint); display: flex; flex-direction: column;
  align-items: center; justify-content: center; line-height: 1;
}
.p-datebox .d { font-family: var(--serif); font-size: 1.35rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.p-datebox .m { font-size: 0.6rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--label); margin-top: 2px; }
.p-row-main { flex: 1; min-width: 0; }
.p-row-title { font-weight: 600; color: var(--ink); }
.p-row-meta { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }
.p-amount { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

/* ---- Skeletons -------------------------------------------------------- */
.p-skel {
  background: linear-gradient(90deg, var(--sand) 25%, #EFE9DE 37%, var(--sand) 63%);
  background-size: 400% 100%; animation: p-shimmer 1.4s ease infinite;
  border-radius: 8px;
}
.p-skel--line { height: 0.9em; margin: 0.4em 0; }
.p-skel--title { height: 1.4em; width: 55%; }
.p-skel--card { height: 84px; }
@keyframes p-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---- Empty states ----------------------------------------------------- */
.p-empty { text-align: center; padding: 3rem 1.5rem; max-width: 34rem; margin: 0 auto; }
.p-empty img, .p-empty svg.illus { width: 120px; height: auto; margin: 0 auto 1.25rem; display: block; opacity: 0.9; }
.p-empty h3 { font-size: 1.3rem; margin-bottom: 0.5rem; }
.p-empty p { color: var(--text-muted); margin: 0 0 1.5rem; }

/* ---- Toasts: defined in motion.css (shared with the marketing site) --- */

/* ---- Session / modal dialog ------------------------------------------ */
.p-modal-backdrop {
  position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; background: rgba(30, 59, 49, 0.4); backdrop-filter: blur(4px);
  animation: p-fade var(--dur-base) ease both;
}
.p-modal { background: var(--cream); border-radius: var(--radius-lg); padding: 2rem; max-width: 420px; width: 100%; box-shadow: var(--shadow-xl); animation: p-modal-in var(--dur-base) var(--ease-luxe) both; }
@keyframes p-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes p-modal-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---- Alert / notice banner -------------------------------------------
   Full-width tinted bar with a left icon slot. Add the .p-alert classes to
   an element whose className you control. For elements whose className is
   overwritten by JS (billing #notice-banner, reset #msg) style the legacy
   name page-side instead. Default the element to hidden where the JS toggles
   inline style.display (login #alert). */
.p-alert {
  display: flex; align-items: flex-start; gap: 0.65rem;
  padding: 0.85rem 1.05rem; border-radius: var(--radius-sm);
  font-size: 0.9rem; line-height: 1.5; border: 1px solid transparent;
}
.p-alert .icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.p-alert--good      { background: var(--success-bg); border-color: var(--sage-deep); color: var(--success); }
.p-alert--info      { background: var(--powder-tint); border-color: var(--info-border); color: var(--info-text); }
.p-alert--neutral   { background: var(--sand); border-color: var(--hairline); color: var(--text-secondary); }
.p-alert--attention { background: var(--apricot); border-color: var(--apricot-text); color: var(--apricot-text); }
.p-alert--error     { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }

/* ---- Avatar: photo variant + sizes -----------------------------------
   The patient header avatar is a monogram (initials). Dr. Afzal's portrait
   uses --photo (object-position focuses her face in a 3:4 source) at a
   context-appropriate size. */
.p-avatar--photo { object-position: 50% 20%; }
.p-avatar--md { width: 44px; height: 44px; }
.p-avatar--lg { width: 56px; height: 56px; }
.p-avatar--xl { width: 72px; height: 72px; font-size: 1.15rem; }

/* ---- Auth pages (login, signup, reset): centered card ----------------- */
.p-auth {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2.5rem 1.25rem; background: var(--cream);
}
.p-auth-card { width: 100%; max-width: 440px; padding: clamp(1.75rem, 5vw, 2.75rem); position: relative; z-index: 1; }
.p-auth-card--wide { max-width: 620px; }
.p-auth .p-alert { margin-bottom: var(--space-3); }
.p-auth-brand { text-align: center; margin-bottom: var(--space-4); }
.p-auth-mark { width: 136px; height: 136px; display: block; margin: 0 auto 1.25rem; filter: drop-shadow(0 10px 22px rgba(30, 59, 49, 0.16)); }
.p-auth-brand h1 { font-family: var(--serif); font-weight: 500; font-size: 1.9rem; color: var(--ink); letter-spacing: -0.02em; margin: 0 0 0.35rem; }
.p-auth-brand .p-eyebrow { margin-bottom: 0; }
.p-password { position: relative; }
.p-password .p-input { padding-right: 4.25rem; }
.p-reveal {
  position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 0.35rem 0.5rem;
  font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--label);
  border-radius: var(--radius-xs);
}
.p-reveal:hover { color: var(--action); }
.p-auth-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 1.1rem; margin-top: var(--space-4); font-size: 0.88rem; }
.p-auth-links a { color: var(--label); font-weight: 500; }
.p-auth-links a:hover { color: var(--ink); }
.p-auth-secure { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-top: var(--space-3); color: var(--text-muted); font-size: 0.82rem; }
.p-auth-secure .icon { width: 15px; height: 15px; color: var(--label); }
.p-auth-sub { text-align: center; color: var(--text-secondary); font-size: 0.95rem; line-height: 1.55; margin: -0.5rem 0 1.5rem; }
.p-auth-note { display: flex; align-items: flex-start; justify-content: center; gap: 0.45rem; text-align: center; color: var(--text-muted); font-size: 0.78rem; line-height: 1.5; margin-top: 1rem; }
.p-auth-note .icon { width: 14px; height: 14px; color: var(--label); flex-shrink: 0; margin-top: 2px; }

/* ---- Motion opt-out --------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .p-skel { animation: none; background: var(--sand); }
  .p-toast, .p-modal, .p-modal-backdrop { animation-duration: 0.01ms; }
  * { scroll-behavior: auto !important; }
}

/* ---- Mobile: bottom tab bar ------------------------------------------ */
@media (max-width: 768px) {
  .p-shell { grid-template-columns: 1fr; }
  .p-sidebar { display: none; }
  .p-content { padding: 1.25rem 1.1rem 5.5rem; max-width: none; }
  .p-tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    display: flex; height: calc(60px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(251, 249, 244, 0.94); backdrop-filter: blur(16px);
    border-top: 1px solid var(--hairline);
  }
  .p-tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text-muted); font-size: 0.62rem; font-weight: 600; letter-spacing: 0.03em; }
  .p-tab .icon { width: 22px; height: 22px; }
  .p-tab[aria-current="page"] { color: var(--action); }
}
@media (min-width: 769px) { .p-tabbar { display: none; } }

/* Brand mark image (new hands+plant logo) — keeps aspect within its box */
.brandmark { object-fit: contain; }
.p-lockup .brandmark { width: 40px; height: 40px; }

/* ── Brand watermark ───────────────────────────────────────────────────
   Ghosted pine->gold line drawing of the logo (hands cradling the leafy
   bouquet), traced from the mark. position:fixed so it persists on scroll,
   behind the card/content (the auth card sits at z-index 1), pointer-events
   none, aria-hidden. Purely presentational — no JS/contract touched. */
.page-watermark {
  position: fixed;
  top: 1vh;
  right: -3vw;
  width: min(45vw, 580px);
  z-index: 0;
  pointer-events: none;
  transform: rotate(-4deg);
  opacity: 0.17;
}
.page-watermark svg { display: block; width: 100%; height: auto; overflow: visible; }
.page-watermark path {
  fill: none;
  stroke: url(#ttmd-wm-grad);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  stroke-linecap: round;
}
