/* ==========================================================================
   common.css — shared styles for every Backoffice page
   Load order: normalize.css → grid3.css → common.css → [page].css

   CONTENTS
     1. Fonts and icons (Inter + Font Awesome 6 Free)
     2. Variables (palette, typography, sizes, layout)
     3. Base
     4. App layout (with / without sidebar)
     5. Header
     6. Sidebar
     7. Layout responsive (header + sidebar)
     8. Page header (title + actions) and card
     9. Buttons
    10. Forms
    11. Filter
    12. Cell elements and badges
    13. Table (→ cards on tablet and mobile)
    14. Pagination
    15. Modal
    16. Toast
    (each component from 8 on has its own media queries at the end of its section)

   BREAKPOINTS (same as grid3)
     Mobile     < 768
     Tablet     768–991
     PC narrow  992–1199   → sidebar shows icons only
     PC         ≥ 1200     → full sidebar
   The sidebar is ALWAYS stuck to the left edge. On wide screens
   (≥ ~1450px) the content stops growing at --content-max and is
   centred in the space left by the sidebar, with empty sides.
   (CSS variables can't be used inside @media, so the numbers are written by hand.)

   WARNING: grid3 adds padding to anything whose class contains "col"
   ([class*="col"]). Don't use names like "collapse", "color" or "column".
   ========================================================================== */


/* ==========================================================================
   1. Fonts and icons
   Inter from Google Fonts for now (later, local @font-face).
   ========================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");
@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css");


/* ==========================================================================
   2. Variables
   ========================================================================== */
:root {
  /* ---------- BO palette ---------- */
  --nordic-charcoal: #1F2933;
  --fjord-gray:      #6B7280;
  --cloud-gray:      #D1D5DB;
  --snow-cream:      #F7F7F2;
  --warm-wood:       #A68A64;
  --wine:            #8B2635; /* outside the original palette: errors and dangerous actions (8:1 on Snow Cream) */

  /* ---------- Roles (what the styles actually use) ---------- */
  --Primary_Dark:  var(--nordic-charcoal); /* text, table header, dark buttons, sidebar */
  --Primary_Light: var(--snow-cream);      /* page background, cards, text on dark */
  --Accent_Dark:   var(--fjord-gray);      /* focus and secondary details */
  --Accent_Light:  var(--cloud-gray);      /* borders and separators */
  --Secundary:     var(--warm-wood);       /* accent: badges, tints, active sidebar item */
  --Danger:        var(--wine);
  --Danger_Hover:  #6E1E2A;

  --Text:          var(--Primary_Dark);

  /* ---------- Derived tints ---------- */
  --Fila_Alterna:      #D1D5DB59; /* Cloud Gray 35% → even rows */
  --Secundary_Alpha03: #A68A644d; /* Warm Wood 30% → row hover */
  --Accent_Alpha10:    #1F29331a; /* Nordic Charcoal 10% → action button hover */
  --Accent_Hover:      #11171D;   /* darker Nordic Charcoal → dark button hover */
  --Light_Alpha08:     #F7F7F214; /* Snow Cream 8% → hover on dark background (sidebar) */
  --Backdrop:          #1F293380; /* Nordic Charcoal 50% → behind modals and the mobile sidebar */

  /* ---------- Typography ---------- */
  --fontInter: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-base:  16px;
  --text-table: 16px;
  --text-sm:    14px;  /* codes, labels, pagination */
  --text-xs:    12px;  /* badges, sidebar section titles */
  --text-h1:    30px;

  /* ---------- Sizes ---------- */
  --radius:         8px;
  --radius-lg:      12px;
  --control-height: 44px; /* buttons and fields: comfortable for a finger */
  --label-height:   27px; /* label above a field (21px line + 6px gap) */

  /* ---------- Layout ---------- */
  --content-max:      1140px; /* max width of the content (same as grid3 .container); more space = empty sides */
  --sidebar-width:    260px;
  --sidebar-icons:    72px;   /* sidebar with icons only (992–1199) */
  --sidebar-drawer:   280px;  /* sidebar as a side panel (< 992) */
  --header-height:    64px;
  --page-padding:     24px;   /* side padding of the content */
  --transition:       .25s ease;

  /* ---------- Logo (relative to this file) ---------- */
  --logo_Blanc: url("../img/mera-blanc-fonsOscur.svg"); /* on dark background */
  --logo_Oscur: url("../img/mera-oscur-fonsBlanc.svg"); /* on light background */
}


