/**
 * Northstar UI Primitives (ns-*)
 *
 * Visual layer for the Jinja2 macros under
 * templates/patient/_partials/primitives/. Each `.ns-*` class is the code
 * mirror of a component in the Figma "Northstar UI Library" page; their
 * properties resolve through CSS custom properties in design-tokens.css,
 * which is regenerated from Figma Variables via the Tokens Studio plugin.
 *
 * Hard rules:
 *   1. NEVER hardcode hex / px in this file. Use --color-*, --space-*,
 *      --radius-*, --shadow-* exclusively. Phase 6 lint enforces this.
 *   2. The legacy `.btn`, `.card`, `.alert`, etc. classes in sibling files
 *      remain for not-yet-migrated pages. Do not couple ns-* with them.
 *   3. When Figma adds a new variant, add the matching `.ns-*--<variant>`
 *      block here and the variant arg to the macro. Keep them in lockstep.
 */

/* -------------------------------------------------------------------------
 * Button — ns-btn
 * ------------------------------------------------------------------------- */

.ns-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  height: var(--button-height-md);
  padding: 0 var(--space-md);
  border: 1px solid transparent;
  border-radius: var(--button-radius);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background var(--transition-fast),
              border-color var(--transition-fast),
              color var(--transition-fast),
              box-shadow var(--transition-fast),
              transform var(--transition-fast);
}

.ns-btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

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

.ns-btn--full { width: 100%; }

/* Sizes */
.ns-btn--size-sm { height: var(--button-height-sm); padding: 0 var(--space-sm); font-size: var(--text-sm); }
.ns-btn--size-md { height: var(--button-height-md); }
.ns-btn--size-lg { height: var(--button-height-lg); padding: 0 var(--space-lg); font-size: var(--text-body-lg); }

/* Variants */
.ns-btn--primary {
  background: var(--color-primary);
  color: var(--color-text-on-primary);
}
.ns-btn--primary:hover {
  background: var(--color-primary-dark);
  text-decoration-line: underline;
  text-decoration-color: var(--color-secondary);
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

/* Tailwind primary buttons: same Sunshine underline, because Dusk alone does not separate from Ink. */
.hover\:bg-primary-dark:hover {
  text-decoration-line: underline;
  text-decoration-color: var(--color-secondary);
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

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

.ns-btn--ghost {
  background: transparent;
  color: var(--color-text-primary);
}
.ns-btn--ghost:hover { background: var(--color-gray-100); }

.ns-btn--destructive {
  background: var(--color-error);
  color: var(--color-ink);
}
.ns-btn--destructive:hover { background: var(--color-error-fg); }

/* Loading state — spinner via ::after using token-driven sizes */
.ns-btn--loading .ns-btn__label { opacity: 0; }
.ns-btn--loading::after {
  content: "";
  position: absolute;
  width: var(--space-sm);
  height: var(--space-sm);
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--radius-full);
  animation: ns-spin 0.75s linear infinite;
}
.ns-btn { position: relative; }

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

/* -------------------------------------------------------------------------
 * Card — ns-card
 * ------------------------------------------------------------------------- */

.ns-card {
  background: var(--color-bg-surface);
  border-radius: var(--card-radius);
  border: var(--card-border);
  padding: var(--card-padding);
}
.ns-card--no-pad { padding: 0; }

/* SoT: the `--card-shadow` token (= `--shadow-sm`) names the Figma Card
 * component's default drop shadow, so the primitive's default variant
 * carries it. `--no-shadow` is the explicit opt-out for cards nested
 * inside another shadowed surface (where the inner card looks flat). */
.ns-card--default     { box-shadow: var(--card-shadow); }
.ns-card--no-shadow   { box-shadow: none; }
.ns-card--interactive {
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.ns-card--interactive:hover { box-shadow: var(--shadow-md); }
.ns-card--elevated    { box-shadow: var(--shadow-md); }

/* -------------------------------------------------------------------------
 * Badge — ns-badge
 * ------------------------------------------------------------------------- */

.ns-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  padding: var(--space-2xs) var(--space-xs);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1;
  border-radius: var(--radius-xs);
  background: var(--color-gray-200);
  color: var(--color-text-secondary);
}
.ns-badge--pill { border-radius: var(--radius-full); }

.ns-badge--success { background: var(--color-success-bg); color: var(--color-success-fg); }
.ns-badge--warning { background: var(--color-warning-bg); color: var(--color-ink); }
.ns-badge--error   { background: var(--color-error-bg);   color: var(--color-error-fg); }
.ns-badge--info    { background: var(--color-info-bg);    color: var(--color-info-fg); }
.ns-badge--neutral { background: var(--color-gray-200);   color: var(--color-text-secondary); }

/* -------------------------------------------------------------------------
 * SidebarItem — ns-sidebar-item
 * ------------------------------------------------------------------------- */

.ns-sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.ns-sidebar-item:hover { background: var(--color-gray-100); color: var(--color-text-primary); }
.ns-sidebar-item--active {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}
.ns-sidebar-item--indented { padding-left: calc(var(--space-md) + var(--space-md)); }

.ns-sidebar-item__icon { font-size: var(--text-h4); }
.ns-sidebar-item__label { flex: 1; }
.ns-sidebar-item__badge {
  background: var(--color-error);
  color: var(--color-ink);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  padding: var(--space-2xs) var(--space-xs);
  min-width: var(--space-md);
  text-align: center;
  margin-left: auto;
}

.ns-sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest, 0.08em);
  color: var(--color-text-muted);
}

