/* AssignedHealth — Design System stylesheet
   Tokens mirror design/DESIGN-SYSTEM.md. Re-theming = edit :root. */

/* Inter (optional; system stack is the fallback and reads correctly offline) */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap");

/* ----------------------------------------------------------------------------
   1. Tokens
---------------------------------------------------------------------------- */
:root {
  /* neutrals */
  --c-canvas: #f7f6f3;
  --c-surface: #ffffff;
  --c-surface-2: #f1efea;
  --c-border: #e2dfd8;
  --c-border-strong: #cbc7bd;
  --c-text: #1f2a2e;
  --c-text-muted: #5b6770;
  --c-text-subtle: #7e8890;

  /* primary */
  --c-primary: #1f6f78;
  --c-primary-hover: #185a62;
  --c-primary-soft: #e3f0f1;
  --c-on-primary: #ffffff;

  /* accent */
  --c-accent: #b5734a;

  /* status */
  --c-status-assigned: #2c5c8a;
  --c-status-assigned-bg: #e6eef6;
  --c-status-done: #2f6b4f;
  --c-status-done-bg: #e4f0e9;
  --c-status-late: #8a5a1c;
  --c-status-late-bg: #f6ecdd;

  /* feedback */
  --c-danger: #9a3329;
  --c-focus: #1f6f78;

  /* type */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --fs-display: 30px;
  --fs-h1: 24px;
  --fs-h2: 19px;
  --fs-h3: 16px;
  --fs-body: 16px;
  --fs-small: 14px;
  --fs-xs: 12.5px;

  /* space */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  /* radius */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;

  /* shadow */
  --shadow-sm: 0 1px 2px rgba(31, 42, 46, 0.06);
  --shadow-md: 0 2px 8px rgba(31, 42, 46, 0.08);
  --shadow-lg: 0 8px 24px rgba(31, 42, 46, 0.10);

  /* motion */
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
}

/* ----------------------------------------------------------------------------
   2. Base / reset
---------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--c-text);
  background: var(--c-canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--fs-h1); line-height: 1.25; font-weight: 600; }
h2 { font-size: var(--fs-h2); line-height: 1.3; font-weight: 600; }
h3 { font-size: var(--fs-h3); line-height: 1.4; font-weight: 600; }

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

small { font-size: var(--fs-small); }

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

:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.muted { color: var(--c-text-muted); }
.subtle { color: var(--c-text-subtle); }
.meta { font-size: var(--fs-small); color: var(--c-text-subtle); }
.stack > * + * { margin-top: var(--s-4); }
.stack-sm > * + * { margin-top: var(--s-2); }
.center { text-align: center; }

/* ----------------------------------------------------------------------------
   3. Page shells
---------------------------------------------------------------------------- */
.page { min-height: 100vh; display: flex; flex-direction: column; }

.page__main {
  width: 100%;
  margin: 0 auto;
  padding: var(--s-6) var(--s-5);
  flex: 1;
}
.page--app .page__main { max-width: 960px; }
.page--form .page__main { max-width: 640px; }

/* Client mobile frame */
.page--mobile { background: var(--c-canvas); }
.page--mobile .page__main {
  max-width: 420px;
  padding: var(--s-5) var(--s-4) var(--s-7);
}

.page-head { margin-bottom: var(--s-5); }
.page-head h1 { margin-bottom: var(--s-1); }
.page-head p { color: var(--c-text-muted); }

