/*
 * ============================================================
 * Feralism Component Library — fe-*
 * ============================================================
 *
 * Convention: BEM
 *   .fe-block              block
 *   .fe-block__element     element of a block
 *   .fe-block--modifier    variant of a block or element
 *
 * Consumes design tokens from feralism-base.css and
 * marketplace/design-tokens.css. Defines no variables of its own.
 *
 * Policy:
 *   - Zero JavaScript. Interactivity uses native HTML
 *     (<details>/<summary>, <dialog>, <a>, <button>).
 *   - E-ink optimised: variants differ by SHAPE (border-style,
 *     border-width, weight, geometry) in addition to colour.
 *   - Privacy-first: no external assets, no font URLs, no tracking.
 *
 * This file is the canonical replacement for any Bootstrap-derived
 * vocabulary. New templates use .fe-* exclusively.
 * ============================================================ */


/* ============================================================
   1. ACCESSIBILITY HELPERS
   ============================================================ */

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


/* ============================================================
   2. LAYOUT — container, grid, stack, spacer
   ============================================================ */

.fe-container {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  padding-inline: var(--space-lg);
}
.fe-container--narrow { max-width: 720px; }
.fe-container--wide { max-width: 1280px; }

/* Grid — auto fits items at a sensible min, with a fixed gap.
   Mobile collapse handled by minmax/auto-fit, not media queries. */
.fe-grid {
  display: grid;
  gap: var(--space-lg);
}
.fe-grid--2col { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.fe-grid--3col { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.fe-grid--4col { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.fe-grid--sidebar {
  grid-template-columns: 220px 1fr;
  gap: var(--space-xl);
}
@media (max-width: 720px) {
  .fe-grid--sidebar { grid-template-columns: 1fr; }
}

/* Stack — vertical rhythm via gap. Default uses --space-lg. */
.fe-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}
.fe-stack--tight { gap: var(--space-sm); }
.fe-stack--snug  { gap: var(--space-md); }
.fe-stack--loose { gap: var(--space-xl); }
.fe-stack--xl    { gap: var(--space-2xl); }

/* Cluster — horizontal stack that wraps. For inline chip-like rows. */
.fe-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}

/* Spacer — deliberate vertical whitespace where stack/grid don't fit. */
.fe-spacer--sm { height: var(--space-md); }
.fe-spacer--md { height: var(--space-xl); }
.fe-spacer--lg { height: var(--space-2xl); }


/* ============================================================
   3. BUTTONS
   ============================================================ */

.fe-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: var(--space-sm) var(--space-lg);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

/* Primary — solid fill, dominant. */
.fe-button--primary {
  background: var(--gold);
  color: var(--white);
  border-color: var(--gold);
}
.fe-button--primary:hover,
.fe-button--primary:focus-visible {
  background: var(--gold-dark);
  border-color: var(--gold-dark);
  color: var(--white);
}

/* Secondary — outlined, gold text. SHAPE: 2px solid outline. */
.fe-button--secondary {
  background: var(--white);
  color: var(--gold-dark);
  border-color: var(--gold-dark);
}
.fe-button--secondary:hover,
.fe-button--secondary:focus-visible {
  background: var(--gold-dark);
  color: var(--white);
}

/* Destructive — distinguishable on e-ink by DASHED border. */
.fe-button--destructive {
  background: var(--white);
  color: #721c24;
  border-color: #721c24;
  border-style: dashed;
}
.fe-button--destructive:hover,
.fe-button--destructive:focus-visible {
  background: #721c24;
  color: var(--white);
  border-style: solid;
}

/* Subtle — minimal chrome, for tertiary actions. */
.fe-button--subtle {
  background: transparent;
  color: var(--charcoal);
  border-color: var(--pale-gray);
  border-width: 1px;
  font-weight: 500;
}
.fe-button--subtle:hover,
.fe-button--subtle:focus-visible {
  background: var(--off-white);
  border-color: var(--medium-gray);
  color: var(--charcoal);
}

/* Link — text only, no chrome. For inline cancel/back navigation. */
.fe-button--link {
  background: transparent;
  color: var(--gold-dark);
  border: none;
  padding: 0;
  min-height: 0;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.fe-button--link:hover,
.fe-button--link:focus-visible {
  color: var(--gold);
}

/* Sizes */
.fe-button--small {
  min-height: 36px;
  padding: var(--space-xs) var(--space-md);
  font-size: var(--text-sm);
}
.fe-button--large {
  min-height: 52px;
  padding: var(--space-md) var(--space-2xl);
  font-size: var(--text-lg);
}

/* Width */
.fe-button--full {
  width: 100%;
}

/* Disabled — applies to all variants. */
.fe-button[disabled],
.fe-button--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Form actions row — buttons aligned together. */
.fe-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: center;
  margin-top: var(--space-xl);
}


/* ============================================================
   4. FORM FIELDS
   ============================================================ */

.fe-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.fe-field__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--charcoal);
  line-height: 1.3;
}

