/* ============================================================================
   Mandy — Design System · Components
   ----------------------------------------------------------------------------
   Framework-free. Every class is namespaced `m-` and standalone, so each maps
   to one ERB partial. Depends only on tokens.css. Interactive behaviour lives
   in Stimulus controllers (data-controller="…") — see mandy/controllers/.
   ============================================================================ */

/* —— Base / typography helpers ———————————————————————————————————————————— */
.m-body { font-family: var(--font-sans); font-size: var(--text-base); line-height: var(--leading); color: var(--text-default); background: var(--bg); }
.m-h1 { font-size: var(--text-2xl); font-weight: var(--fw-bold); letter-spacing: -.02em; color: var(--text-strong); margin: 0; }
.m-h2 { font-size: var(--text-xl); font-weight: var(--fw-bold); letter-spacing: -.015em; color: var(--text-strong); margin: 0; }
.m-h3 { font-size: var(--text-lg); font-weight: var(--fw-semibold); color: var(--text-strong); margin: 0; }
/* Display headings and the brand lockup use the Varela Round brand face. Its
   rounded shapes don't want negative tracking, so reset letter-spacing. */
.m-h1, .m-h2, .m-h3, .m-sidebar__name, .m-auth__name { font-family: var(--font-display); letter-spacing: normal; }
.m-text-muted { color: var(--text-muted); }
.m-link { color: var(--brand-text); font-weight: var(--fw-semibold); text-decoration: none; }
.m-link:hover { text-decoration: underline; }

/* —— Buttons ——————————————————————————————————————————————————————————————
   <button class="m-btn m-btn--primary">Label</button>
   Variants: --primary --secondary --ghost --danger · Sizes: --sm --lg · --icon */
.m-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 42px; padding: 0 18px;
  font-family: var(--font-sans); font-size: var(--text-base); font-weight: var(--fw-semibold);
  border: 1px solid transparent; border-radius: var(--radius-md);
  background: transparent; color: var(--text-default);
  cursor: pointer; white-space: nowrap; user-select: none;
  /* Only transition interaction effects, NOT background/border-color: those derive
     from themed custom properties, and transitioning them freezes the old value
     when the theme/brand token changes on <html>. */
  transition: filter .12s ease, box-shadow .12s ease;
}
.m-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.m-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }
.m-btn:disabled { opacity: .5; cursor: not-allowed; }

.m-btn--primary   { background: var(--brand); color: var(--brand-on); box-shadow: var(--shadow-sm); }
.m-btn--primary:hover:not(:disabled)   { filter: brightness(1.06); }
.m-btn--secondary { background: var(--surface); color: var(--text-default); border-color: var(--border-strong); }
.m-btn--secondary:hover:not(:disabled) { border-color: var(--text-muted); }
.m-btn--ghost     { background: transparent; color: var(--text-default); border-color: transparent; }
.m-btn--ghost:hover:not(:disabled)     { background: var(--row-hover); }
.m-btn--danger    { background: var(--danger); color: #fff; }
.m-btn--danger:hover:not(:disabled)    { filter: brightness(1.06); }

.m-btn--sm   { height: 34px; padding: 0 13px; font-size: var(--text-sm); }
.m-btn--lg   { height: 48px; padding: 0 24px; font-size: var(--text-md); }
.m-btn--icon { width: 42px; height: 42px; padding: 0; }
.m-btn--icon.m-btn--sm { width: 34px; height: 34px; }
.m-btn--block { display: flex; width: 100%; }

/* —— Form fields ——————————————————————————————————————————————————————————
   <label class="m-label">…</label><input class="m-input"> */
.m-label { display: block; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-strong); margin-bottom: var(--space-2); }
.m-input, .m-select, .m-textarea {
  width: 100%; height: 42px; padding: 0 13px;
  font-family: var(--font-sans); font-size: var(--text-base); color: var(--text-default);
  background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  transition: box-shadow .12s ease;
}
.m-textarea { height: auto; min-height: 96px; padding: 11px 13px; resize: vertical; line-height: var(--leading); }
.m-input::placeholder, .m-textarea::placeholder { color: var(--text-muted); }
.m-input:focus, .m-select:focus, .m-textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.m-input:disabled, .m-select:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
.m-input--error, .m-input--error:focus { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
.m-select {
  appearance: none; cursor: pointer; padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b938d' stroke-width='2' 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;
}
.m-help  { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); }
.m-error { font-size: var(--text-sm); color: var(--danger); margin-top: var(--space-2); }

