/* ===========================================================
   Thesis A — Components catalogue styles
   Builds on tokens/a.css and a/local.css (which has .btn primitives).
   =========================================================== */

/* ---- State demo grid ---- */
.state-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}
.state-cell {
  border: 1px solid var(--border);
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  min-height: 100px;
}
.state-cell__demo { display: flex; align-items: center; justify-content: center; flex: 1; }
.state-cell__label {
  font: var(--type-mono);
  font-size: 10px;
  color: var(--ink-subtle);
  text-align: center;
}

/* ---- Buttons: add danger, sm, icon, spinner, group, forced states ---- */
.btn--danger {
  background: var(--brand-magenta);
  color: #FFFFFF;
  box-shadow: var(--shadow-sm);
}
.btn--danger:hover {
  background: color-mix(in srgb, var(--brand-magenta) 88%, black);
  box-shadow: var(--shadow-md);
}
.btn--danger::after { display: none; }

.btn--sm { height: var(--control-height-sm); padding: 0 var(--space-3); font-size: 12px; }
.btn--sm svg { width: 12px; height: 12px; }
.btn--icon { padding: 0 var(--space-2); }

.btn[disabled],
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn[disabled]:hover, .btn:disabled:hover { transform: none; box-shadow: var(--shadow-sm); }
.btn[disabled]::after { display: none; }

/* Forced state classes (for documentation only) */
.btn.is-hover.btn--primary { background: var(--color-action-bg-hover); box-shadow: var(--shadow-md); }
.btn.is-hover.btn--primary::after { opacity: 1; }
.btn.is-hover.btn--secondary { background: var(--surface-hover); border-color: var(--color-accent-readable); color: var(--color-accent-readable); }
.btn.is-active { transform: translateY(1px); box-shadow: inset 0 1px 2px rgba(0,0,0,0.18); }
.btn.is-focus { box-shadow: var(--shadow-focus); outline: none; }

.btn.is-loading { color: transparent; pointer-events: none; position: relative; }
.btn.is-loading .btn__spinner {
  position: absolute; left: 50%; top: 50%;
  width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border: 2px solid currentColor; opacity: 0.4;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
  color: var(--color-action-fg);
}
.btn--primary.is-loading .btn__spinner { color: var(--color-action-fg); opacity: 1; border-top-color: transparent; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn__spinner { animation: none; } }

.btn-group {
  display: inline-flex;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
}
.btn-group .btn {
  border-radius: 0;
  border: 0;
  border-right: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}
.btn-group .btn:last-child { border-right: 0; }
.btn-group .btn:hover { background: var(--surface-hover); }
.btn-group .btn--primary { background: var(--color-action-bg); color: var(--color-action-fg); }
.btn-group .btn--primary:hover { background: var(--color-action-bg-hover); }

