/* ==========================================================================
   Components — all values reference tokens from main.css. No raw hex.
   Shape language from inspire.jpg: hairline borders, near-flat elevation,
   uniform 16px card radius, pill for every interactive chip/button.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-6);
  transition: border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}

.card--flush { padding: 0; }

.card--hover:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* The one deliberately inverted block — per inspire.jpg's black accent card */
.card--invert {
  background: var(--bg-invert);
  border-color: var(--bg-invert);
  color: var(--fg-invert);
}

.card--invert .card__label,
.card--invert .card__meta { color: var(--fg-invert-dim); }

.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.card__label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--fg-dim);
  line-height: var(--lh-snug);
}

.card__title {
  font-size: var(--fs-md);
  font-weight: 650;
}

.card__meta {
  font-size: var(--fs-xs);
  color: var(--fg-dim);
}

/* --------------------------------------------------------------------------
   Stat card — big heavy numeral is the display element
   -------------------------------------------------------------------------- */

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.stat__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.stat__icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  background: var(--bg-inset);
  color: var(--fg-dim);
  flex: none;
}

.stat__icon--invert {
  background: var(--bg-invert);
  color: var(--fg-invert);
}

.card--invert .stat__icon {
  background: var(--border-invert);
  color: var(--fg-invert);
}

.stat__value {
  font-family: var(--font-display);
  font-size: var(--fs-stat);
  font-weight: 700;
  letter-spacing: var(--tracking-stat);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: var(--fs-sm);
  color: var(--fg-dim);
}

.card--invert .stat__label { color: var(--fg-invert-dim); }

/* --------------------------------------------------------------------------
   Grid
   -------------------------------------------------------------------------- */

.grid {
  display: grid;
  gap: var(--sp-4);
}

.grid--stats {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.grid--split {
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
}

.grid--cards {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid + .grid { margin-top: var(--sp-4); }

@media (max-width: 1100px) {
  .grid--split { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Buttons — primary is black pill, everything else is ghost/outline pill
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 38px;
  padding: 0 var(--sp-5);
  border-radius: var(--radius-pill);
  font-size: var(--fs-base);
  font-weight: 550;
  white-space: nowrap;
  transition: background var(--dur) var(--ease),
              color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              transform var(--dur-fast) var(--ease),
              box-shadow var(--dur) var(--ease);
}

.btn:active { transform: scale(0.98); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.btn--primary {
  background: var(--accent);
  color: var(--fg-invert);
  border: 1px solid var(--accent);
}

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

.btn--ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  background: var(--bg-inset);
  border-color: var(--border-strong);
}

.btn--soft {
  background: var(--bg-inset);
  color: var(--fg);
  border: 1px solid transparent;
}

.btn--soft:hover {
  border-color: var(--border);
}

/* Destructive action. The palette is single-hue cool, so "danger" is the
   deepest blue rather than red — it reads as weight, not alarm. */
.btn--danger {
  background: var(--blue-900);
  color: var(--fg-invert);
  border: 1px solid var(--blue-900);
}

.btn--danger:hover {
  background: var(--blue-500);
  border-color: var(--blue-500);
}

.btn--sm {
  height: 30px;
  padding: 0 var(--sp-4);
  font-size: var(--fs-sm);
}

.btn--icon {
  width: 38px;
  padding: 0;
}

.btn--icon.btn--sm { width: 30px; }

.btn__icon {
  width: 16px;
  height: 16px;
  flex: none;
}

/* --------------------------------------------------------------------------
   Pills / chips / badges
   -------------------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 24px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  background: var(--bg-inset);
  color: var(--fg);
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill--outline {
  background: transparent;
  border-color: var(--border);
}

.pill--invert {
  background: var(--bg-invert);
  color: var(--fg-invert);
}

.pill--accent {
  background: var(--accent-soft);
  color: var(--blue-500);
}

.pill--danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.pill--warn {
  background: var(--warn-surface);
  border-color: transparent;
  color: var(--warn-on);
}

.pill--success {
  background: var(--success-surface);
  border-color: transparent;
  color: var(--success-on);
}

/* Filled danger for delete confirmations — the one high-urgency surface */
.pill--danger-fill {
  background: var(--danger-surface);
  border-color: transparent;
  color: var(--danger-on);
}

.pill__dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: currentColor;
  flex: none;
}

/* Notification count badge on an avatar */
.badge-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-invert);
  color: var(--fg-invert);
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Table — banded rows, comfortable height, trailing actions
   -------------------------------------------------------------------------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}

.table th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr {
  transition: background var(--dur-fast) var(--ease);
}

.table tbody tr:hover { background: var(--gray-25); }

.table tbody tr:last-child td { border-bottom: 0; }

.table tbody tr.is-selected { background: var(--accent-soft); }

.table__actions {
  display: flex;
  gap: var(--sp-1);
  justify-content: flex-end;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.field__label {
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--fg);
}

