/* =====================================================================
   HOMECARE — Reusable base UI components (M00 PART 03)
   -------------------------------------------------------------------
   Design Tokens -> Base Components -> Future HOMECARE Screens
   All components are class-based and token-driven so later screens reuse
   them instead of duplicating one-off styles. Interactive behaviour for
   toast + modal lives in scripts/ui/*.js.
   ===================================================================== */

/* =====================================================================
   Shared service context and canonical-record projection (CR-HC-03 PART 02)
   ===================================================================== */
.hc-service-context {
  margin-top: var(--hc-space-4);
  padding: var(--hc-space-4);
  background: var(--hc-bg-subtle);
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius-md);
}
.hc-service-context h4 { margin-bottom: var(--hc-space-3); }
.hc-service-context dl,
.hc-service-context__references dl { display: grid; gap: var(--hc-space-2); }
.hc-service-context dl > div,
.hc-service-context__references dl > div {
  display: grid;
  grid-template-columns: minmax(7.5rem, 0.8fr) minmax(0, 1.6fr);
  gap: var(--hc-space-3);
  min-width: 0;
}
.hc-service-context dt,
.hc-service-context__references dt { color: var(--hc-text-muted); font-size: var(--hc-font-size-xs); }
.hc-service-context dd,
.hc-service-context__references dd {
  min-width: 0;
  color: var(--hc-text-strong);
  font-size: var(--hc-font-size-sm);
  font-weight: var(--hc-font-weight-medium);
  overflow-wrap: anywhere;
}
.hc-service-context__lineage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--hc-space-2);
  margin-top: var(--hc-space-3);
  color: var(--hc-color-primary);
  font-size: var(--hc-font-size-xs);
  font-weight: var(--hc-font-weight-semibold);
}
.hc-service-context__lineage b { color: var(--hc-text-faint); }
.hc-service-context__references {
  margin-top: var(--hc-space-3);
  border-top: 1px solid var(--hc-border);
  padding-top: var(--hc-space-3);
}
.hc-service-context__references summary {
  min-height: var(--hc-touch-target);
  cursor: pointer;
  color: var(--hc-color-accent);
  font-size: var(--hc-font-size-sm);
  font-weight: var(--hc-font-weight-semibold);
}
.hc-service-context__references dl { margin-top: var(--hc-space-2); }
@media (max-width: 359px) {
  .hc-service-context dl > div,
  .hc-service-context__references dl > div { grid-template-columns: minmax(0, 1fr); gap: var(--hc-space-1); }
}

/* ---- Shared keyframes ---- */
@keyframes hc-spin {
  to {
    transform: rotate(360deg);
  }
}

/* =====================================================================
   Buttons
   ===================================================================== */
.hc-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--hc-space-2);
  min-height: var(--hc-touch-target);
  padding: 0 var(--hc-space-4);
  font-size: var(--hc-font-size-sm);
  font-weight: var(--hc-font-weight-semibold);
  line-height: 1;
  color: var(--hc-text-inverse);
  background: var(--hc-color-primary);
  border: 1px solid var(--hc-color-primary);
  border-radius: var(--hc-radius-md);
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--hc-duration-fast) var(--hc-ease-standard),
    border-color var(--hc-duration-fast) var(--hc-ease-standard),
    box-shadow var(--hc-duration-fast) var(--hc-ease-standard);
}
.hc-btn:hover {
  background: var(--hc-color-primary-strong);
  border-color: var(--hc-color-primary-strong);
}
.hc-btn:focus-visible {
  outline: none;
  box-shadow: var(--hc-focus-ring);
}
.hc-btn[disabled],
.hc-btn.is-disabled {
  cursor: not-allowed;
  opacity: 0.5;
  pointer-events: none;
}

.hc-btn--secondary {
  color: var(--hc-color-primary);
  background: var(--hc-bg-surface);
  border-color: var(--hc-border-strong);
}
.hc-btn--secondary:hover {
  background: var(--hc-bg-subtle);
  border-color: var(--hc-border-strong);
  color: var(--hc-color-primary-strong);
}