/* ==========================================================================
   3. Base
   ========================================================================== */
body {
  font-family: var(--fontInter);
  font-size: var(--text-base);
  line-height: 1.45;
  color: var(--Text);
  background: var(--Primary_Light);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

img,
svg {
  max-width: 100%;
}

/* Hidden on screen, still read by screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* "Skip to content" link: only visible when it receives keyboard focus */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 300;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--Primary_Dark);
  color: var(--Primary_Light);
  font-weight: 500;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

/* Common keyboard focus */
:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--Accent_Dark);
  outline-offset: 2px;
}


/* ==========================================================================
   4. App layout
   <body class="app">                       ← with sidebar
   <body class="app app--no-sidebar">       ← header only

     <aside class="sidebar">…</aside>        (only with sidebar)
     <div class="app-main">
       <header class="header">…</header>
       <main class="container-fluid page">…</main>
     </div>
   ========================================================================== */

/* z-index levels (keep it simple: nothing above 300) */
/* 100 header · 200 sidebar/backdrop · 250 modals · 300 skip link */

.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-main {
  flex: 1 1 auto;
  min-width: 0; /* KEY: lets tables scroll inside instead of widening the page */
  display: flex;
  flex-direction: column;
}

/* grid3's container-fluid (fluid, no fixed widths = no side scroll)
   with more breathing room and a max width, centred */
.app-main > .container-fluid {
  max-width: calc(var(--content-max) + 2 * var(--page-padding));
  padding-left: var(--page-padding);
  padding-right: var(--page-padding);
}

.page {
  flex: 1 0 auto;
  padding-top: 32px;
  padding-bottom: 48px;
}

/* the page stops scrolling while the mobile sidebar is open */
body.is-locked {
  overflow: hidden;
}


/* ==========================================================================
   5. Header (all pages)
   ========================================================================== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: var(--header-height);
  /* the header background fills the whole width, but its content
     lines up with the edges of the page content (--content-max) */
  padding: 8px max(var(--page-padding), calc((100% - var(--content-max)) / 2));
  background: var(--Primary_Light);
  border-bottom: 1px solid var(--Accent_Light);
}

.header__start {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}

.header__end {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

/* ☰ button: only < 992 and only on pages with a sidebar */
.header__menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  flex: none;
  padding: 0;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius);
  background: transparent;
  color: var(--Text);
  font-size: 18px;
  cursor: pointer;
}

/* Logo in the header: always without sidebar, and < 992 with sidebar */
.header__logo {
  display: none;
  flex: none;
}

.header__logo img {
  display: block;
  height: 32px;
  width: auto;
}

.app--no-sidebar .header__logo {
  display: block;
}

/* Breadcrumb */
.breadcrumb {
  min-width: 0;
}

.breadcrumb ol {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
  color: var(--Accent_Dark);
}

.breadcrumb li {
  display: flex;
  align-items: center;
  min-width: 0;
}

.breadcrumb li + li::before {
  content: "/";
  margin: 0 8px;
  color: var(--Accent_Light);
}

.breadcrumb a {
  color: var(--Accent_Dark);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--Text);
  text-decoration: underline;
}

.breadcrumb [aria-current="page"] {
  color: var(--Text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* User */
.header__user {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Usuari de la capçalera: enllaç a l'àrea personal */
a.header__user {
  padding: 4px 8px;
  border-radius: var(--radius);
  color: var(--Text);
  text-decoration: none;
}

@media (hover: hover) {
  a.header__user:hover {
    background: var(--Accent_Alpha10);
  }
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 2px solid var(--Secundary);
  border-radius: 50%;
  background: var(--Primary_Dark);
  color: var(--Primary_Light);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .03em;
}

.header__user-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.header__user-name {
  font-size: var(--text-sm);
  font-weight: 600;
}

.header__user-role {
  font-size: var(--text-xs);
  color: var(--Accent_Dark);
}

/* Log out */
.header__logout {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--control-height);
  padding: 0 14px;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius);
  color: var(--Text);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
}

@media (hover: hover) {
  .header__menu-btn:hover,
  .header__logout:hover {
    background: var(--Accent_Alpha10);
  }
}


/* ==========================================================================
   6. Sidebar
   ========================================================================== */
.sidebar {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--Primary_Dark);
  color: var(--Primary_Light);
}