.field__hint {
  font-size: var(--fs-xs);
  color: var(--fg-dim);
}

.field__error {
  font-size: var(--fs-xs);
  color: var(--danger);
  font-weight: 550;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px var(--sp-4);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  color: var(--fg);
  transition: border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}

.input::placeholder,
.textarea::placeholder { color: var(--border-strong); }

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--border-strong); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea { border-color: var(--danger); }

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: var(--lh-normal);
}

.select {
  appearance: none;
  padding-right: var(--sp-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%238a8a8a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-4) center;
  cursor: pointer;
}

.select:disabled {
  background: var(--bg-inset);
  color: var(--fg-dim);
  cursor: not-allowed;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
}

.form-grid--full { grid-column: 1 / -1; }

/* Search input with leading icon */
.search {
  position: relative;
  min-width: 220px;
}

.search .input { padding-left: var(--sp-10); }

.search__icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--fg-dim);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Segmented control — for choosing fiche type
   -------------------------------------------------------------------------- */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg-inset);
  border-radius: var(--radius-pill);
}

.segmented__item {
  padding: 7px var(--sp-4);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--fg-dim);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.segmented__item:hover { color: var(--fg); }

.segmented__item[aria-pressed="true"],
.segmented__item.is-active {
  background: var(--bg-panel);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
  background: var(--scrim);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - var(--sp-12));
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}

.modal--wide { max-width: 760px; }

/* A form-wrapped modal must keep the flex chain going: .modal is a column
   flex container, but its child is the <form>, so the form has to be the
   flex item that shrinks (min-height:0) for .modal__body to scroll. Without
   this the footer sits below the viewport on short screens. */
.modal > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-6) var(--sp-4);
}

.modal__title {
  font-size: var(--fs-lg);
  font-weight: 650;
}

.modal__desc {
  margin-top: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--fg-dim);
}

.modal__body {
  padding: 0 var(--sp-6) var(--sp-5);
  overflow-y: auto;
}

.modal__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  background: var(--gray-25);
}

.modal__close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  color: var(--fg-dim);
  flex: none;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.modal__close:hover {
  background: var(--bg-inset);
  color: var(--fg);
}

/* --------------------------------------------------------------------------
   Progress — determinate bar with % while generating
   -------------------------------------------------------------------------- */

.progress {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  background: var(--bg-invert);
  transition: width var(--dur-slow) var(--ease-out);
}

.progress__meta {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--fg-dim);
}

.progress__pct {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--fg);
}

/* Step list during generation */
.steps-status {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}

.steps-status__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--fg-dim);
  transition: color var(--dur) var(--ease);
}

.steps-status__item.is-done { color: var(--fg); }

.steps-status__bullet {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex: none;
  font-size: 10px;
  font-weight: 700;
}

.steps-status__item.is-done .steps-status__bullet {
  background: var(--bg-invert);
  border-color: var(--bg-invert);
  color: var(--fg-invert);
}

/* --------------------------------------------------------------------------
   Skeleton — matches real element dimensions to avoid layout shift
   -------------------------------------------------------------------------- */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-inset) 0%,
    var(--gray-25) 50%,
    var(--bg-inset) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: skeleton-sweep 1.3s var(--ease) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--bg-inset); }
}

.skeleton--text { height: 12px; }
.skeleton--title { height: 22px; width: 40%; }
.skeleton--stat { height: 42px; width: 60%; }
.skeleton--block { height: 120px; }
.skeleton--circle { border-radius: var(--radius-pill); }

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-12) var(--sp-6);
}

.empty__icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  background: var(--bg-inset);
  color: var(--fg-dim);
  margin-bottom: var(--sp-1);
}

.empty__title {
  font-size: var(--fs-md);
  font-weight: 600;
}

.empty__text {
  font-size: var(--fs-sm);
  color: var(--fg-dim);
  max-width: 42ch;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  right: var(--sp-6);
  bottom: var(--sp-6);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-pill);
  background: var(--bg-invert);
  color: var(--fg-invert);
  font-size: var(--fs-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

.toast--danger  { background: var(--blue-500); color: var(--fg-invert); }
.toast--warn    { background: var(--blue-400); color: var(--fg-invert); }
.toast--success { background: var(--blue-500); color: var(--fg-invert); }

/* --------------------------------------------------------------------------
   Inline edit — contenteditable regions
   -------------------------------------------------------------------------- */

.editable {
  border-radius: var(--radius-xs);
  outline: none;
  transition: background var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
  padding: 2px 4px;
  margin: -2px -4px;
}

.editable:hover { background: var(--gray-25); }

.editable:focus {
  background: var(--bg-panel);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.editable.is-saving { opacity: 0.6; }

.editable[data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: var(--border-strong);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Divider + utility
   -------------------------------------------------------------------------- */

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

.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-2); }
.row--between { justify-content: space-between; }
.spacer { flex: 1; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