.hc-btn--ghost {
  color: var(--hc-color-primary);
  background: transparent;
  border-color: transparent;
}
.hc-btn--ghost:hover {
  background: var(--hc-color-accent-weak);
}

.hc-btn--danger {
  color: var(--hc-text-inverse);
  background: var(--hc-danger-600);
  border-color: var(--hc-danger-600);
}
.hc-btn--danger:hover {
  background: var(--hc-danger-500);
  border-color: var(--hc-danger-500);
}

.hc-btn--sm {
  /* Compact visual treatment without shrinking the accessible touch target. */
  min-height: var(--hc-touch-target);
  padding: 0 var(--hc-space-3);
  font-size: var(--hc-font-size-xs);
}
.hc-btn--block {
  display: flex;
  width: 100%;
}

.hc-btn__icon {
  flex: 0 0 auto;
}
.hc-btn__label {
  transition: opacity var(--hc-duration-fast) var(--hc-ease-standard);
}
/* Loading state: spinner overlays; label kept for stable width. */
.hc-btn__spinner {
  position: absolute;
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: hc-spin 0.6s linear infinite;
}
.hc-btn--loading {
  pointer-events: none;
  color: transparent;
}
.hc-btn--loading .hc-btn__spinner {
  display: inline-block;
  color: var(--hc-text-inverse);
}
.hc-btn--secondary.hc-btn--loading,
.hc-btn--ghost.hc-btn--loading {
  color: transparent;
}
.hc-btn--secondary.hc-btn--loading .hc-btn__spinner,
.hc-btn--ghost.hc-btn--loading .hc-btn__spinner {
  color: var(--hc-color-primary);
}

/* Icon button */
.hc-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--hc-touch-target);
  height: var(--hc-touch-target);
  color: var(--hc-color-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--hc-radius-md);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--hc-duration-fast) var(--hc-ease-standard),
    box-shadow var(--hc-duration-fast) var(--hc-ease-standard);
}
.hc-icon-btn:hover {
  background: var(--hc-color-accent-weak);
}
.hc-icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--hc-focus-ring);
}
.hc-icon-btn--sm {
  width: var(--hc-touch-target);
  height: var(--hc-touch-target);
}
.hc-icon-btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

/* =====================================================================
   Cards
   ===================================================================== */
.hc-card {
  background: var(--hc-bg-surface);
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius-lg);
  padding: var(--hc-space-4);
  box-shadow: var(--hc-shadow-sm);
}
.hc-card--compact {
  padding: var(--hc-space-3);
}
.hc-card--actionable {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: box-shadow var(--hc-duration-base) var(--hc-ease-standard),
    transform var(--hc-duration-base) var(--hc-ease-standard),
    border-color var(--hc-duration-base) var(--hc-ease-standard);
}
.hc-card--actionable:hover {
  box-shadow: var(--hc-shadow-md);
  border-color: var(--hc-border-strong);
}
.hc-card--actionable:focus-visible {
  outline: none;
  box-shadow: var(--hc-focus-ring);
}
.hc-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--hc-space-3);
  margin-bottom: var(--hc-space-2);
}
.hc-card__title {
  font-size: var(--hc-font-size-md);
  font-weight: var(--hc-font-weight-semibold);
  color: var(--hc-text-strong);
}
.hc-card__body {
  color: var(--hc-text-base);
  font-size: var(--hc-font-size-sm);
}
.hc-card__body > * + * {
  margin-top: var(--hc-space-2);
}
.hc-card__footer {
  margin-top: var(--hc-space-3);
  display: flex;
  gap: var(--hc-space-2);
  align-items: center;
}

/* =====================================================================
   Form controls
   ===================================================================== */
.hc-field {
  display: flex;
  flex-direction: column;
  gap: var(--hc-space-2);
}
.hc-label {
  font-size: var(--hc-font-size-sm);
  font-weight: var(--hc-font-weight-medium);
  color: var(--hc-text-strong);
}
.hc-label__req {
  color: var(--hc-danger-500);
  margin-left: 2px;
}