.fe-field__required {
  color: var(--gold-dark);
  font-weight: 700;
  margin-left: 2px;
}

.fe-field__control {
  display: block;
}

/* Style raw inputs/selects/textareas inside any field control. */
.fe-field__control input[type="text"],
.fe-field__control input[type="email"],
.fe-field__control input[type="password"],
.fe-field__control input[type="tel"],
.fe-field__control input[type="url"],
.fe-field__control input[type="number"],
.fe-field__control input[type="search"],
.fe-field__control input[type="date"],
.fe-field__control input[type="time"],
.fe-field__control input[type="datetime-local"],
.fe-field__control select,
.fe-field__control textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.4;
  color: var(--charcoal);
  background: var(--white);
  border: 1px solid var(--medium-gray);
  border-radius: 4px;
  transition: border-color var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.fe-field__control textarea {
  min-height: 120px;
  resize: vertical;
}

/* Select chevron via background-image inline SVG, no JS. */
.fe-field__control select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M6 8 0 0h12z' fill='%231a1a1a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-md) center;
  background-size: 10px 7px;
  padding-right: var(--space-2xl);
}

/* Placeholder text — italic + lighter colour, distinct from real input. */
.fe-field__control input::placeholder,
.fe-field__control textarea::placeholder {
  font-style: italic;
  color: var(--gray);
  opacity: 1;
}

/* Focus state — gold outline. */
.fe-field__control input:focus,
.fe-field__control select:focus,
.fe-field__control textarea:focus {
  outline: 3px solid var(--gold);
  outline-offset: 1px;
  border-color: var(--gold-dark);
}

/* Checkbox & radio — keep native, with extra spacing. */
.fe-field__control input[type="checkbox"],
.fe-field__control input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  margin-right: var(--space-xs);
  vertical-align: middle;
  cursor: pointer;
  accent-color: var(--gold-dark);
}

/* Help text — shown below the control. */
.fe-field__help {
  font-size: var(--text-sm);
  color: var(--medium-gray);
  line-height: 1.4;
  margin: 0;
}

/* Error text — shown below; red + bold. Field gets shape change too. */
.fe-field__error {
  font-size: var(--text-sm);
  color: #721c24;
  font-weight: 600;
  line-height: 1.4;
  margin: 0;
}

/* Error state — DOUBLE border on the control, not only red.
   On e-ink the doubled border distinguishes error fields from normal ones. */
.fe-field--error .fe-field__control input,
.fe-field--error .fe-field__control select,
.fe-field--error .fe-field__control textarea {
  border-color: #721c24;
  border-style: double;
  border-width: 3px;
}

/* Inline field — for checkbox/radio rows where label is to the right. */
.fe-field--inline {
  flex-direction: row;
  align-items: center;
  gap: var(--space-sm);
}
.fe-field--inline .fe-field__label { font-weight: 500; }

/* Fieldset — semantic grouping. */
.fe-fieldset {
  border: 1px solid var(--pale-gray);
  border-radius: 4px;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.fe-fieldset__legend {
  padding: 0 var(--space-sm);
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  color: var(--charcoal);
}


/* ============================================================
   5. CARD
   ============================================================ */

.fe-card {
  background: var(--white);
  border: 1px solid var(--pale-gray);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
}

.fe-card__header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--pale-gray);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
}

.fe-card__title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  margin: 0;
  color: var(--charcoal);
  line-height: 1.3;
}

.fe-card__body {
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.fe-card__footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--pale-gray);
  background: var(--off-white);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}