/* ---- Fields ---- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin: var(--space-4) 0;
}
.field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.field__label {
  font: var(--type-heading-sm);
  color: var(--ink);
}
.field__input {
  height: var(--control-height-md);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--ink);
  font: var(--type-body);
  width: 100%;
  transition: border-color var(--motion-standard) var(--ease),
              box-shadow var(--motion-standard) var(--ease),
              background var(--motion-standard) var(--ease);
}
.field__input:hover { border-color: var(--ink-muted); }
.field__input:focus,
.field__input.is-focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.field__input::placeholder { color: var(--ink-subtle); }
.field__input:disabled { background: var(--surface-sunken); color: var(--ink-subtle); cursor: not-allowed; }

.field__input--textarea { height: auto; padding: var(--space-3); line-height: 1.5; resize: vertical; }
.field__input--with-icon { padding-left: 36px; }
.field__input--with-prefix { padding-left: 28px; }

.field__wrap { position: relative; }
.field__icon {
  position: absolute; left: 10px; top: 50%; margin-top: -8px;
  color: var(--ink-subtle); pointer-events: none;
}
.field__icon svg { width: 16px; height: 16px; }
.field__prefix {
  position: absolute; left: 10px; top: 50%; margin-top: -10px;
  color: var(--ink-muted); font: var(--type-body-strong);
}
.field__action {
  position: absolute; right: 6px; top: 50%; margin-top: -14px;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  transition: background var(--motion-micro) var(--ease), color var(--motion-micro) var(--ease);
}
.field__action:hover { background: var(--surface-hover); color: var(--ink); }
.field__action svg { width: 16px; height: 16px; }
.field__action--read { pointer-events: none; }

.field__input--select {
  appearance: none; -webkit-appearance: none;
  padding-right: 36px;
  /* Dropdown chevron drawn in the reserved 36px (was `background-image: none`, which left selects
     looking like static text boxes). Theme-aware: a lighter chevron under the ink (dark) theme. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 12px;
}

[data-theme="ink"] .field__input--select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.field__help {
  font: var(--type-caption);
  color: var(--ink-subtle);
  display: inline-flex; align-items: center; gap: 4px;
}
.field__help--error { color: var(--color-state-danger); }
.field__help--error svg { width: 12px; height: 12px; }
.field__help--success { color: var(--color-state-success); }

.field.is-error .field__input { border-color: var(--color-state-danger); }
.field.is-error .field__input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-state-danger) 24%, transparent); }
.field.is-success .field__input { border-color: var(--color-state-success); }
.field.is-success .field__action--read { color: var(--color-state-success); }

/* ---- Combobox ---- */
.combobox { position: relative; display: inline-block; min-width: 280px; }
.combobox__trigger {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  width: 100%; height: var(--control-height-md);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--ink);
  font: var(--type-body);
  cursor: pointer;
  transition: border-color var(--motion-standard) var(--ease);
}
.combobox__trigger:hover { border-color: var(--ink-muted); }
.combobox__trigger:focus-visible { outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.combobox__trigger svg { width: 16px; height: 16px; color: var(--ink-subtle); transition: transform var(--motion-standard) var(--ease); }
.combobox.is-open .combobox__trigger svg { transform: rotate(180deg); }
.combobox__value { color: var(--ink); }
.combobox.is-empty .combobox__value { color: var(--ink-subtle); }

.combobox__panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: none;
  overflow: hidden;
}
.combobox.is-open .combobox__panel { display: block; }
.combobox__search {
  position: relative; padding: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.combobox__search .field__icon { left: 18px; top: 50%; margin-top: -8px; }
.combobox__search-input {
  width: 100%; height: var(--control-height-sm);
  padding: 0 var(--space-3) 0 32px;
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  font: var(--type-body);
  color: var(--ink);
}
.combobox__search-input:focus { outline: none; }
.combobox__list { max-height: 240px; overflow-y: auto; padding: var(--space-1); }
.combobox__item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font: var(--type-body);
  color: var(--ink);
  cursor: pointer;
  transition: background var(--motion-micro) var(--ease);
}
.combobox__item:hover, .combobox__item:focus-visible { background: var(--surface-hover); outline: none; }
.combobox__item-check { width: 14px; height: 14px; color: var(--color-accent); display: none; }
.combobox__item:first-child .combobox__item-check { display: inline-block; }

/* ---- Tags input ---- */
.tags-input {
  display: flex; flex-wrap: wrap; gap: 6px;
  min-height: var(--control-height-md);
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  align-items: center;
}
.tags-input:focus-within { border-color: var(--color-accent); box-shadow: var(--shadow-focus); }
.tags-input__input { flex: 1; min-width: 80px; border: 0; padding: 4px; background: transparent; font: var(--type-body); color: var(--ink); }
.tags-input__input:focus { outline: none; }