/* -------------------------------------------------------------------------
 * SectionHeader — ns-section-header
 * ------------------------------------------------------------------------- */

.ns-section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}
.ns-section-header__text { display: flex; flex-direction: column; gap: var(--space-2xs); }
.ns-section-header__title {
  font-size: var(--text-h3);
  font-weight: var(--weight-regular);
  color: var(--color-text-primary);
  letter-spacing: var(--tracking-tight);
  margin: 0;
}
.ns-section-header__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin: 0;
}
.ns-section-header__action { flex-shrink: 0; }

/* -------------------------------------------------------------------------
 * TopBar — ns-top-bar
 * ------------------------------------------------------------------------- */

.ns-top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  height: var(--header-height);
  padding: 0 var(--space-md);
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-subtle);
}
.ns-top-bar__title {
  font-size: var(--text-h4);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
}
.ns-top-bar__search {
  flex: 1;
  max-width: var(--top-bar-search-max-width);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0 var(--space-sm);
  height: var(--input-height);
  background: var(--color-gray-100);
  border-radius: var(--radius-full);
}
.ns-top-bar__search-icon { color: var(--color-text-muted); }
.ns-top-bar__search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: var(--text-sm);
  color: var(--color-text-primary);
}
.ns-top-bar__search-input:focus {
  box-shadow: var(--shadow-focus);
}
.ns-top-bar__user { margin-left: auto; }
.ns-top-bar__user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
}
.ns-top-bar__slot { display: flex; align-items: center; gap: var(--space-sm); }

/* -------------------------------------------------------------------------
 * TextField — ns-text-field
 * ------------------------------------------------------------------------- */

.ns-text-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}
.ns-text-field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
}
.ns-text-field__required { color: var(--color-error); }
.ns-text-field__input {
  height: var(--input-height);
  padding: 0 var(--input-padding-x);
  border: 1px solid var(--input-border);
  border-radius: var(--input-radius);
  font-family: inherit;
  font-size: var(--text-body);
  color: var(--color-text-primary);
  background: var(--color-bg-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.ns-text-field__input:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: var(--shadow-focus);
}
.ns-text-field__input--area {
  height: auto;
  min-height: var(--space-2xl);
  padding-top: var(--input-padding-y);
  padding-bottom: var(--input-padding-y);
  resize: vertical;
  line-height: var(--leading-relaxed);
}
.ns-text-field__input:disabled {
  background: var(--color-gray-100);
  color: var(--color-text-muted);
  cursor: not-allowed;
}
.ns-text-field--state-error .ns-text-field__input {
  border-color: var(--color-error);
}
.ns-text-field--state-error .ns-text-field__input:focus {
  box-shadow: var(--shadow-focus);
}
.ns-text-field__hint  { font-size: var(--text-xs); color: var(--color-text-muted); }
.ns-text-field__error { font-size: var(--text-xs); color: var(--color-error-fg); }

.ns-text-field__control { position: relative; }
.ns-text-field__input--select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding-right: calc(var(--input-padding-x) + var(--space-md));
}
.ns-text-field__chevron {
  position: absolute;
  right: var(--space-sm);
  top: 50%;
  width: var(--space-xs);
  height: var(--space-xs);
  border-right: 2px solid var(--color-text-primary);
  border-bottom: 2px solid var(--color-text-primary);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

/* Overlay scrim — shared by portal modals. Strength matches --modal-overlay-bg. */
.ns-overlay-scrim {
  background: var(--modal-overlay-bg);
}
.ns-overlay-scrim--strong {
  background: color-mix(in srgb, var(--color-ink) 80%, transparent);
}