.sidebar__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 24px 20px 20px;
}

.sidebar__brand {
  display: block;
  color: inherit;
  text-decoration: none;
}

.sidebar__logo {
  display: block;
  height: 40px;
  width: auto;
}

.sidebar__subtitle {
  display: block;
  margin-top: 6px;
  font-size: var(--text-xs);
  color: var(--Accent_Light);
}

/* × button: only when it is a side panel (< 992) */
.sidebar__close {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  flex: none;
  margin: -8px -8px 0 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--Primary_Light);
  font-size: 20px;
  cursor: pointer;
}

.sidebar__nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 12px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--Accent_Dark) transparent;
}

.sidebar__group + .sidebar__group {
  margin-top: 20px;
}

.sidebar__title {
  margin: 0 0 6px;
  padding: 0 12px;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--Secundary);
}

.sidebar__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--Primary_Light);
  font-size: 15px;
  text-decoration: none;
}

.sidebar__link i {
  width: 20px;
  flex: none;
  text-align: center;
  font-size: 16px;
}

.sidebar__link[aria-current="page"] {
  background: var(--Secundary);
  color: var(--Primary_Dark);
  font-weight: 600;
}

.sidebar__link:focus-visible,
.sidebar__close:focus-visible {
  outline: 2px solid var(--Secundary);
  outline-offset: 2px;
}

@media (hover: hover) {
  .sidebar__link:not([aria-current="page"]):hover {
    background: var(--Light_Alpha08);
  }

  .sidebar__close:hover {
    background: var(--Light_Alpha08);
  }
}

/* Tooltip for the icons-only sidebar (JS positions it with --tip-top) */
.sidebar__tip {
  position: fixed;
  top: var(--tip-top, 0);
  left: calc(var(--sidebar-icons) + 8px);
  z-index: 210;
  transform: translateY(-50%);
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--Primary_Dark);
  color: var(--Primary_Light);
  font-size: var(--text-sm);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 12px var(--Backdrop);
}

.sidebar__tip[hidden] {
  display: none;
}

/* Dark background behind the sidebar side panel */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 190;
  background: var(--Backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}


/* ==========================================================================
   7. Layout responsive (header + sidebar)
   ========================================================================== */

/* ---------- PC narrow (992–1199): sidebar with icons only ---------- */
@media only screen and (min-width: 992px) and (max-width: 1199px) {
  .sidebar {
    width: var(--sidebar-icons);
    flex-basis: var(--sidebar-icons);
  }

  .sidebar__top {
    justify-content: center;
    padding: 20px 8px 16px;
  }

  .sidebar__logo {
    height: auto;
    width: 52px;
  }

  .sidebar__subtitle {
    display: none;
  }

  .sidebar__nav {
    padding: 0 10px 20px;
    scrollbar-width: none;
  }

  /* the section title becomes a separator line (still readable by screen readers) */
  .sidebar__title {
    height: 1px;
    margin: 0 6px 8px;
    padding: 0;
    overflow: hidden;
    color: transparent;
    background: var(--Accent_Dark);
  }

  .sidebar__group + .sidebar__group {
    margin-top: 12px;
  }

  .sidebar__link {
    justify-content: center;
    padding: 8px 0;
  }

  /* the text stays for screen readers; the tooltip shows it on screen */
  .sidebar__link span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* ---------- Tablet and mobile (< 992): sidebar as a side panel ---------- */
@media only screen and (max-width: 991px) {
  .header__menu-btn {
    display: inline-flex;
  }

  .header__logo {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(var(--sidebar-drawer), 85vw);
    transform: translateX(-100%);
    visibility: hidden; /* closed: links can't be focused with Tab */
    transition: transform var(--transition), visibility var(--transition);
  }

  .sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
    box-shadow: 8px 0 24px var(--Backdrop);
  }

  .sidebar.is-open + .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
  }

  .sidebar__close {
    display: inline-flex;
  }

  .sidebar__tip {
    display: none;
  }
}