.hc-input,
.hc-select,
.hc-textarea {
  width: 100%;
  min-height: var(--hc-touch-target);
  padding: var(--hc-space-3);
  font-size: var(--hc-font-size-base);
  color: var(--hc-text-base);
  background: var(--hc-bg-surface);
  border: 1px solid var(--hc-border-strong);
  border-radius: var(--hc-radius-md);
  transition: border-color var(--hc-duration-fast) var(--hc-ease-standard),
    box-shadow var(--hc-duration-fast) var(--hc-ease-standard);
}
.hc-textarea {
  min-height: 96px;
  resize: vertical;
  line-height: var(--hc-leading-base);
}
.hc-input::placeholder,
.hc-textarea::placeholder {
  color: var(--hc-text-faint);
}
.hc-input:focus,
.hc-select:focus,
.hc-textarea:focus {
  outline: none;
  border-color: var(--hc-border-focus);
  box-shadow: var(--hc-focus-ring);
}
.hc-input[disabled],
.hc-select[disabled],
.hc-textarea[disabled] {
  background: var(--hc-bg-subtle);
  color: var(--hc-text-faint);
  cursor: not-allowed;
}

.hc-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--hc-space-8);
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%235a6b82'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M6%209l6%206%206-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--hc-space-3) center;
  background-size: 18px;
}

.hc-field__help {
  font-size: var(--hc-font-size-xs);
  color: var(--hc-text-muted);
}
.hc-field__error {
  font-size: var(--hc-font-size-xs);
  color: var(--hc-danger-600);
  font-weight: var(--hc-font-weight-medium);
}
.hc-field--error .hc-input,
.hc-field--error .hc-select,
.hc-field--error .hc-textarea {
  border-color: var(--hc-danger-500);
}
.hc-field--error .hc-input:focus,
.hc-field--error .hc-select:focus,
.hc-field--error .hc-textarea:focus {
  border-color: var(--hc-danger-500);
  box-shadow: 0 0 0 3px rgba(210, 69, 79, 0.25);
}

/* Checkbox / radio baseline (native + accent) */
.hc-check {
  display: flex;
  align-items: flex-start;
  gap: var(--hc-space-2);
  min-height: var(--hc-touch-target);
  padding: var(--hc-space-1) 0;
}
.hc-check__input {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  flex: 0 0 auto;
  accent-color: var(--hc-color-accent);
}
.hc-check__input:focus-visible {
  outline: none;
  box-shadow: var(--hc-focus-ring);
  border-radius: var(--hc-radius-sm);
}
.hc-check__label {
  font-size: var(--hc-font-size-sm);
  color: var(--hc-text-base);
  line-height: var(--hc-leading-base);
}
.hc-radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--hc-space-1);
}

/* =====================================================================
   Chips & status badges
   ===================================================================== */
.hc-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--hc-space-1);
  min-height: 28px;
  padding: 0 var(--hc-space-3);
  font-size: var(--hc-font-size-xs);
  font-weight: var(--hc-font-weight-medium);
  color: var(--hc-text-base);
  background: var(--hc-bg-subtle);
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius-pill);
}
.hc-chip--outline {
  background: transparent;
  border-color: var(--hc-border-strong);
  color: var(--hc-text-muted);
}

.hc-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 0 var(--hc-space-2);
  font-size: var(--hc-font-size-xs);
  font-weight: var(--hc-font-weight-semibold);
  border-radius: var(--hc-radius-pill);
}
.hc-badge__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.hc-badge--neutral {
  color: var(--hc-text-muted);
  background: var(--hc-bg-subtle);
}
.hc-badge--info {
  color: var(--hc-blue-700);
  background: var(--hc-info-50);
}
.hc-badge--success {
  color: var(--hc-success-600);
  background: var(--hc-success-50);
}
.hc-badge--warning {
  color: var(--hc-warning-600);
  background: var(--hc-warning-50);
}
.hc-badge--danger {
  color: var(--hc-danger-600);
  background: var(--hc-danger-50);
}

/* =====================================================================
   Section header
   ===================================================================== */