/* Field with leading icon: <div class="m-field"><svg/><input class="m-field__input"></div> */
.m-field { display: flex; align-items: center; gap: var(--space-2); height: 42px; padding: 0 13px; background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: var(--radius-md); }
.m-field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.m-field svg { width: 17px; height: 17px; color: var(--text-muted); flex-shrink: 0; }
.m-field__input { flex: 1; min-width: 0; border: none; outline: none; background: none; font: inherit; color: var(--text-default); }
.m-field__input::placeholder { color: var(--text-muted); }

/* —— Checkbox / Radio / Switch ————————————————————————————————————————————— */
.m-check, .m-radio { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-base); color: var(--text-default); cursor: pointer; }
.m-check input, .m-radio input { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.m-switch { position: relative; display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.m-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.m-switch__track { width: 40px; height: 22px; border-radius: var(--radius-pill); background: var(--border-strong); flex-shrink: 0; }
.m-switch__track::after { content: ""; position: absolute; left: 3px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: left .15s ease; }
.m-switch input:checked + .m-switch__track { background: var(--brand); }
.m-switch input:checked + .m-switch__track::after { left: 21px; }
.m-switch input:focus-visible + .m-switch__track { box-shadow: 0 0 0 3px var(--brand-ring); }

/* —— Badges / status ——————————————————————————————————————————————————————
   <span class="m-badge m-badge--success">Encaissé</span> · --dot for a leading dot */
.m-badge { display: inline-flex; align-items: center; gap: var(--space-2); padding: 4px 11px; font-size: var(--text-sm); font-weight: var(--fw-semibold); line-height: 1.4; border-radius: var(--radius-pill); }
.m-badge--brand   { background: var(--brand-soft);   color: var(--brand-text); }
.m-badge--info    { background: var(--info-soft);    color: var(--info); }
.m-badge--success { background: var(--success-soft); color: var(--success); }
.m-badge--warning { background: var(--warning-soft); color: var(--warning); }
.m-badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.m-badge--neutral { background: var(--surface-2);    color: var(--text-muted); border: 1px solid var(--border); }
.m-badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* —— Avatar ———————————————————————————————————————————————————————————————— */
.m-avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-text); font-size: var(--text-sm); font-weight: var(--fw-bold); }
.m-avatar--sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.m-avatar--lg { width: 44px; height: 44px; font-size: var(--text-md); }

/* —— Card —————————————————————————————————————————————————————————————————— */
.m-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); overflow: hidden; }
.m-card--flat { box-shadow: none; }
.m-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.m-card__title { font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); }
.m-card__body { padding: var(--space-5); }
.m-card__foot { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: flex-end; gap: var(--space-3); }

/* —— Stat card ————————————————————————————————————————————————————————————— */
.m-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-sm); }
.m-stat__top { display: flex; align-items: center; gap: var(--space-3); }
.m-stat__icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--radius-md); background: var(--brand-soft); color: var(--brand-text); }
.m-stat__icon svg { width: 19px; height: 19px; }
.m-stat__label { font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-muted); }
.m-stat__value { display: flex; align-items: baseline; gap: var(--space-3); margin-top: var(--space-3); font-size: var(--text-3xl); font-weight: var(--fw-bold); letter-spacing: -.02em; color: var(--text-strong); white-space: nowrap; }
.m-stat__delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--success); white-space: nowrap; }
.m-stat__delta svg { width: 13px; height: 13px; }

/* —— Tabs ——————————————————————————————————————————————————————————————————
   <div class="m-tabs" data-controller="tabs"> <button class="m-tab is-active">…</button> */
.m-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.m-tab { padding: 12px 16px; border: none; background: none; font: inherit; font-size: var(--text-base); font-weight: var(--fw-medium); color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; cursor: pointer; }
.m-tab:hover { color: var(--text-default); background: var(--row-hover); }
.m-tab.is-active { color: var(--brand-text); border-bottom-color: var(--brand); font-weight: var(--fw-semibold); }

/* —— Table ————————————————————————————————————————————————————————————————— */
.m-table-wrap { overflow-x: auto; }
.m-table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.m-table th { text-align: left; padding: 13px 16px; font-size: var(--text-xs); font-weight: var(--fw-semibold); letter-spacing: .02em; color: var(--text-muted); background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); white-space: nowrap; }
.m-table td { padding: 15px 16px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text-default); }
.m-table tbody tr:last-child td { border-bottom: none; }
.m-table tbody tr:hover td { background: var(--row-hover); }
.m-table--compact th, .m-table--compact td { padding-top: 10px; padding-bottom: 10px; }
.m-table__num { text-align: right; font-variant-numeric: tabular-nums; }
.m-cell-strong { font-weight: var(--fw-semibold); color: var(--text-strong); }
.m-cell-ref { font-weight: var(--fw-semibold); color: var(--brand-text); }
.m-cell-sub { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }

/* —— Dropdown menu ————————————————————————————————————————————————————————
   <div class="m-menu" data-controller="dropdown">
     <button data-action="dropdown#toggle">…</button>
     <div class="m-menu__list" data-dropdown-target="menu" hidden>…</div></div> */
.m-menu { position: relative; display: inline-block; }
.m-menu__list { position: absolute; top: calc(100% + 6px); left: 0; min-width: 200px; padding: var(--space-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md); z-index: 40; }
.m-menu__list[hidden] { display: none; }
.m-menu__item { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: 9px 11px; font: inherit; font-size: var(--text-base); color: var(--text-default); background: none; border: none; border-radius: var(--radius-sm); text-align: left; cursor: pointer; }
.m-menu__item svg { width: 17px; height: 17px; color: var(--text-muted); }
.m-menu__item:hover { background: var(--row-hover); }
.m-menu__item--danger { color: var(--danger); }
.m-menu__item--danger svg { color: var(--danger); }
.m-menu__sep { height: 1px; margin: var(--space-2) 0; background: var(--border); }

/* —— Modal ————————————————————————————————————————————————————————————————
   <div class="m-modal" data-controller="modal" data-modal-open-value="true"> … */
.m-modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--space-5); }
.m-modal[hidden] { display: none; }
.m-modal__backdrop { position: absolute; inset: 0; background: rgba(15, 22, 18, .5); backdrop-filter: blur(1px); }
.m-modal__dialog { position: relative; width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; }
.m-modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); padding: var(--space-5) var(--space-5) var(--space-3); }
.m-modal__title { font-size: var(--text-lg); font-weight: var(--fw-bold); color: var(--text-strong); }
.m-modal__body { padding: 0 var(--space-5) var(--space-5); color: var(--text-default); }
.m-modal__foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); background: var(--surface-2); }
.m-modal__close { display: grid; place-items: center; width: 32px; height: 32px; border: none; background: none; color: var(--text-muted); border-radius: var(--radius-sm); cursor: pointer; }
.m-modal__close:hover { background: var(--row-hover); color: var(--text-strong); }

/* —— Alert / banner ———————————————————————————————————————————————————————— */
.m-alert { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.m-alert svg { width: 19px; height: 19px; flex-shrink: 0; margin-top: 1px; }
.m-alert__title { font-weight: var(--fw-semibold); color: var(--text-strong); }
.m-alert__body { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }
.m-alert--info    { background: var(--info-soft);    border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.m-alert--info svg { color: var(--info); }
.m-alert--success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.m-alert--success svg { color: var(--success); }
.m-alert--warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.m-alert--warning svg { color: var(--warning); }
.m-alert--danger  { background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.m-alert--danger svg { color: var(--danger); }

/* —— Pagination ———————————————————————————————————————————————————————————— */
.m-pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.m-pager__info { font-size: var(--text-sm); color: var(--text-muted); }
.m-pager__btns { display: flex; gap: var(--space-1); }
.m-page { min-width: 36px; height: 36px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; font: inherit; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.m-page:hover { border-color: var(--text-muted); color: var(--text-default); }
.m-page.is-active { background: var(--brand); color: var(--brand-on); border-color: var(--brand); }
.m-page:disabled { opacity: .45; cursor: not-allowed; }

/* —— Tooltip (CSS-only) ————————————————————————————————————————————————————
   <span class="m-tip" data-tip="Texte">…</span> */
.m-tip { position: relative; }
.m-tip::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%); padding: 6px 9px; font-size: var(--text-xs); font-weight: var(--fw-medium); white-space: nowrap; color: #fff; background: #1c2420; border-radius: var(--radius-sm); opacity: 0; pointer-events: none; transition: opacity .12s ease; }
.m-tip:hover::after { opacity: 1; }

/* —— Theming variants (set on <html>) ————————————————————————————————————————
   data-primary="neutre" → neutral (dark/ink) primary button instead of brand.
   data-density="compact" → tighter controls & table rows. */
[data-primary="neutre"] .m-btn--primary { background: #1f2620; color: #fff; }
[data-theme="dark"][data-primary="neutre"] .m-btn--primary { background: #e9ece6; color: #161a16; }

[data-density="compact"] .m-btn { height: 38px; }
[data-density="compact"] .m-input,
[data-density="compact"] .m-select,
[data-density="compact"] .m-field { height: 38px; }
[data-density="compact"] .m-table th,
[data-density="compact"] .m-table td { padding-top: 10px; padding-bottom: 10px; }
[data-density="compact"] .m-stat { padding: var(--space-3) var(--space-4); }
[data-density="compact"] .m-stat__value { font-size: var(--text-2xl); margin-top: var(--space-2); }
[data-density="compact"] .m-toolbar { padding: var(--space-3); }