/* ----------------------------------------------------------------------------
   4. App header (therapist)
---------------------------------------------------------------------------- */
.app-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header__inner {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--s-3) var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-4);
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 600;
  font-size: var(--fs-h3);
  color: var(--c-text);
}
.wordmark:hover { text-decoration: none; }
.wordmark__bridge { width: 22px; height: 22px; display: inline-block; vertical-align: -4px; }
.app-header__spacer { flex: 1; }
.app-header__account {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-small); color: var(--c-text-muted);
}
.avatar {
  width: 32px; height: 32px; border-radius: var(--r-pill);
  background: var(--c-primary-soft); color: var(--c-primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: var(--fs-small);
}

/* ----------------------------------------------------------------------------
   5. Buttons
---------------------------------------------------------------------------- */
.btn {
  --btn-bg: var(--c-surface);
  --btn-fg: var(--c-text);
  --btn-bd: var(--c-border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: 0 var(--s-5);
  font: inherit; font-size: var(--fs-body); font-weight: 500;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn--primary {
  --btn-bg: var(--c-primary);
  --btn-fg: var(--c-on-primary);
  --btn-bd: var(--c-primary);
}
.btn--primary:hover { --btn-bg: var(--c-primary-hover); --btn-bd: var(--c-primary-hover); }

.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--c-primary); }
.btn--ghost:hover { --btn-bg: var(--c-primary-soft); }

.btn--danger { --btn-fg: var(--c-danger); --btn-bd: var(--c-border-strong); }
.btn--danger:hover { --btn-bg: #f7ece9; }

.btn--block { width: 100%; }

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

/* ----------------------------------------------------------------------------
   6. Cards
---------------------------------------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--s-5);
}
.card--pad-lg { padding: var(--s-6); }
.card--interactive { transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.card--interactive:hover { box-shadow: var(--shadow-md); border-color: var(--c-border-strong); }

/* ----------------------------------------------------------------------------
   7. Status badge
---------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 3px 10px;
  font-size: var(--fs-xs); font-weight: 500; line-height: 1.4;
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: var(--r-pill); background: currentColor; opacity: 0.9; }
.badge--assigned { color: var(--c-status-assigned); background: var(--c-status-assigned-bg); }
.badge--done { color: var(--c-status-done); background: var(--c-status-done-bg); }
.badge--late { color: var(--c-status-late); background: var(--c-status-late-bg); }

/* ----------------------------------------------------------------------------
   8. Task list (dashboard core)
---------------------------------------------------------------------------- */
.toolbar {
  display: flex; align-items: center; gap: var(--s-3);
  margin-bottom: var(--s-4); flex-wrap: wrap;
}
.toolbar__spacer { flex: 1; }

.filterbar { display: inline-flex; gap: var(--s-1); background: var(--c-surface-2); padding: var(--s-1); border-radius: var(--r-pill); }
.filterbar__btn {
  border: 0; background: transparent; font: inherit; font-size: var(--fs-small); font-weight: 500;
  color: var(--c-text-muted); padding: 6px var(--s-3); border-radius: var(--r-pill); cursor: pointer;
}
.filterbar__btn[aria-pressed="true"] { background: var(--c-surface); color: var(--c-text); box-shadow: var(--shadow-sm); }

.task-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--c-border); border-radius: var(--r-lg); background: var(--c-surface); overflow: hidden; }
.task-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--s-2) var(--s-4);
  align-items: center;
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--c-border);
  text-decoration: none; color: inherit;
  transition: background var(--dur-fast) var(--ease);
}
.task-row:last-child { border-bottom: 0; }
.task-row:hover { background: var(--c-surface-2); text-decoration: none; }
.task-row__main { min-width: 0; }
.task-row__client { display: block; font-weight: 600; }
.task-row__prompt { display: block; color: var(--c-text-muted); font-size: var(--fs-small); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-row__side { display: flex; flex-direction: column; align-items: flex-end; gap: var(--s-1); }
.task-row__date { font-size: var(--fs-xs); color: var(--c-text-subtle); }

/* family grouping (therapist sees a household together) */
.family-group { margin-bottom: var(--s-6); }
.family-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-1) var(--s-3);
}
.family-head__title { display: flex; align-items: center; gap: var(--s-2); font-weight: 600; }
.family-head__icon {
  width: 26px; height: 26px; border-radius: var(--r-sm);
  background: var(--c-primary-soft); color: var(--c-primary);
  display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex: none;
}
.family-head__meta { font-size: var(--fs-small); color: var(--c-text-subtle); }
.family-head__spacer { flex: 1; }

/* avatar cluster for household members */
.avatars { display: inline-flex; }
.avatars .avatar { width: 28px; height: 28px; font-size: var(--fs-xs); border: 2px solid var(--c-surface); }
.avatars .avatar + .avatar { margin-left: -8px; }

/* member block on the family view */
.member { padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--c-border); }
.member:last-child { border-bottom: 0; }
.member__head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); }
.member__name { font-weight: 600; }
.member__role { font-size: var(--fs-xs); color: var(--c-text-subtle); }
.member__tasks { list-style: none; margin: 0; padding: 0; }
.member__task {
  display: grid; grid-template-columns: 1fr auto; gap: var(--s-2) var(--s-4); align-items: center;
  padding: var(--s-2) 0; text-decoration: none; color: inherit;
}
.member__task + .member__task { border-top: 1px dashed var(--c-border); }
.member__task > .task-row__prompt { min-width: 0; }
.member__task:hover .task-row__prompt { color: var(--c-text); }

/* ----------------------------------------------------------------------------
   9. Forms
---------------------------------------------------------------------------- */
.field { display: block; margin-bottom: var(--s-5); }
.field__label { display: block; font-size: var(--fs-small); font-weight: 500; color: var(--c-text); margin-bottom: var(--s-2); }
.field__req { color: var(--c-danger); }
.field__hint { font-size: var(--fs-small); color: var(--c-text-subtle); margin-top: var(--s-2); }