/* ---- Choice (checkbox + radio) ---- */
.choice { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font: var(--type-body); user-select: none; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice__box, .choice__radio {
  width: 18px; height: 18px;
  background: var(--surface-raised);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  transition: background var(--motion-standard) var(--ease),
              border-color var(--motion-standard) var(--ease);
  position: relative;
}
.choice__radio { border-radius: 50%; }
.choice:hover .choice__box, .choice:hover .choice__radio { border-color: var(--ink-muted); }
.choice input:focus-visible ~ .choice__box,
.choice input:focus-visible ~ .choice__radio {
  box-shadow: var(--shadow-focus);
}
.choice input:checked ~ .choice__box {
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.choice input:checked ~ .choice__box::after {
  content: ''; width: 10px; height: 10px;
  background: var(--ink);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
          mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}
.choice input.is-indeterminate ~ .choice__box,
.choice input:indeterminate ~ .choice__box {
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.choice input.is-indeterminate ~ .choice__box::after,
.choice input:indeterminate ~ .choice__box::after {
  content: ''; width: 8px; height: 2px; background: var(--ink); border-radius: 1px;
  -webkit-mask-image: none; mask-image: none;
}
.choice input:checked ~ .choice__radio::after {
  content: ''; width: 8px; height: 8px;
  background: var(--color-accent);
  border-radius: 50%;
}
.choice input:checked ~ .choice__radio { border-color: var(--color-accent); }
.choice input:disabled ~ .choice__box, .choice input:disabled ~ .choice__radio { opacity: 0.4; }

/* Force checkbox indeterminate visually for demo */
.choice input.is-indeterminate ~ .choice__box::after { width: 10px; height: 2px; background: var(--ink); border-radius: 1px; -webkit-mask-image: none; mask-image: none; }

/* ---- Switch ---- */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font: var(--type-body); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track {
  position: relative;
  width: 36px; height: 20px;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background var(--motion-standard) var(--ease);
  flex: 0 0 auto;
}
.switch__thumb {
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; background: #FFFFFF;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: left var(--motion-standard) var(--ease);
}
.switch input:checked ~ .switch__track { background: var(--color-accent); }
.switch input:checked ~ .switch__track .switch__thumb { left: 18px; }
.switch input:focus-visible ~ .switch__track { box-shadow: var(--shadow-focus); }
.switch input:disabled ~ .switch__track { opacity: 0.4; }

/* ---- Mini calendar ---- */
.mini-cal {
  width: 320px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}
.mini-cal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.mini-cal__title { font: var(--type-heading-md); margin: 0; }
.mini-cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini-cal__dow {
  font: var(--type-eyebrow); letter-spacing: var(--letter-eyebrow); text-transform: uppercase;
  color: var(--ink-subtle); text-align: center; padding: 6px 0;
}
.mini-cal__day {
  height: 32px; display: flex; align-items: center; justify-content: center;
  font: var(--type-mono); font-size: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--motion-micro) var(--ease), color var(--motion-micro) var(--ease);
}
.mini-cal__day:hover { background: var(--surface-hover); }
.mini-cal__day--muted { color: var(--ink-subtle); opacity: 0.5; }
.mini-cal__day--today {
  background: var(--color-action-bg);
  color: var(--color-action-fg);
  font-weight: 600;
}
.mini-cal__day--range { background: color-mix(in srgb, var(--color-accent) 18%, transparent); }
.mini-cal__day--range-start, .mini-cal__day--range-end {
  background: var(--color-accent); color: var(--ink); font-weight: 600;
}
.accent-yellow .mini-cal__day--range-start, .accent-yellow .mini-cal__day--range-end { color: var(--ink); }

/* ---- Dropzone ---- */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  background: var(--surface-sunken);
  transition: border-color var(--motion-standard) var(--ease), background var(--motion-standard) var(--ease);
}
.dropzone.is-drag-over { border-color: var(--color-accent); background: color-mix(in srgb, var(--color-accent) 6%, var(--surface-sunken)); }
.dropzone__icon { width: 32px; height: 32px; color: var(--ink-subtle); margin: 0 auto var(--space-2); display: block; }
.dropzone__title { font: var(--type-heading-md); margin: 0 0 var(--space-1); }
.dropzone__hint { font: var(--type-caption); color: var(--ink-subtle); margin: 0; }
.dropzone__browse { color: var(--color-accent-readable); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }

.file-list { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-4); }
.file-row {
  display: grid; grid-template-columns: 24px 1fr auto auto; gap: var(--space-3);
  align-items: center;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}
.file-row__icon { width: 20px; height: 20px; color: var(--ink-muted); }
.file-row__meta { min-width: 0; }
.file-row__name { font: var(--type-body-strong); margin: 0 0 2px; }
.file-row__sub { font: var(--type-caption); color: var(--ink-subtle); margin: 0; }
.file-row__meta .progress { margin-top: 6px; max-width: 320px; }
.file-row--error .file-row__icon { color: var(--color-state-danger); }
.file-row--error .file-row__name { color: var(--color-state-danger); }

/* ---- Badges & tags ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  font: var(--type-body-strong);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-hover);
  color: var(--ink);
  border: 1px solid transparent;
  line-height: 1.5;
}
.badge svg { width: 11px; height: 11px; stroke-width: 2.5; flex: 0 0 auto; }
/* Status pills — solid coloured backgrounds with proper contrast text.
   Each state gets a hue-shifted dark-on-light combo so the colour is
   present without being shouty. */