/* ---------- Mobile (< 768) ---------- */
@media only screen and (max-width: 767px) {
  :root {
    --text-h1: 26px;
    --page-padding: 16px;
    --header-height: 56px;
  }

  .page {
    padding-top: 20px;
    padding-bottom: 32px;
  }

  .header {
    gap: 8px;
  }

  .header__logo img {
    height: 26px;
  }

  /* breadcrumb: only the current page */
  .breadcrumb li:not(:last-child) {
    display: none;
  }

  .breadcrumb li + li::before {
    display: none;
  }

  /* user: only the avatar; logout: only the icon (text still accessible) */
  .header__user-text {
    display: none;
  }

  .header__logout {
    width: var(--control-height);
    padding: 0;
    justify-content: center;
  }

  .header__logout-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* ---------- Very narrow mobile (< 360) ---------- */
@media only screen and (max-width: 359px) {
  .header__logo {
    display: none;
  }
}

/* ---------- Fewer animations if the user asks for it ---------- */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-backdrop {
    transition: none;
  }
}


/* ==========================================================================
   8. Page header (title + actions)
   <div class="page-header">
     <div class="page-header__text"><h1>…</h1><p>…</p></div>
     <div class="page-actions"><button class="btn">…</button></div>
   </div>
   ========================================================================== */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px 24px;
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0 0 4px;
  font-size: var(--text-h1);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.page-header p {
  margin: 0;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media only screen and (max-width: 767px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 20px;
  }

  .page-actions .btn {
    flex: 1 1 0;
    padding: 0 12px;
  }
}

@media only screen and (max-width: 359px) {
  .page-actions {
    flex-direction: column;
  }
}


/* Generic box with border (forms, summaries…) */
.card {
  padding: 24px;
  background: var(--Primary_Light);
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius-lg);
}

.card__title {
  margin: 0 0 16px;
  font-size: 18px;
}

.card__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

@media only screen and (max-width: 767px) {
  .card {
    padding: 16px;
  }

  .card__footer .btn {
    flex: 1 1 0;
  }
}


/* ==========================================================================
   9. Buttons
   .btn             light button with border
   .btn--dark       main action (Nordic Charcoal)
   .btn--danger     dangerous action (wine)
   .btn--block      full width
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-height);
  margin: 0;
  padding: 0 18px;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius);
  background: var(--Primary_Light);
  color: var(--Text);
  font: inherit;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .2s, color .2s, border-color .2s;
}

.btn--dark {
  background: var(--Primary_Dark);
  border-color: var(--Primary_Dark);
  color: var(--Primary_Light);
}

.btn--danger {
  background: var(--Danger);
  border-color: var(--Danger);
  color: var(--Primary_Light);
}

.btn--block {
  display: flex;
  width: 100%;
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

@media (hover: hover) {
  .btn:not(:disabled):hover {
    background: var(--Accent_Alpha10);
  }

  .btn--dark:not(:disabled):hover {
    background: var(--Primary_Light);
    border-color: var(--Primary_Dark);
    color: var(--Text);
  }

  .btn--danger:not(:disabled):hover {
    background: var(--Danger_Hover);
    border-color: var(--Danger_Hover);
  }
}


/* ==========================================================================
   10. Forms
   <div class="form-grid">
     <div class="form-field [form-field--half]">
       <label class="form-label" for="x">Name</label>
       <input class="form-control" id="x">
     </div>
   </div>
   Add .was-validated to the <form> after the first submit to show errors.
   ========================================================================== */
.form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.form-field {
  flex: 1 1 100%;
  min-width: 0;
}

.form-field--half {
  flex-basis: calc(50% - 8px);
}

.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 21px;
}

.form-label .required {
  color: var(--Danger);
}

.form-control {
  display: block;
  width: 100%;
  height: var(--control-height);
  padding: 0 12px;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius);
  background: var(--Primary_Light);
  color: var(--Text);
  font: inherit;
  font-size: 16px; /* >= 16px: the iPhone doesn't zoom when you tap the field */
}

textarea.form-control {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
}

.form-control:focus-visible {
  outline: 2px solid var(--Accent_Dark);
  outline-offset: 1px;
}

.form-control[readonly] {
  background: var(--Fila_Alterna);
}

.was-validated .form-control:invalid {
  border-color: var(--Danger);
}

.form-hint {
  margin: 4px 0 0;
  font-size: var(--text-xs);
  color: var(--Accent_Dark);
}

/* error messages (empty = takes no space) */
.form-error {
  margin: 12px 0 0;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--Danger);
}

.form-error:empty {
  display: none;
}

@media only screen and (max-width: 767px) {
  .form-field--half {
    flex-basis: 100%;
  }
}