.input, .textarea, .select {
  width: 100%;
  font: inherit; font-size: var(--fs-body);
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  padding: 11px var(--s-3);
  min-height: 44px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.textarea { min-height: 132px; resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--c-text-subtle); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235b6770' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right var(--s-3) center; padding-right: var(--s-7); }

.form-actions { display: flex; gap: var(--s-3); margin-top: var(--s-6); }
.form-actions--end { justify-content: flex-end; }

/* choice group (radios / checkboxes) */
.choice {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--c-border); border-radius: var(--r-md);
  cursor: pointer; min-height: 44px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.choice + .choice { margin-top: var(--s-2); }
.choice:hover { background: var(--c-surface-2); }
.choice input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--c-primary); flex: none; }
.choice:has(input:checked) { border-color: var(--c-primary); background: var(--c-primary-soft); }
.choice__label { font-weight: 500; }
.choice__desc { font-size: var(--fs-small); color: var(--c-text-muted); }

/* ----------------------------------------------------------------------------
   10. File upload + attachment chip
---------------------------------------------------------------------------- */
.upload {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  text-align: center;
  padding: var(--s-5);
  border: 1.5px dashed var(--c-border-strong);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  cursor: pointer; min-height: 44px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.upload:hover { border-color: var(--c-primary); background: var(--c-primary-soft); }
.upload__icon { font-size: 22px; }
.upload__hint { font-size: var(--fs-small); color: var(--c-text-muted); }

.chip {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--r-md);
  font-size: var(--fs-small);
}
.chip__icon {
  width: 26px; height: 26px; border-radius: var(--r-sm);
  background: #f0e7df; color: var(--c-accent);
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600;
  flex: none;
}
.chip__name { font-weight: 500; }
.chip__meta { color: var(--c-text-subtle); }

/* ----------------------------------------------------------------------------
   11. Consent block
---------------------------------------------------------------------------- */
.consent {
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  padding: var(--s-5);
}
.consent__notice { font-size: var(--fs-small); color: var(--c-text-muted); line-height: 1.6; }
.consent__notice + .consent__check { margin-top: var(--s-4); }
.consent__check { display: flex; align-items: flex-start; gap: var(--s-3); cursor: pointer; }
.consent__check input { margin-top: 3px; width: 20px; height: 20px; accent-color: var(--c-primary); flex: none; }
.consent__check-label { font-size: var(--fs-small); }

/* ----------------------------------------------------------------------------
   12. Crisis banner (client — persistent)
---------------------------------------------------------------------------- */
.crisis {
  display: flex; gap: var(--s-3); align-items: flex-start;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-small);
  color: var(--c-text-muted);
  line-height: 1.5;
}
.crisis__icon { color: var(--c-accent); flex: none; font-size: 16px; line-height: 1.5; }
.crisis strong { color: var(--c-text); }
.crisis a { color: var(--c-primary); font-weight: 500; }

/* ----------------------------------------------------------------------------
   13. Empty state
---------------------------------------------------------------------------- */
.empty {
  text-align: center;
  padding: var(--s-8) var(--s-5);
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--r-lg);
  background: var(--c-surface);
}
.empty__icon { font-size: 28px; margin-bottom: var(--s-3); }
.empty h2 { margin-bottom: var(--s-2); }
.empty p { color: var(--c-text-muted); margin-bottom: var(--s-5); max-width: 42ch; margin-left: auto; margin-right: auto; }

/* ----------------------------------------------------------------------------
   14. Read-only value blocks (submission / task view)
---------------------------------------------------------------------------- */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: var(--s-2) var(--s-4); }
.kv dt { font-size: var(--fs-small); color: var(--c-text-muted); }
.kv dd { margin: 0; }

.prose { line-height: 1.7; max-width: 66ch; }
.prose p + p { margin-top: var(--s-4); }

.readback {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  white-space: pre-wrap;
  line-height: 1.7;
}

.divider { height: 1px; background: var(--c-border); border: 0; margin: var(--s-5) 0; }

/* prototype-only note ribbon */
.proto-note {
  font-size: var(--fs-xs); color: var(--c-text-subtle);
  background: var(--c-surface-2); border: 1px dashed var(--c-border-strong);
  border-radius: var(--r-sm); padding: var(--s-2) var(--s-3); margin-top: var(--s-5);
}

/* ----------------------------------------------------------------------------
   15. Responsive
---------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .page--app .page__main { padding: var(--s-5) var(--s-4); }
  .kv { grid-template-columns: 1fr; gap: var(--s-1); }
  .kv dd { margin-bottom: var(--s-3); }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
}

/* ----------------------------------------------------------------------------
   16. Reduced motion
---------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
    scroll-behavior: auto !important;
  }
}