.badge--info    {
  background: color-mix(in srgb, var(--color-state-info) 16%, var(--surface-raised));
  color: color-mix(in srgb, var(--color-state-info) 64%, var(--ink));
  border-color: color-mix(in srgb, var(--color-state-info) 32%, transparent);
}
.badge--success {
  background: color-mix(in srgb, var(--color-state-success) 16%, var(--surface-raised));
  color: color-mix(in srgb, var(--color-state-success) 70%, var(--ink));
  border-color: color-mix(in srgb, var(--color-state-success) 36%, transparent);
}
.badge--caution {
  background: color-mix(in srgb, var(--color-state-caution) 32%, var(--surface-raised));
  color: #6B5A00;
  border-color: color-mix(in srgb, var(--color-state-caution) 70%, transparent);
}
.badge--danger  {
  background: color-mix(in srgb, var(--color-state-danger) 14%, var(--surface-raised));
  color: color-mix(in srgb, var(--color-state-danger) 70%, var(--ink));
  border-color: color-mix(in srgb, var(--color-state-danger) 32%, transparent);
}
.badge--neutral { background: var(--surface-hover); color: var(--ink-muted); border-color: var(--border); }

/* Ink theme — back to brand colours for the text since the surface is dark */
[data-theme="ink"] .badge--info    { color: var(--brand-cyan); }
[data-theme="ink"] .badge--success { color: var(--brand-green); }
[data-theme="ink"] .badge--caution { color: var(--brand-yellow); }
[data-theme="ink"] .badge--danger  { color: var(--brand-magenta); }

.badge--count {
  min-width: 18px; height: 18px; padding: 0 6px;
  border-radius: 999px;
  background: var(--color-state-danger);
  color: #FFFFFF;
  font-size: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0;
}
.badge--count-strong { background: var(--brand-magenta); }
.badge--count-dot { min-width: 8px; width: 8px; height: 8px; padding: 0; }

.icon-with-badge { position: relative; display: inline-flex; }
.icon-with-badge .badge--count { position: absolute; top: -4px; right: -8px; }
.icon-with-badge i, .icon-with-badge svg { width: 20px; height: 20px; color: var(--ink); }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  font: var(--type-body);
  font-size: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  color: var(--ink-muted);
}
.tag--accent { background: color-mix(in srgb, var(--color-accent) 18%, transparent); color: var(--ink); border: 1px solid color-mix(in srgb, var(--color-accent) 36%, transparent); }
.tag--removable button { background: none; border: 0; color: inherit; cursor: pointer; padding: 0 2px; opacity: 0.6; font-size: 16px; line-height: 1; }
.tag--removable button:hover { opacity: 1; color: var(--color-state-danger); }

/* ---- Avatars ---- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--avatar-bg, var(--ink-subtle));
  color: #FFFFFF;
  font: var(--type-heading-sm);
  font-size: 13px;
  letter-spacing: 0;
  flex: 0 0 auto;
  border: 2px solid var(--surface);
  position: relative;
}
.avatar--xs { width: 20px; height: 20px; font-size: 9px; border-width: 1.5px; }
.avatar--sm { width: 24px; height: 24px; font-size: 10px; }
.avatar--lg { width: 48px; height: 48px; font-size: 18px; }

.avatar--with-status::after {
  content: ''; position: absolute; bottom: -2px; right: -2px;
  width: 10px; height: 10px;
  background: var(--status-color, var(--color-state-success));
  border-radius: 50%;
  border: 2px solid var(--surface);
}

.avatar-group { display: inline-flex; }
.avatar-group .avatar { margin-left: -8px; }
.avatar-group .avatar:first-child { margin-left: 0; }
.avatar--overflow {
  background: var(--surface-hover);
  color: var(--ink-muted);
  font-size: 10px;
}

/* ---- Tooltip ---- */
.tip-trigger { position: relative; display: inline-block; }
.tip-trigger::before {
  content: attr(data-tip);
  white-space: pre-line;
  position: absolute;
  background: var(--ink);
  color: var(--surface);
  font: var(--type-caption);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--motion-standard) var(--ease), transform var(--motion-standard) var(--ease);
  z-index: 30;
  max-width: 240px;
  white-space: nowrap;
}
.tip-trigger[data-tip*="\A"]::before { white-space: pre-line; }
.tip-trigger:hover::before, .tip-trigger:focus-within::before { opacity: 1; }
.tip-trigger[data-tip-pos="top"]::before    { bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px); }
.tip-trigger[data-tip-pos="bottom"]::before { top: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(-4px); }
.tip-trigger[data-tip-pos="left"]::before   { right: calc(100% + 8px); top: 50%; transform: translateY(-50%) translateX(4px); }
.tip-trigger[data-tip-pos="right"]::before  { left: calc(100% + 8px); top: 50%; transform: translateY(-50%) translateX(-4px); }
.tip-trigger:hover[data-tip-pos="top"]::before    { transform: translateX(-50%) translateY(0); }
.tip-trigger:hover[data-tip-pos="bottom"]::before { transform: translateX(-50%) translateY(0); }
.tip-trigger:hover[data-tip-pos="left"]::before   { transform: translateY(-50%) translateX(0); }
.tip-trigger:hover[data-tip-pos="right"]::before  { transform: translateY(-50%) translateX(0); }