/* ==========================================================================
   11. Filter (always above the table)
   Use with js/filter.js → initFilter("filterForm", applyFilter)

   <section class="filter" aria-labelledby="filterTitle">
     <div class="filter__head">
       <h2 class="filter__title" id="filterTitle">Filtrar …</h2>
       <button class="filter__toggle" type="button" aria-expanded="false" aria-controls="filterExtra">Más filtros</button>
     </div>
     <form id="filterForm" class="filter__form" novalidate>
       <div class="filter__fields">
         <div class="filter-field"> <label class="form-label">…</label> <input class="form-control" name="…"> </div>
         <div class="filter-field filter-field--secondary">…</div>   ← hidden on mobile until "Más filtros"
         <div class="filter__extra" id="filterExtra" hidden> …more .filter-field… </div>
       </div>
       <div class="filter__actions">
         <button class="btn btn--dark" type="submit">Buscar</button>
         <button class="btn" type="reset">Limpiar</button>
       </div>
       <p class="form-error filter__error" role="alert"></p>
     </form>
   </section>
   <p id="filterResult" class="filter-result" aria-live="polite"></p>

   - 1–2 fields: delete .filter-field--secondary, .filter__extra and the toggle.
   - 3 fields, no extra row: give the toggle the class .filter__toggle--mobile
     (it only appears on mobile, to show the 3rd field).
   ========================================================================== */
.filter {
  margin-bottom: 16px;
  padding: 16px 20px;
  background: var(--Primary_Light);
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius-lg);
}

.filter__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.filter__title {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 600;
}

.filter__toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px dashed var(--Secundary);
  border-radius: var(--radius);
  background: none;
  color: var(--Text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
}

.filter__toggle::after {
  content: "\25BE"; /* ▾ */
}

.filter__toggle[aria-expanded="true"]::after {
  content: "\25B4"; /* ▴ */
}

.filter__toggle--mobile {
  display: none;
}

.filter__form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 16px;
}

/* fields: max 3 per line, they wrap by themselves */
.filter__fields {
  flex: 1 1 520px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  min-width: 0;
}

.filter-field {
  flex: 1 1 calc(33.333% - 11px);
  min-width: 160px;
}

.filter__extra {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  flex: 1 1 100%;
}

/* extra fields keep the same width as the ones above (they don't stretch) */
.filter__extra .filter-field {
  flex-grow: 0;
}

.filter__extra[hidden] {
  display: none;
}

/* Buscar / Limpiar: same height as the fields and aligned with them */
.filter__actions {
  flex: 0 1 260px;
  display: flex;
  gap: 8px;
  padding-top: var(--label-height);
}

.filter__actions .btn {
  flex: 1;
}

.filter__error {
  flex: 1 1 100%;
  margin: 0;
}

.filter-result {
  margin: 0 0 8px;
  font-size: var(--text-sm);
  color: var(--Accent_Dark);
}

@media (hover: hover) {
  .filter__toggle:hover {
    background: var(--Secundary_Alpha03);
  }
}

/* tablet: buttons under the fields, full width */
@media only screen and (max-width: 991px) {
  .filter__fields,
  .filter__actions {
    flex-basis: 100%;
  }

  .filter__actions {
    padding-top: 0;
  }
}

@media only screen and (max-width: 767px) {
  .filter {
    padding: 12px 16px 16px;
  }

  .filter-field,
  .filter__extra .filter-field {
    flex-basis: 100%;
    flex-grow: 1;
  }

  /* on mobile only the main fields are shown; the rest with "Más filtros" */
  .filter__form:not(.is-open) .filter-field--secondary {
    display: none;
  }

  .filter__toggle--mobile {
    display: inline-flex;
  }
}


/* ==========================================================================
   12. Cell elements and badges
   ========================================================================== */
/* Thumbnail: <div class="thumb"><img …></div> or with an icon if there is no photo */
.thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  overflow: hidden;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius);
  background: var(--Primary_Light);
  color: var(--Accent_Dark);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Colour swatch: <span class="swatch" style="--c:#hex"></span> */
.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  border: 1px solid var(--Accent_Light);
  border-radius: 3px;
  background: var(--c);
  vertical-align: -2px;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}

.badge--active {
  background: var(--Primary_Dark);
  color: var(--Primary_Light);
}