/* Variant: flat — no border. For nested or grouped cards. */
.fe-card--flat {
  border: none;
  background: var(--off-white);
}

/* Variant: emphasised — gold rule on top. For the primary CTA card on a page. */
.fe-card--emphasised {
  border-top: 3px solid var(--gold);
}


/* ============================================================
   6. NOTICE — inline / flash messages
   ============================================================ */

.fe-notice {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--off-white);
  border-left: 3px solid var(--medium-gray);
  border-radius: 0 4px 4px 0;
}

.fe-notice__icon {
  flex-shrink: 0;
  font-weight: 700;
  font-size: var(--text-lg);
  line-height: 1.4;
}

.fe-notice__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.fe-notice__title {
  font-weight: 700;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--charcoal);
  line-height: 1.3;
}

.fe-notice__text {
  font-size: var(--text-base);
  color: var(--dark-gray);
  line-height: 1.5;
  margin: 0;
}

/* Variants — colour + DISTINCT BORDER STYLE so each is unmistakable on e-ink. */
.fe-notice--info {
  border-left-style: solid;
  border-left-color: #0c5460;
}
.fe-notice--info .fe-notice__icon { color: #0c5460; }

.fe-notice--success {
  border-left-style: double;
  border-left-width: 5px;
  border-left-color: #1e7e34;
}
.fe-notice--success .fe-notice__icon { color: #1e7e34; }

.fe-notice--warning {
  border-left-style: dashed;
  border-left-color: #856404;
}
.fe-notice--warning .fe-notice__icon { color: #856404; }

.fe-notice--danger {
  border-left-style: solid;
  border-left-width: 5px;
  border-left-color: #721c24;
  background: #f8d7da;
}
.fe-notice--danger .fe-notice__icon { color: #721c24; }


/* ============================================================
   7. TABLE
   ============================================================ */

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

.fe-table th,
.fe-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--pale-gray);
  vertical-align: top;
}

.fe-table th {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--medium-gray);
  background: var(--off-white);
  border-bottom: 2px solid var(--charcoal);
}

.fe-table--zebra tbody tr:nth-child(even) {
  background: var(--off-white);
}

.fe-table--compact th,
.fe-table--compact td {
  padding: var(--space-xs) var(--space-sm);
}

.fe-table--borderless th,
.fe-table--borderless td {
  border: none;
}

/* Wrap long tables in this for horizontal-scroll on narrow screens. */
.fe-table-responsive {
  overflow-x: auto;
  border: 1px solid var(--pale-gray);
  border-radius: 4px;
}


/* ============================================================
   8. BADGE
   ============================================================ */

.fe-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-sm);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
  border-radius: 999px;
  border: 2px solid transparent;
  white-space: nowrap;
}

.fe-badge--neutral {
  background: var(--charcoal);
  color: var(--white);
  border-color: var(--charcoal);
}

/* Status variants — distinct BORDER STYLE per state for e-ink. */
.fe-badge--success {
  background: var(--white);
  color: #1e7e34;
  border-color: #1e7e34;
  border-style: solid;
}

.fe-badge--warning {
  background: var(--white);
  color: #856404;
  border-color: #856404;
  border-style: dashed;
}

.fe-badge--danger {
  background: var(--white);
  color: #721c24;
  border-color: #721c24;
  border-style: double;
  border-width: 3px;
}

.fe-badge--info {
  background: var(--white);
  color: #0c5460;
  border-color: #0c5460;
  border-style: dotted;
}


/* ============================================================
   9. BREADCRUMB
   ============================================================ */

.fe-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  align-items: center;
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--text-sm);
  color: var(--medium-gray);
}

.fe-breadcrumb__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

.fe-breadcrumb__item a {
  color: var(--medium-gray);
  text-decoration: none;
}

.fe-breadcrumb__item a:hover,
.fe-breadcrumb__item a:focus-visible {
  color: var(--gold-dark);
  text-decoration: underline;
}

.fe-breadcrumb__separator {
  color: var(--light-gray);
  user-select: none;
}

.fe-breadcrumb__current {
  color: var(--charcoal);
  font-weight: 600;
}


/* ============================================================
   10. EMPTY STATE
   ============================================================ */

.fe-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-md);
  padding: var(--space-2xl) var(--space-lg);
  background: var(--off-white);
  border: 1px dashed var(--light-gray);
  border-radius: 4px;
}