/* ---- Alerts (action + body) ---- */
.alert { gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.alert__body { flex: 1; min-width: 0; }
.alert > .btn { flex: 0 0 auto; align-self: center; }
.alert > .btn--ghost.btn--sm svg { width: 14px; height: 14px; }

/* ---- Toasts ---- */
.toast-stack {
  position: fixed; bottom: 20px; left: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  min-width: 280px; max-width: 360px;
  padding: 12px 14px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-left: 4px solid var(--color-state-info);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  transform: translateX(-120%);
  opacity: 0;
  transition: transform var(--motion-panel) var(--ease), opacity var(--motion-panel) var(--ease);
}
.toast.is-in { transform: translateX(0); opacity: 1; }
.toast--success { border-left-color: var(--color-state-success); }
.toast--caution { border-left-color: var(--color-state-caution); }
.toast--danger  { border-left-color: var(--color-state-danger); }
.toast__icon { width: 18px; height: 18px; flex: 0 0 auto; }
.toast__icon svg { width: 18px; height: 18px; }
.toast--info .toast__icon { color: var(--color-state-info); }
.toast--success .toast__icon { color: var(--color-state-success); }
.toast--caution .toast__icon { color: var(--color-state-caution); }
.toast--danger  .toast__icon { color: var(--color-state-danger); }
.toast__msg { flex: 1; font: var(--type-body); }
.toast__close { flex: 0 0 auto; color: var(--ink-subtle); display: flex; align-items: center; justify-content: center; width: 20px; height: 20px; }
.toast__close:hover { color: var(--ink); }
.toast__close svg { width: 14px; height: 14px; }

/* ---- Modal & drawer ---- */
.modal, .drawer {
  position: fixed; inset: 0; z-index: 70;
  display: none;
}
.modal[aria-hidden="false"], .drawer[aria-hidden="false"] { display: block; }
.modal__backdrop, .drawer__backdrop {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--brand-navy) 60%, transparent);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: backdrop-in var(--motion-panel) var(--ease);
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