.badge--low {
  background: var(--Accent_Light);
  color: var(--Text);
}

.badge--out {
  background: var(--Secundary);
  color: var(--Text);
}

.badge--draft {
  border: 1px solid var(--Accent_Light);
  color: var(--Text);
}

/* Action buttons (icon on PC; icon + text on tablet and mobile)
   <button class="action-btn action-btn--edit" aria-label="Editar">
     <i class="fa-solid fa-pen" aria-hidden="true"></i><span class="action-btn__text">Editar</span>
   </button> */
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--Text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  vertical-align: middle;
}

.action-btn i {
  font-size: 16px;
}

.action-btn__text {
  display: none;
}

@media (hover: hover) {
  .action-btn:hover {
    background: var(--Accent_Alpha10);
  }

  .action-btn--delete:hover {
    color: var(--Danger);
    background: var(--Secundary_Alpha03);
  }
}


/* ==========================================================================
   13. Table (PC) → cards (tablet and mobile)
   Any <table class="data-table"> inside .table-card becomes cards < 992.
   Cell classes (all optional):
     .cell-image      thumbnail (with .thumb inside)
     .cell-main       name + code (<strong> + <small>), card title
     .cell-status     status badge
     .cell-highlight  big value on the right (price, amount, total…)
     .cell-actions    .action-btn buttons
     .optional        optional column: hidden on PC while the content is narrower
                      than --content-max (992–1449, the sidebar takes space)
     .num             number aligned to the right (on PC)
   Cells with data-label="…" are shown in 2 columns with the label above.
   ========================================================================== */
.table-card {
  background: var(--Primary_Light);
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* many columns → horizontal scroll INSIDE the table, never on the page */
.table-scroll {
  overflow-x: auto;
}

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

.data-table th {
  padding: 14px 8px;
  background: var(--Primary_Dark);
  color: var(--Primary_Light);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.data-table td {
  padding: 12px 8px;
  vertical-align: middle;
}

.data-table th:first-child,
.data-table td:first-child {
  padding-left: 16px;
}

.data-table th:last-child,
.data-table td:last-child {
  padding-right: 16px;
}

.data-table tbody tr:nth-child(odd) {
  background: var(--Primary_Light);
}

.data-table tbody tr:nth-child(even) {
  background: var(--Fila_Alterna);
}

.data-table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.data-table td:has(> .swatch) {
  white-space: nowrap; /* the swatch doesn't split from its name */
}

.cell-main {
  min-width: 150px; /* the name wraps in 2–3 lines at most, not in 4 */
}

.cell-main strong {
  display: block;
  font-weight: 600;
}

.cell-main small {
  font-size: var(--text-sm);
  color: var(--Text);
  white-space: nowrap;
}

.data-table .cell-highlight {
  font-weight: 600;
}

.cell-actions {
  white-space: nowrap;
  text-align: right;
}

/* "no results" row */
.data-table .table-empty td {
  padding: 32px 16px;
  text-align: center;
  color: var(--Accent_Dark);
}

@media (hover: hover) {
  .data-table tbody tr:not(.table-empty):hover {
    background: var(--Secundary_Alpha03);
  }
}

/* narrow table (sidebar takes space): hide optional columns */
@media only screen and (min-width: 992px) and (max-width: 1449px) {
  .data-table .optional {
    display: none;
  }
}

/* ---------- TABLET AND MOBILE (< 992): every <tr> is drawn as a card ---------- */
@media only screen and (max-width: 991px) {
  .table-card {
    background: none;
    border: 0;
    border-radius: 0;
    overflow: visible;
  }

  /* header hidden on screen; screen readers still read it */
  .data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .data-table {
    display: block;
  }

  .data-table tbody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)); /* 2 cards per row */
    gap: 16px;
  }

  .data-table tbody tr,
  .data-table tbody tr:nth-child(odd),
  .data-table tbody tr:nth-child(even) {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    row-gap: 14px;
    padding: 0 8px 16px;
    overflow: hidden; /* the grey band follows the rounded corners */
    background: var(--Primary_Light);
    border: 1px solid var(--Accent_Light);
    border-radius: var(--radius-lg);
  }

  .data-table td,
  .data-table td:first-child,
  .data-table td:last-child {
    padding: 0 8px;
    text-align: left;
    min-width: 0;
  }

  /* data in 2 columns, with the label above */
  .data-table td[data-label] {
    order: 5;
    width: 50%;
    overflow-wrap: anywhere;
  }

  .data-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--Accent_Dark);
  }

  .data-table td.optional {
    display: block;
  }

  .data-table td.num {
    text-align: left;
  }

  /* order: image + main · status + highlight · data · actions
     the first two lines share the grey band */
  .data-table td.cell-image,
  .data-table td.cell-main,
  .data-table td.cell-status,
  .data-table td.cell-highlight {
    align-self: stretch;
    background: var(--Fila_Alterna);
  }

  .data-table td.cell-image {
    order: 1;
    flex: none;
    display: flex;
    align-items: center;
    margin-left: -8px;
    padding: 12px 8px 12px 16px;
  }

  .data-table td.cell-main {
    order: 2;
    flex: 1 1 calc(100% - 64px); /* takes the rest of the line: status and highlight go down */
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-right: -8px;
    padding: 12px 16px 12px 8px;
    overflow-wrap: anywhere;
  }

  .cell-main strong {
    font-size: 17px;
    line-height: 1.3;
  }

  .data-table td.cell-status,
  .data-table td.cell-highlight {
    margin-top: -14px; /* covers the row-gap with the title line */
    padding-top: 0;
    padding-bottom: 12px;
  }

  .data-table td.cell-status {
    order: 3;
    flex: 1 1 40%;
    display: flex;
    align-items: center;
    margin-left: -8px;
    padding-left: 16px;
  }

  .data-table td.cell-highlight {
    order: 4;
    flex: 1 1 40%;
    margin-right: -8px;
    padding-right: 16px;
    text-align: right;
    font-size: 19px;
  }

  .data-table td.cell-highlight::before {
    display: none;
  }

  .data-table td.cell-actions {
    order: 6;
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .thumb {
    width: 48px;
    height: 48px;
  }

  .action-btn {
    flex: 1;
    width: auto;
    height: var(--control-height);
    padding: 0 10px;
    border: 1px solid var(--Accent_Light);
  }

  .action-btn__text {
    display: inline;
    white-space: nowrap;
  }

  .action-btn--edit {
    background: var(--Primary_Dark);
    border-color: var(--Primary_Dark);
    color: var(--Primary_Light);
  }

  .action-btn--delete {
    flex: 0 0 var(--control-height);
    padding: 0;
  }

  .action-btn--delete .action-btn__text {
    display: none;
  }

  /* the "no results" row takes the whole grid */
  .data-table tbody tr.table-empty {
    grid-column: 1 / -1;
    padding: 0;
  }

  .data-table .table-empty td {
    width: 100%;
    padding: 32px 16px;
    text-align: center;
  }
}

