/* ============================================================================
 * components.css — reusable UI pieces (buttons, fields, cards, alerts).
 * Load after tokens.css + base.css. Specs from design.md §10.
 * ========================================================================== */

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px;                 /* touch target (design.md §10) */
  padding: 0 var(--sp-5);
  border: none;                     /* reset the native <button> border (else Save shows it) */
  border-radius: var(--r-md);
  font-size: var(--fs-base); font-weight: 500;
  cursor: pointer;
  transition: filter var(--dur) var(--ease-out), background-color var(--dur) var(--ease-out),
              border-color var(--dur) var(--ease-out);
}
.btn:hover { filter: brightness(0.96); }       /* no size change → no layout shift */
.btn:active { filter: brightness(0.92); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

/* Primary = the one main action. Gold fill + near-black text (passes contrast). */
.btn--primary { background: var(--gold-gradient); color: var(--on-gold); font-weight: 600; }
/* Secondary = supporting action. Filled, borderless (luxury: no hard strokes). */
.btn--secondary { background: var(--surface-2); color: var(--text); }
.btn--secondary:hover { background: var(--surface-3); filter: none; }
/* Ghost = tertiary/toolbar. */
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-2); filter: none; }
/* Destructive = delete/cancel. */
.btn--danger { background: var(--danger); color: #fff; }
/* Soft destructive = a secondary-position delete: red text/icon, no heavy fill.
   Used for Supprimer (bien detail), Annuler (booking), Suppr. (pricing). */
.btn--danger-soft { background: transparent; color: var(--danger); }
.btn--danger-soft:hover { background: var(--danger-bg); filter: none; }

.btn--block { width: 100%; }       /* full width (used on the login form) */

/* Icons inside buttons/chips/checks must never be squeezed by flex. */
.btn svg, .chip svg, .check svg { flex-shrink: 0; }

/* Tiny spinner shown while a button is loading (set aria-busy + add .is-loading). */
.btn.is-loading { pointer-events: none; }
.btn.is-loading::before {
  content: ""; width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Form fields --------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.label .req { color: var(--danger); }                 /* the * on required fields */

/* Filled, borderless fields (same luxury language as the filter chips).
   No 1px stroke → no bulky/black border. Focus ring comes from base.css. */
.input {
  width: 100%; min-width: 0;        /* min-width:0 prevents flex overflow bugs */
  min-height: 44px; padding: 0 var(--sp-4);
  background: var(--surface-2);
  border: none;
  border-radius: var(--r-md);
  color: var(--text);
  transition: background-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.input::placeholder { color: var(--text-muted); }
/* Use background-COLOR (not the shorthand) so a <select>'s chevron image survives. */
.input:hover { background-color: var(--surface-3); }
.input:focus-visible { background-color: var(--surface); }   /* field lifts to white when active */

/* Native <select>: remove the browser's chrome (the "black border" + arrow)
   and draw our own muted chevron. */
select.input {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  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='%238C8276' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* Multi-line fields need real vertical padding. */
textarea.input { min-height: 88px; padding: 10px var(--sp-4); line-height: 1.5; resize: vertical; }

/* Helper text under a field, and the error variant. */
.field__help { font-size: var(--fs-sm); color: var(--text-muted); }
.field__error { font-size: var(--fs-sm); color: var(--danger); }
/* Danger indicator as an inset ring → no 1px border, no layout shift. */
.field--invalid .input { box-shadow: inset 0 0 0 1.5px var(--danger); }

/* --- Card ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
}

/* --- Alert (inline messages: error / success / info) --------------------- */
.alert {
  display: flex; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
}
.alert--error   { background: var(--danger-bg);  color: var(--danger); }
.alert--success { background: var(--success-bg); color: var(--success); }
.alert--info    { background: var(--info-bg);    color: var(--info); }
.alert[hidden]  { display: none; }      /* toggle visibility from JS with .hidden = true/false */

/* --- Status chips (color + label; never color alone) --------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px var(--sp-3); border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 500; line-height: 1.6;
  background: var(--surface-2); color: var(--text-2);
}
.chip--success { background: var(--success-bg); color: var(--success); }
.chip--warning { background: var(--warning-bg); color: var(--warning); }
.chip--danger  { background: var(--danger-bg);  color: var(--danger); }
.chip--info    { background: var(--info-bg);    color: var(--info); }
.chip--muted   { background: var(--surface-2);  color: var(--text-muted); }

/* --- Toasts -------------------------------------------------------------- */
.toast-wrap {
  position: fixed; top: var(--sp-4); right: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: var(--z-toast); pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 220px; max-width: 360px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--text); color: #fff; font-size: var(--fs-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(-8px);
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.toast.is-in { opacity: 1; transform: none; }
.toast--success { background: var(--success); }
.toast--error   { background: var(--danger); }
.toast--info    { background: var(--text); }

/* --- Snackbar (undo-able action) -------------------------------------------
 * Bottom-centered charcoal bar: message + gold action, with a thin gold line
 * draining along the bottom to show the remaining time. */
.snackbar {
  position: fixed; left: 50%; bottom: var(--sp-6);
  transform: translate(-50%, 12px);
  display: flex; align-items: center; gap: var(--sp-3);
  min-width: 280px; max-width: min(92vw, 480px);
  padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-5);
  background: var(--brand-dark); color: var(--on-dark);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  z-index: var(--z-toast); overflow: hidden;
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.snackbar.is-in { opacity: 1; transform: translate(-50%, 0); }
.snackbar__msg { flex: 1; font-size: var(--fs-sm); }
.snackbar__btn {
  border: none; background: transparent; cursor: pointer;
  color: var(--gold-300); font-weight: 600; font-size: var(--fs-sm); letter-spacing: .02em;
  padding: 8px 12px; border-radius: var(--r-sm); white-space: nowrap;
  transition: background-color var(--dur) var(--ease-out);
}
.snackbar__btn:hover { background: rgba(255, 255, 255, .09); }
.snackbar::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: 100%;
  background: var(--gold-500); transform-origin: left;
  animation: snack-drain var(--snack-dur, 6000ms) linear forwards;
}
@keyframes snack-drain { to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .snackbar::after { animation: none; } }

/* --- Modal (confirm dialog) ---------------------------------------------- */
.modal-root { position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--sp-4); }
.modal__scrim { position: absolute; inset: 0; background: rgba(20,17,11,.5); }
.modal {
  position: relative; width: 100%; max-width: 420px;
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: var(--sp-6);
  animation: modal-in var(--dur) var(--ease-out);
}
@keyframes modal-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
.modal__title { font-size: var(--fs-lg); margin-bottom: var(--sp-3); }
.modal__body  { color: var(--text-2); margin-bottom: var(--sp-6); }
.modal__actions { display: flex; justify-content: flex-end; gap: var(--sp-3); }

/* --- Skeleton (loading shimmer) ------------------------------------------ */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, #ECE7DB 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.4s ease infinite;
}
.skeleton--row { height: 44px; margin-bottom: var(--sp-2); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* --- Entrance: content rises as it paints ----------------------------------
 * Pairs with the SWR instant paint — cached data doesn't just appear, it
 * glides in (transform/opacity only → zero layout shift, ≤.35s).
 * Layer 1: the page chrome (direct children of .content), lightly staggered.
 * Layer 2: async list/state containers, which land after the chrome; they
 *          re-rise on each render, so motion also reads as "content updated".
 * The dashboard keeps its own orchestrated sequence (dashboard.css) → :not(.dash). */
@media (prefers-reduced-motion: no-preference) {
  .content > *:not(.dash) { animation: rise .35s var(--ease-out) backwards; }
  .content > *:nth-child(2) { animation-delay: .05s; }
  .content > *:nth-child(3) { animation-delay: .1s; }
  .content > *:nth-child(n+4) { animation-delay: .15s; }
  .content .booking-list, .content .loc-group, .content .bon-list, .content .state {
    animation: rise .35s var(--ease-out) backwards;
  }
  /* Image-bearing containers FADE only (no transform). A transform animation
     rasterizes the container into a temporary GPU layer; photos that finish
     decoding mid-animation are re-rasterized when that layer is dropped at
     animation end — on fractional grid widths the re-snap reads as a subtle
     horizontal "stretch" of the image. Opacity alone never re-rasters.
     (.detail included: the bien page's gallery hero lives inside it.) */
  .content .table-wrap, .content .grid-biens, .content > .detail {
    animation: fade .35s var(--ease-out) backwards;
  }
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fade { from { opacity: 0; } }

/* --- Filter chip + dropdown menu (filled, borderless controls) ------------ */
.fdrop { position: relative; display: inline-flex; }
.fchip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  height: 44px; padding: 0 var(--sp-3); min-width: 0;
  background: var(--surface-2); border: none; border-radius: var(--r-md);
  color: var(--text); font-size: var(--fs-sm); font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background-color var(--dur) var(--ease-out);
}
.fchip:hover,
.fchip[aria-expanded="true"] { background: var(--surface-3); }
.fchip__ic { display: inline-flex; flex-shrink: 0; }
.fchip__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fchip__chev { display: inline-flex; color: var(--text-muted); margin-left: 2px; flex-shrink: 0; }

.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: var(--z-dropdown);
  min-width: 200px; max-width: 280px; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-md);
  animation: menu-in var(--dur) var(--ease-out);
}
.menu--right { left: auto; right: 0; }
/* Opens upward (set by JS when there's no room below the trigger). */
.menu--up { top: auto; bottom: calc(100% + 6px); }
.menu[hidden] { display: none; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .menu { animation: none; } }
.menu__item {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 40px; padding: 8px 10px; border-radius: var(--r-sm);
  cursor: pointer; color: var(--text); font-size: var(--fs-sm);
}
/* :focus (not :focus-visible) so arrow-key navigation highlights the option. */
.menu__item:hover, .menu__item:focus { background: var(--surface-2); outline: none; }
.menu__item[aria-selected="true"] { font-weight: 600; }
.menu__icon { display: inline-flex; flex-shrink: 0; }
.menu__label { flex: 1; }
.menu__check { display: inline-flex; color: var(--gold-ink); }