.hc-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--hc-space-3);
  margin-bottom: var(--hc-space-3);
}
.hc-section-header__title {
  font-size: var(--hc-font-size-md);
  font-weight: var(--hc-font-weight-semibold);
  color: var(--hc-text-strong);
}
.hc-section-header__action {
  flex: 0 0 auto;
}

/* =====================================================================
   Divider
   ===================================================================== */
.hc-divider {
  height: 1px;
  margin: var(--hc-space-4) 0;
  background: var(--hc-border);
  border: 0;
}

/* =====================================================================
   List rows
   ===================================================================== */
.hc-list {
  background: var(--hc-bg-surface);
  border: 1px solid var(--hc-border);
  border-radius: var(--hc-radius-lg);
  overflow: hidden;
}
.hc-list-item {
  display: flex;
  align-items: center;
  gap: var(--hc-space-3);
  min-height: 56px;
  padding: var(--hc-space-3) var(--hc-space-4);
  color: inherit;
  text-decoration: none;
  background: var(--hc-bg-surface);
  border-bottom: 1px solid var(--hc-border);
  -webkit-tap-highlight-color: transparent;
}
.hc-list-item:last-child {
  border-bottom: 0;
}
.hc-list-item--actionable {
  cursor: pointer;
  transition: background var(--hc-duration-fast) var(--hc-ease-standard);
}
.hc-list-item--actionable:hover {
  background: var(--hc-bg-subtle);
}
.hc-list-item--actionable:focus-visible {
  outline: none;
  box-shadow: var(--hc-focus-ring);
}
.hc-list-item__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: var(--hc-radius-md);
  background: var(--hc-color-accent-weak);
  color: var(--hc-color-primary);
}
.hc-list-item__main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hc-list-item__title {
  font-size: var(--hc-font-size-sm);
  font-weight: var(--hc-font-weight-semibold);
  color: var(--hc-text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hc-list-item__text {
  font-size: var(--hc-font-size-xs);
  color: var(--hc-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hc-list-item__trailing {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--hc-space-2);
  color: var(--hc-text-faint);
}
.hc-list-item__value {
  font-size: var(--hc-font-size-sm);
  font-weight: var(--hc-font-weight-medium);
  color: var(--hc-text-base);
}

/* =====================================================================
   Loading: inline spinner + skeleton + content placeholder
   ===================================================================== */
.hc-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--hc-color-accent-weak);
  border-top-color: var(--hc-color-accent);
  border-radius: 50%;
  animation: hc-spin 0.6s linear infinite;
}
.hc-spinner--sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}
.hc-spinner--lg {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

.hc-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--hc-space-3);
  padding: var(--hc-space-10) var(--hc-space-4);
  color: var(--hc-text-muted);
  text-align: center;
}
.hc-loading__label {
  font-size: var(--hc-font-size-sm);
}

.hc-skeleton {
  display: block;
  width: 100%;
  height: 1rem;
  background: linear-gradient(
    90deg,
    var(--hc-bg-subtle) 25%,
    #eef2f8 37%,
    var(--hc-bg-subtle) 63%
  );
  background-size: 400% 100%;
  animation: hc-shimmer 1.4s ease infinite;
  border-radius: var(--hc-radius-sm);
}
@keyframes hc-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}
.hc-skeleton--text {
  height: 0.875rem;
}
.hc-skeleton--line {
  height: 0.75rem;
}
.hc-skeleton--title {
  height: 1.25rem;
  width: 60%;
}
.hc-skeleton--circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: 0 0 auto;
}
@media (prefers-reduced-motion: reduce) {
  .hc-skeleton {
    animation: none;
    background: var(--hc-bg-subtle);
  }
}

/* =====================================================================
   Empty state
   ===================================================================== */