@media only screen and (max-width: 991px) and (hover: hover) {
  .action-btn--edit:hover {
    background: var(--Accent_Hover);
    border-color: var(--Accent_Hover);
  }
}

/* ---------- MOBILE (< 768): 1 card per row ---------- */
@media only screen and (max-width: 767px) {
  .data-table tbody {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
}

@media only screen and (max-width: 359px) {
  .action-btn__text {
    font-size: 14px;
  }
}


/* ==========================================================================
   14. Pagination (js/pagination.js builds it)
   PC: numbered pages + rows per page.
   Tablet and mobile: "Cargar más" button (.load-more) instead.

   <nav class="pagination" id="pagination" aria-label="Paginación"></nav>
   <button class="btn btn--block load-more" id="loadMore" type="button">Cargar más</button>
   ========================================================================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 12px 16px;
  border-top: 1px solid var(--Accent_Light);
  font-size: var(--text-sm);
}

.pagination:empty {
  display: none;
}

.pagination__info {
  margin: 0;
}

.pagination__end {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
}

.pagination__size {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination__size select {
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius);
  background: var(--Primary_Light);
  color: var(--Text);
  font: inherit;
}

.pagination__pages {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pagination__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius);
  background: var(--Primary_Light);
  color: var(--Text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.pagination__btn[aria-current="page"] {
  background: var(--Primary_Dark);
  border-color: var(--Primary_Dark);
  color: var(--Primary_Light);
  font-weight: 600;
}

.pagination__btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.pagination__dots {
  min-width: 20px;
  text-align: center;
  color: var(--Accent_Dark);
}

.load-more {
  display: none;
  margin-top: 16px;
}

.load-more[hidden] {
  display: none !important;
}

@media (hover: hover) {
  .pagination__btn:not(:disabled):not([aria-current="page"]):hover {
    background: var(--Accent_Alpha10);
  }
}

@media only screen and (max-width: 991px) {
  .pagination {
    display: none;
  }

  .load-more {
    display: flex;
  }
}


/* ==========================================================================
   15. Modal (native <dialog>; js/modal.js opens and closes it)
   Open:  <button data-modal-open="modalId">
   Close: any element with data-modal-close, Esc, or a click outside.

   <dialog class="modal [modal--sm]" id="modalId" aria-labelledby="modalIdTitle">
     <form class="modal__form" method="dialog" novalidate>
       <header class="modal__header">
         <h2 class="modal__title" id="modalIdTitle">Editar producto</h2>
         <p class="modal__subtitle">Saco rafia…</p>
         <button class="modal__close" type="button" data-modal-close aria-label="Cerrar">…</button>
       </header>
       <div class="modal__body">…</div>
       <footer class="modal__footer">
         <button class="btn" type="button" data-modal-close>Cancelar</button>
         <button class="btn btn--dark" type="submit">Guardar</button>
       </footer>
     </form>
   </dialog>
   ========================================================================== */
.modal {
  width: min(600px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--Accent_Light);
  border-radius: var(--radius-lg);
  background: var(--Primary_Light);
  color: var(--Text);
  box-shadow: 0 20px 48px rgba(31, 41, 51, .25);
}

.modal--sm {
  width: min(440px, calc(100vw - 32px));
}

/* literal colour: some browsers don't pass variables to ::backdrop */
.modal::backdrop {
  background: rgba(31, 41, 51, .5);
}

.modal[open] {
  display: flex;
  flex-direction: column;
}

.modal__form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: inherit;
}

