/* Web SARA App: component classes (wsa-*). Needs tokens.css first. */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--text);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
::selection { background: var(--brand-100); color: var(--ink); }

:where(button, a, input, textarea, select, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.wsa-icon {
  width: var(--icon-md);
  height: var(--icon-md);
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wsa-icon--lg { width: var(--icon-lg); height: var(--icon-lg); }

/* Screen */

.wsa-screen {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: var(--surface-page);
}

.wsa-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-4);
}

.wsa-content--card { background: var(--surface); }

.wsa-prompt { display: flex; flex-direction: column; gap: var(--space-1); }

.wsa-prompt__title {
  font-size: var(--text-title);
  line-height: 1.3;
  font-weight: var(--weight-semibold);
  color: var(--text);
}

.wsa-prompt__hint { font-size: var(--text-label); line-height: 1.43; color: var(--text-muted); }

/* Button */

.wsa-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.wsa-btn--primary { background: var(--interactive); color: var(--on-interactive); }
.wsa-btn--primary:hover { background: var(--interactive-hover); }

.wsa-btn--secondary { background: var(--surface); border-color: var(--border-control); color: var(--text); }
.wsa-btn--secondary:hover { background: var(--interactive-subtle); border-color: var(--interactive); }

.wsa-btn--ghost { background: transparent; color: var(--interactive); padding: 0 var(--space-3); }
.wsa-btn--ghost:hover { background: var(--interactive-subtle); }

.wsa-btn--danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.wsa-btn--danger:hover { background: var(--danger-subtle); }

.wsa-btn--block { width: 100%; }

.wsa-btn--icon { width: var(--touch-min); padding: 0; }

.wsa-btn:disabled,
.wsa-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* App bar */

.wsa-appbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--appbar-height);
  padding: env(safe-area-inset-top, 0px) var(--space-2) 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.wsa-appbar__title {
  flex-grow: 1;
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-heading);
  font-weight: var(--weight-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wsa-appbar__brand { display: flex; align-items: center; }

.wsa-appbar__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.wsa-appbar__action:hover { background: var(--surface-subtle); }

/* Step header */

.wsa-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.wsa-steps__row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.wsa-steps__count { font-size: var(--text-caption); color: var(--text-muted); font-variant-numeric: tabular-nums; }

.wsa-steps__bar {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.wsa-steps__bar li { height: 4px; border-radius: var(--radius-sm); background: var(--border); }
.wsa-steps__bar li.is-done { background: var(--interactive); }
.wsa-steps__bar li.is-current { background: var(--brand-200); }

.wsa-steps__name {
  font-size: 0.75rem;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--interactive);
}

/* Choice card */

.wsa-choices { display: flex; flex-direction: column; gap: var(--space-2); }

.wsa-choice {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.wsa-choice__chip {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--interactive-subtle);
  color: var(--interactive);
}

.wsa-choice__text { display: flex; flex-grow: 1; flex-direction: column; min-width: 0; }
.wsa-choice__title { font-weight: var(--weight-medium); }
.wsa-choice__meta { font-size: var(--text-caption); color: var(--text-muted); }
.wsa-choice__check { color: var(--interactive); visibility: hidden; }

.wsa-choice[aria-pressed="true"] {
  border-color: var(--interactive);
  box-shadow: inset 0 0 0 1px var(--interactive);
  background: var(--interactive-subtle);
}

.wsa-choice[aria-pressed="true"] .wsa-choice__chip { background: var(--surface); }
.wsa-choice[aria-pressed="true"] .wsa-choice__check { visibility: visible; }

/* Chip */

.wsa-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.wsa-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-label);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.wsa-chip .wsa-icon { width: 16px; height: 16px; }

.wsa-chip[aria-pressed="true"] {
  border-color: var(--selection-border);
  background: var(--selection);
  color: var(--on-selection);
}

/* Field */

.wsa-field { display: flex; flex-direction: column; gap: var(--space-1); }

.wsa-field__label { font-size: var(--text-label); font-weight: var(--weight-medium); color: var(--text); }
.wsa-field__required { font-weight: var(--weight-regular); color: var(--text-muted); }
.wsa-field__hint { font-size: var(--text-caption); color: var(--text-muted); }

.wsa-field__control {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-body);
}

textarea.wsa-field__control { min-height: 120px; padding: var(--space-3); resize: vertical; }

.wsa-field__control::placeholder { color: var(--text-muted); }

.wsa-field__control:focus-visible {
  border-color: var(--interactive);
  outline: none;
  box-shadow: 0 0 0 1px var(--interactive);
}

.wsa-field__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  text-align: left;
  cursor: pointer;
}

.wsa-field__trigger--empty { color: var(--text-muted); }

.wsa-field__error {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-caption);
  font-weight: var(--weight-medium);
  color: var(--danger);
}

.wsa-field.is-invalid .wsa-field__control { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }

.wsa-field__pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-3); }

/* Segmented */

.wsa-segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.wsa-segmented button {
  min-width: 88px;
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-label);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.wsa-segmented button[aria-pressed="true"] { background: var(--interactive); color: var(--on-interactive); }

/* Photos */

.wsa-photos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }

.wsa-photo {
  position: relative;
  aspect-ratio: 1;
  max-width: 100%;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.wsa-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }

.wsa-photo__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--scrim);
  color: var(--surface);
  cursor: pointer;
}

.wsa-photo__state {
  position: absolute;
  left: 4px;
  bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--warning-subtle);
  color: var(--warning);
  font-size: 0.75rem;
  font-weight: var(--weight-medium);
}

.wsa-photo--add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  border: 1px dashed var(--border-control);
  background: var(--surface);
  color: var(--interactive);
  font: inherit;
  font-size: var(--text-caption);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

/* Action bar */

.wsa-actionbar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.wsa-actionbar > .wsa-btn { flex: 1 1 0; }

/* Sync status */

.wsa-sync {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-label);
  font-weight: var(--weight-medium);
}

.wsa-sync__text { flex-grow: 1; min-width: 0; }
.wsa-sync__action { color: inherit; font: inherit; text-decoration: underline; background: none; border: 0; padding: 0; min-height: 40px; cursor: pointer; }

.wsa-sync--offline { background: var(--surface-subtle); color: var(--text); border-bottom: 1px solid var(--border); }
.wsa-sync--pending { background: var(--warning-subtle); color: var(--warning); }
.wsa-sync--sending { background: var(--info-subtle); color: var(--info); }
.wsa-sync--done { background: var(--success-subtle); color: var(--success); }
.wsa-sync--error { background: var(--danger-subtle); color: var(--danger); }

/* List */

.wsa-list {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface-card);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.wsa-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  text-decoration: none;
}

.wsa-list > li + li .wsa-row { border-top: 1px solid var(--border-light); }

.wsa-row__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--mod-sga);
  color: var(--mod-sga-ink);
}

.wsa-row__text { display: flex; flex-direction: column; min-width: 0; }
.wsa-row__title { overflow: hidden; font-weight: var(--weight-medium); text-overflow: ellipsis; white-space: nowrap; }
.wsa-row__meta { font-size: var(--text-caption); color: var(--text-muted); }
.wsa-row__end { display: flex; align-items: center; gap: var(--space-1); color: var(--text-muted); }

/* Badge */

.wsa-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: var(--weight-medium);
  line-height: 1.33;
  white-space: nowrap;
}

.wsa-badge .wsa-icon { width: 14px; height: 14px; }
.wsa-badge--done { background: var(--success-subtle); color: var(--success); }
.wsa-badge--pending { background: var(--warning-subtle); color: var(--warning); }
.wsa-badge--error { background: var(--danger-subtle); color: var(--danger); }
.wsa-badge--sending { background: var(--info-subtle); color: var(--info); }
.wsa-badge--draft { background: var(--surface-subtle); color: var(--text); }

/* Empty and result states */

.wsa-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-6);
  text-align: center;
}

.wsa-state__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--interactive-subtle);
  color: var(--interactive);
}

.wsa-state--pending .wsa-state__chip { background: var(--warning-subtle); color: var(--warning); }
.wsa-state__title { font-size: var(--text-display); line-height: 1.25; font-weight: var(--weight-semibold); }
.wsa-state__text { max-width: 32ch; color: var(--text-muted); }

/* Sheet */

.wsa-scrim { position: fixed; inset: 0 0 var(--wsa-sheet-offset, 0px); z-index: 100; background: var(--scrim); }

.wsa-sheet {
  position: fixed;
  right: 0;
  bottom: var(--wsa-sheet-offset, 0px);
  left: 0;
  z-index: 101;
  display: flex;
  flex-direction: column;
  max-height: calc(80% - var(--wsa-sheet-offset, 0px));
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-sheet);
}

.wsa-sheet__handle {
  align-self: center;
  width: 36px;
  height: 4px;
  margin: var(--space-2) 0;
  border-radius: var(--radius-full);
  background: var(--border-control);
}

.wsa-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-2) var(--space-2) var(--space-4);
}

.wsa-sheet__title { font-size: var(--text-heading); font-weight: var(--weight-semibold); }

.wsa-sheet__options { margin: 0; padding: 0; overflow-y: auto; list-style: none; }

.wsa-sheet__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-top: 1px solid var(--border-light);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.wsa-sheet__option small { display: block; font-size: var(--text-caption); color: var(--text-muted); }
.wsa-sheet__option .wsa-icon { color: var(--interactive); visibility: hidden; }
.wsa-sheet__option[aria-selected="true"] { font-weight: var(--weight-medium); }
.wsa-sheet__option[aria-selected="true"] .wsa-icon { visibility: visible; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