.modal__card {
  position: relative;
  max-width: 480px; width: calc(100% - 32px);
  margin: 10vh auto 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  animation: modal-in var(--motion-panel) var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.modal--full .modal__card { max-width: 720px; padding: 0; }
.modal--full .modal__head, .modal--full .modal__body, .modal--full .modal__foot { padding: var(--space-5) var(--space-6); }
.modal--full .modal__head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal--full .modal__foot { border-top: 1px solid var(--border); display: flex; gap: var(--space-2); justify-content: flex-end; }
.modal__title { font: var(--type-display-md); margin: 0 0 var(--space-3); }
.modal__body { color: var(--ink-muted); margin-bottom: var(--space-5); }
.modal__foot { display: flex; gap: var(--space-2); justify-content: flex-end; }

.drawer__panel {
  position: absolute; top: 0; bottom: 0;
  width: 360px; max-width: 90vw;
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.drawer--right .drawer__panel { right: 0; animation: drawer-in-right var(--motion-panel) var(--ease); border-left: 1px solid var(--border); }
.drawer--left  .drawer__panel { left: 0;  animation: drawer-in-left  var(--motion-panel) var(--ease); border-right: 1px solid var(--border); }
@keyframes drawer-in-right { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes drawer-in-left  { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.drawer__title { font: var(--type-display-md); margin: 0; }
.drawer__body { flex: 1; padding: var(--space-5); overflow-y: auto; }

/* ---- Tabs ---- */
.tabs__list {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
  gap: var(--space-4);
}
.tabs__tab {
  position: relative;
  padding: 10px 0 12px;
  font: var(--type-body-strong);
  font-size: 14px;
  color: var(--ink-muted);
  background: none; border: 0;
  cursor: pointer;
  transition: color var(--motion-standard) var(--ease);
}
.tabs__tab::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--ink);
  transform: scaleX(0); transform-origin: left;
  transition: transform var(--motion-standard) var(--ease);
}
.tabs__tab:hover { color: var(--ink); }
.tabs__tab.is-active { color: var(--ink); }
.tabs__tab.is-active::after { transform: scaleX(1); }
.tabs__panel { padding: var(--space-3) 0; }

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-hover);
  border-radius: var(--radius-md);
}
.segmented__opt {
  padding: 6px 12px;
  font: var(--type-body-strong);
  font-size: 12px;
  color: var(--ink-muted);
  background: none; border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--motion-standard) var(--ease), color var(--motion-standard) var(--ease);
}
.segmented__opt:hover { color: var(--ink); }
.segmented__opt.is-active { background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---- Accordion ---- */
.accordion { display: flex; flex-direction: column; gap: var(--space-2); }
.accordion__item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  overflow: hidden;
}
.accordion__item[open] { border-color: var(--border-strong); }
.accordion__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  font: var(--type-heading-md);
  cursor: pointer;
  list-style: none;
  transition: background var(--motion-standard) var(--ease);
}
.accordion__head::-webkit-details-marker { display: none; }
.accordion__head:hover { background: var(--surface-hover); }
.accordion__chevron { width: 16px; height: 16px; color: var(--ink-subtle); transition: transform var(--motion-standard) var(--ease); }
.accordion__item[open] .accordion__chevron { transform: rotate(180deg); color: var(--ink); }
.accordion__body { padding: 0 var(--space-4) var(--space-4); color: var(--ink-muted); font: var(--type-body); }
.accordion__body p { margin: 0; }

/* ---- Progress ---- */
.progress {
  height: 6px;
  background: var(--surface-hover);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: var(--radius-pill);
  transition: width var(--motion-panel) var(--ease);
}
.progress--indeterminate .progress__fill {
  width: 40% !important;
  animation: prog-slide 1.4s ease-in-out infinite;
}
@keyframes prog-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(280%); }
}
@media (prefers-reduced-motion: reduce) {
  .progress--indeterminate .progress__fill { animation: none; transform: translateX(0); }
}

/* ---- Stepper ---- */
.stepper { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stepper__step { display: flex; align-items: center; gap: 8px; font: var(--type-body-strong); font-size: 13px; color: var(--ink-muted); }
.stepper__dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-hover);
  color: var(--ink-muted);
  font: var(--type-mono); font-size: 11px;
  border: 1.5px solid var(--border-strong);
}
.stepper__dot svg { width: 12px; height: 12px; }
.stepper__step--done { color: var(--ink); }
.stepper__step--done .stepper__dot { background: var(--color-state-success); border-color: var(--color-state-success); color: #FFFFFF; }
.stepper__step--active { color: var(--ink); }
.stepper__step--active .stepper__dot { background: var(--color-accent); border-color: var(--color-accent); color: var(--ink); font-weight: 700; }
.stepper__line { flex: 1; min-width: 24px; height: 2px; background: var(--border); border-radius: 1px; }
.stepper__line--done { background: var(--color-state-success); }

/* ---- Spinner ---- */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
}
.spinner--sm { width: 12px; height: 12px; border-width: 1.5px; }
.spinner--lg { width: 28px; height: 28px; border-width: 3px; }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---- Skeleton ---- */
.skeleton-stack { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-3); }
.skeleton {
  background: linear-gradient(90deg, var(--surface-hover) 0%, var(--surface-sunken) 50%, var(--surface-hover) 100%);
  background-size: 200% 100%;
  animation: skel-pulse 1.8s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton--text { height: 14px; }
.skeleton--rect { width: 100%; border-radius: var(--radius-md); }
@keyframes skel-pulse {
  0%, 100% { background-position: 200% 0; }
  50%      { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---- Kbd ---- */
kbd {
  display: inline-flex; align-items: center;
  min-width: 22px; height: 22px;
  padding: 0 6px;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  font: var(--type-mono);
  font-size: 11px;
  color: var(--ink);
  margin: 0 2px;
}

code {
  font: var(--type-mono);
  font-size: 12px;
  padding: 1px 6px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--ink);
}