.modal__header {
  position: relative;
  flex: none;
  padding: 22px 64px 16px 24px;
  border-bottom: 1px solid var(--Accent_Light);
}

.modal__title {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.modal__subtitle {
  margin: 4px 0 0;
  font-size: var(--text-sm);
  color: var(--Accent_Dark);
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--Accent_Dark);
  font-size: 20px;
  cursor: pointer;
}

.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
}

.modal__footer {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--Accent_Light);
}

.modal__footer .btn {
  min-width: 120px;
}

/* Confirmation modal (delete…): centred, with an icon */
.modal--confirm .modal__header {
  padding: 28px 24px 0;
  border-bottom: 0;
  text-align: center;
}

.modal--confirm .modal__body {
  padding-top: 8px;
  text-align: center;
}

.modal--confirm .modal__footer {
  justify-content: center;
  border-top: 0;
  padding-top: 0;
  padding-bottom: 24px;
}

.modal__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: #8B26351a; /* wine 10% */
  color: var(--Danger);
  font-size: 24px;
}

/* Details list (view modal) */
.details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 24px;
  margin: 0;
}

.details div {
  min-width: 0;
}

.details dt {
  font-size: var(--text-sm);
  color: var(--Accent_Dark);
}

.details dd {
  margin: 2px 0 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.details .details__wide {
  grid-column: 1 / -1;
}

@media (hover: hover) {
  .modal__close:hover {
    background: var(--Accent_Alpha10);
    color: var(--Text);
  }
}

@media only screen and (max-width: 767px) {
  .modal__header {
    padding: 18px 60px 14px 20px;
  }

  .modal__body {
    padding: 16px 20px;
  }

  .modal__footer {
    padding: 14px 20px;
  }

  .modal__footer .btn {
    flex: 1 1 0;
    min-width: 0;
  }

  .modal--confirm .modal__footer {
    padding-bottom: 20px;
  }
}

@media only screen and (max-width: 420px) {
  .modal__footer {
    flex-direction: column-reverse;
  }

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


/* ==========================================================================
   16. Toast (short confirmation message: "Producto guardado")
   <div class="toast" id="toast" role="status" aria-live="polite"></div>
   (always in the HTML; empty = invisible. That way screen readers announce it.)
   ========================================================================== */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 260;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--Primary_Dark);
  color: var(--Primary_Light);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(31, 41, 51, .3);
}

.toast:empty {
  opacity: 0;
  pointer-events: none;
}

@media only screen and (max-width: 767px) {
  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: none;
  }
}