/* --- Themed <select> (see enhanceSelects in ui.js) ------------------------ */
.selectbox { position: relative; }
.selectbox__native { display: none; }         /* real <select> kept as source of truth */
.selectbox__trigger {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  width: 100%; text-align: left; cursor: pointer;
}
.selectbox__value { display: inline-flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.selectbox__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Coloured status circle in an option / the trigger (data-tone on the <option>). */
.opt-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.selectbox__value svg, .menu__item svg { flex-shrink: 0; }
.selectbox__label.is-placeholder { color: var(--text-muted); }
.selectbox__chev { display: inline-flex; color: var(--text-muted); flex-shrink: 0; }
/* The listbox spans the field and scrolls for long lists (e.g. the time picker).
   z-index sits above the sticky form action bar so it's never clipped by it. */
.selectbox__menu { width: 100%; min-width: 0; max-width: none; max-height: 280px; overflow-y: auto; z-index: var(--z-header); }

/* --- Date-range picker (shared: booking form + biens availability search) - */
.drp { position: relative; display: inline-block; }
.drp__trigger { justify-content: flex-start; gap: var(--sp-2); }   /* width set per context */
.drp__ic { display: inline-flex; color: var(--text-muted); }
.drp__val { color: var(--text-muted); }
.drp__val.is-set { color: var(--text); font-weight: 500; }
.drp__sep { color: var(--text-muted); }
.field--invalid .drp__trigger { box-shadow: inset 0 0 0 1.5px var(--danger); }

/* z-index above the sticky form action bars (z-sticky) so the calendar is
   never painted under them. */
.drp__pop { width: 300px; max-width: calc(100vw - 32px); padding: var(--sp-4); z-index: var(--z-header); }
.drp__bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-2); }
.drp__month { font-weight: 600; font-size: var(--fs-sm); text-transform: capitalize; }
.drp__wd { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.drp__wd span { text-align: center; font-size: 10px; text-transform: uppercase; color: var(--text-muted); }
.drp__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.drp__pad { min-height: 38px; }
.drp__day {
  min-height: 38px; border: none; border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text); font-size: var(--fs-sm); cursor: pointer;
  transition: background-color var(--dur) var(--ease-out);
}
.drp__day:hover:not(:disabled) { background: var(--surface-3); }
.drp__day.is-inrange { background: rgba(192, 160, 86, .16); }
.drp__day.is-arrival, .drp__day.is-departure { background: var(--gold-500); color: var(--on-gold); font-weight: 600; }
.drp__day.is-reserved { background: var(--danger-bg); color: var(--danger); cursor: not-allowed; text-decoration: line-through; }
.drp__legend { display: flex; align-items: center; gap: 6px; margin-top: var(--sp-3); font-size: var(--fs-xs); color: var(--text-muted); }
.drp__swatch { width: 12px; height: 12px; border-radius: 3px; }
.drp__swatch--res { background: var(--danger-bg); box-shadow: inset 0 0 0 1px var(--danger); }