.hc-empty,
.hc-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--hc-space-2);
  padding: var(--hc-space-10) var(--hc-space-4);
}
.hc-empty__icon,
.hc-error__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: var(--hc-radius-xl);
  background: var(--hc-color-accent-weak);
  color: var(--hc-color-primary);
  margin-bottom: var(--hc-space-2);
}
.hc-error__icon {
  background: var(--hc-danger-50);
  color: var(--hc-danger-600);
}
.hc-empty__title,
.hc-error__title {
  font-size: var(--hc-font-size-md);
  font-weight: var(--hc-font-weight-semibold);
  color: var(--hc-text-strong);
}
.hc-empty__message,
.hc-error__message {
  font-size: var(--hc-font-size-sm);
  color: var(--hc-text-muted);
  max-width: 36ch;
}
.hc-empty__action,
.hc-error__action {
  margin-top: var(--hc-space-3);
}

/* =====================================================================
   Toast
   ===================================================================== */
.hc-toast-region {
  position: fixed;
  top: calc(env(safe-area-inset-top) + var(--hc-header-height) + var(--hc-space-2));
  left: 0;
  right: 0;
  z-index: var(--hc-z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--hc-space-2);
  padding: 0 var(--hc-space-4);
  margin-inline: auto;
  max-width: var(--hc-app-max-width);
  pointer-events: none;
}
.hc-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--hc-space-2);
  width: 100%;
  padding: var(--hc-space-2) var(--hc-space-3);
  background: var(--hc-color-primary-strong);
  color: var(--hc-text-inverse);
  border-radius: var(--hc-radius-md);
  box-shadow: var(--hc-shadow-lg);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity var(--hc-duration-base) var(--hc-ease-standard),
    transform var(--hc-duration-base) var(--hc-ease-standard);
}
.hc-toast--show {
  opacity: 1;
  transform: translateY(0);
}
.hc-toast__icon {
  flex: 0 0 auto;
}
.hc-toast__msg {
  flex: 1 1 auto;
  font-size: var(--hc-font-size-sm);
  line-height: var(--hc-leading-base);
}
.hc-toast__close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--hc-touch-target);
  height: var(--hc-touch-target);
  color: var(--hc-text-inverse);
  background: transparent;
  border: 0;
  border-radius: var(--hc-radius-sm);
  opacity: 0.85;
  -webkit-tap-highlight-color: transparent;
}
.hc-toast__close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}
.hc-toast__close:focus-visible {
  outline: none;
  box-shadow: var(--hc-focus-ring);
}
.hc-toast--success {
  background: var(--hc-success-600);
}
.hc-toast--warning {
  background: var(--hc-warning-600);
}
.hc-toast--error {
  background: var(--hc-danger-600);
}
.hc-toast--info {
  background: var(--hc-color-primary-strong);
}

/* =====================================================================
   Modal / dialog
   ===================================================================== */
.hc-modal {
  position: fixed;
  inset: 0;
  z-index: 1200; /* above toast region (1100) */
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(10, 23, 42, 0); /* fade in */
  transition: background var(--hc-duration-base) var(--hc-ease-standard);
}
.hc-modal--show {
  background: rgba(10, 23, 42, 0.5);
}
.hc-modal__dialog {
  position: relative;
  width: 100%;
  max-width: var(--hc-app-max-width);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--hc-bg-surface);
  border-radius: var(--hc-radius-xl) var(--hc-radius-xl) 0 0;
  box-shadow: var(--hc-shadow-lg);
  padding: var(--hc-space-4);
  padding-bottom: calc(var(--hc-space-4) + env(safe-area-inset-bottom));
  transform: translateY(16px);
  opacity: 0;
  transition: transform var(--hc-duration-base) var(--hc-ease-standard),
    opacity var(--hc-duration-base) var(--hc-ease-standard);
}
.hc-modal__dialog--show {
  transform: translateY(0);
  opacity: 1;
}
.hc-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--hc-space-3);
  margin-bottom: var(--hc-space-3);
}
.hc-modal__title {
  font-size: var(--hc-font-size-lg);
  font-weight: var(--hc-font-weight-semibold);
  color: var(--hc-text-strong);
}
.hc-modal__close {
  flex: 0 0 auto;
  margin: calc(-1 * var(--hc-space-1));
}
.hc-modal__body {
  overflow-y: auto;
  color: var(--hc-text-base);
  font-size: var(--hc-font-size-sm);
}
.hc-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--hc-space-2);
  margin-top: var(--hc-space-4);
}