.fe-empty-state__title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  color: var(--charcoal);
  margin: 0;
  line-height: 1.3;
}

.fe-empty-state__description {
  font-size: var(--text-base);
  color: var(--medium-gray);
  max-width: 480px;
  line-height: 1.5;
  margin: 0;
}

.fe-empty-state__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
  margin-top: var(--space-sm);
}


/* ============================================================
   11. PAGINATION
   ============================================================ */

.fe-pagination {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  list-style: none;
  padding: 0;
  margin: var(--space-lg) 0 0;
  align-items: center;
}

.fe-pagination__item { display: inline-flex; }

.fe-pagination__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 var(--space-sm);
  border: 1px solid var(--pale-gray);
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--charcoal);
  text-decoration: none;
  background: var(--white);
  transition: var(--transition);
}

.fe-pagination__link:hover,
.fe-pagination__link:focus-visible {
  background: var(--off-white);
  border-color: var(--medium-gray);
  color: var(--gold-dark);
}

.fe-pagination__current {
  background: var(--charcoal);
  color: var(--white);
  border-color: var(--charcoal);
  cursor: default;
}

.fe-pagination__current:hover {
  background: var(--charcoal);
  color: var(--white);
}

.fe-pagination__ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  color: var(--medium-gray);
  user-select: none;
}


/* ============================================================
   12. DISCLOSURE — native <details> styling
   Replaces JS dropdowns/accordions across the site.
   Usage:
     <details class="fe-disclosure">
       <summary>Trigger label</summary>
       <div class="fe-disclosure__panel">…content…</div>
     </details>
   ============================================================ */

.fe-disclosure {
  border: 1px solid var(--pale-gray);
  border-radius: 4px;
  background: var(--white);
}

.fe-disclosure > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-sm) var(--space-md);
  font-weight: 600;
  color: var(--charcoal);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  user-select: none;
}

.fe-disclosure > summary::-webkit-details-marker { display: none; }

/* Caret indicator that rotates when open. Pure CSS, no JS. */
.fe-disclosure > summary::after {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--medium-gray);
  border-bottom: 2px solid var(--medium-gray);
  transform: rotate(45deg);
  transition: transform var(--transition);
  flex-shrink: 0;
}

.fe-disclosure[open] > summary::after {
  transform: rotate(-135deg);
}

.fe-disclosure[open] > summary {
  border-bottom: 1px solid var(--pale-gray);
}

.fe-disclosure__panel {
  padding: var(--space-md);
}


/* ============================================================
   13. PAGE HEADER — reusable header for content pages
   ============================================================ */

.fe-page-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--pale-gray);
}

.fe-page-header__title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  color: var(--charcoal);
  margin: 0;
  line-height: 1.2;
}

.fe-page-header__subtitle {
  font-size: var(--text-base);
  color: var(--medium-gray);
  margin: 0;
  line-height: 1.5;
}

.fe-page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}


/* ============================================================
   14. TEXT UTILITIES — minimal, used only when shape needs help
   ============================================================ */

.fe-text-muted   { color: var(--medium-gray); }
.fe-text-meta    { font-size: var(--text-sm); color: var(--medium-gray); }
.fe-text-strong  { font-weight: 700; color: var(--charcoal); }


/* ============================================================
   15. E-INK / HIGH-CONTRAST / REDUCED-MOTION OVERRIDES
   These layer on top of the base feralism-base.css overrides.
   ============================================================ */

@media (prefers-contrast: more), (prefers-contrast: high) {
  .fe-button { border-width: 3px; }
  .fe-card,
  .fe-fieldset,
  .fe-disclosure { border-color: var(--charcoal); }
  .fe-notice { border-left-width: 5px; }
  .fe-badge { border-width: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  .fe-button,
  .fe-field__control input,
  .fe-field__control select,
  .fe-field__control textarea,
  .fe-disclosure > summary::after,
  .fe-pagination__link {
    transition: none !important;
  }
}

@media print {
  .fe-button {
    border: 1px solid #000 !important;
    background: transparent !important;
    color: #000 !important;
  }
  .fe-card,
  .fe-notice,
  .fe-badge,
  .fe-fieldset { border-color: #000 !important; }
}
