/* ==========================================================================
   Primitive bp- — ogni componente usa SOLO i token.
   Naming BEM con prefisso bp-. Mobile-first, breakpoint 640/768/1024/1280.
   ========================================================================== */

/* --- Icona --- */
.bp-icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.bp-icon--sm { width: 18px; height: 18px; }
.bp-icon--lg { width: 32px; height: 32px; }

/* --- Bottoni --- */
.bp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 12px 24px;
  border-radius: var(--pill);
  font-weight: 600;
  font-size: var(--fs-md);
  border: 1.5px solid transparent;
  transition: background var(--t-fast), transform var(--t-fast) var(--ease-out), border-color var(--t-fast);
  min-height: 44px; /* target touch */
}
.bp-btn:active { transform: scale(0.98); }
.bp-btn[disabled], .bp-btn[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }

.bp-btn--primary { background: var(--orange); color: var(--white); }
.bp-btn--primary:hover { background: var(--orange); }

.bp-btn--navy { background: var(--navy); color: var(--white); }
.bp-btn--navy:hover { background: var(--navy-deep); }

.bp-btn--secondary { background: var(--white); color: var(--navy); border-color: var(--n3); }
.bp-btn--secondary:hover { border-color: var(--navy); }

.bp-btn--ghost { background: transparent; color: var(--navy); }
.bp-btn--ghost:hover { background: var(--n2); }

.bp-btn--danger { background: var(--orange); color: var(--white); }
.bp-btn--danger:hover { background: var(--orange); }

.bp-btn--ok { background: var(--ok); color: var(--white); }
.bp-btn--ok:hover { background: var(--n10); }

.bp-btn--warn { background: var(--orange); color: var(--white); }
.bp-btn--warn:hover { background: var(--orange); }

.bp-btn--sm { padding: 8px 16px; font-size: var(--fs-sm); min-height: 36px; }
.bp-btn--block { width: 100%; }

/* Icon-only */
.bp-btn--icon { padding: 10px; width: 44px; height: 44px; border-radius: 50%; gap: 0; }

/* --- Form --- */
.bp-field { display: grid; gap: 6px; }
.bp-label { font-size: var(--fs-sm); font-weight: 600; color: var(--n7); }

.bp-input,
.bp-select,
.bp-textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--n3);
  background: var(--white);
  min-height: 46px;
  transition: border-color var(--t-fast);
}
.bp-input:focus, .bp-select:focus, .bp-textarea:focus {
  border-color: var(--sky);
  outline: none;
  box-shadow: 0 0 0 3px var(--info-bg);
}
.bp-input[aria-invalid="true"] { border-color: var(--danger); }
.bp-help { font-size: var(--fs-xs); color: var(--n6); }
.bp-error { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; }

.bp-checkbox, .bp-radio { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; }
.bp-checkbox input, .bp-radio input { width: 20px; height: 20px; accent-color: var(--orange); flex: none; }

/* Ricerca */
.bp-search { position: relative; }
.bp-search .bp-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--n5); width: 20px; height: 20px; pointer-events: none;
}
.bp-search .bp-input { padding-left: 44px; }
.bp-search__reset {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--n6); padding: 6px; border-radius: 50%;
}

/* --- Card --- */
.bp-card {
  background: var(--white);
  border: 1px solid var(--n3);
  border-radius: var(--radius);
  padding: var(--sp-4);
}
.bp-card--pad { padding: var(--sp-5); }
.bp-card--flat { border: none; box-shadow: var(--shadow-card); }

/* Card con ribbon (ACQUISTATO / SOLD OUT / COMING SOON) */
.bp-ribbon-card { position: relative; overflow: hidden; }
.bp-ribbon {
  position: absolute; top: 14px; right: -34px;
  transform: rotate(38deg);
  width: 130px; text-align: center;
  padding: 4px 0;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.04em;
  color: var(--white);
  background: var(--orange);
}
.bp-ribbon--soldout { background: var(--n7); }
.bp-ribbon--soon { background: var(--sky); }

/* --- Badge e chip --- */
.bp-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--pill);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.03em;
  background: var(--n2); color: var(--n7);
}
.bp-badge--ok { background: var(--ok-bg); color: var(--ok); }
.bp-badge--warn { background: var(--warn-bg); color: var(--warn); }
.bp-badge--danger { background: var(--danger-bg); color: var(--danger); }
.bp-badge--info { background: var(--info-bg); color: var(--info); }
.bp-badge--orange { background: var(--orange-soft); color: var(--orange-text); }
.bp-badge--navy { background: var(--navy); color: var(--white); }

/* Pill di filtro (categorie messaggi, tipo file) con contatore */
.bp-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: var(--pill);
  background: var(--white); border: 1.5px solid var(--n3);
  color: var(--n7); font-weight: 600; font-size: var(--fs-sm);
  cursor: pointer; white-space: nowrap;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.bp-chip:hover { border-color: var(--sky); }
.bp-chip[aria-pressed="true"], .bp-chip.is-active {
  background: var(--navy); border-color: var(--navy); color: var(--white);
}
.bp-chip__count {
  min-width: 22px; height: 22px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--pill);
  background: var(--n2); color: var(--n7); font-size: var(--fs-xs);
}
.bp-chip[aria-pressed="true"] .bp-chip__count, .bp-chip.is-active .bp-chip__count {
  background: var(--orange); color: var(--white);
}
.bp-chip-row {
  display: flex; gap: var(--sp-2); overflow-x: auto;
  padding: var(--sp-1) 0; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.bp-chip-row::-webkit-scrollbar { display: none; }

/* --- KPI stat card --- */
.bp-kpi {
  background: var(--white); border: 1px solid var(--n3);
  border-radius: var(--radius); padding: var(--sp-4);
  display: grid; gap: var(--sp-1);
  position: relative; overflow: hidden;
}
.bp-kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: var(--navy);
}
.bp-kpi--orange::before { background: var(--orange); }
.bp-kpi--ok::before { background: var(--ok); }
.bp-kpi--warn::before { background: var(--warn); }
.bp-kpi--danger::before { background: var(--danger); }
.bp-kpi__num {
  font-family: var(--serif); font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 700; color: var(--navy-deep); line-height: 1.1;
}
.bp-kpi__label { font-size: var(--fs-sm); color: var(--n6); }

/* --- Tab pill --- */
.bp-tabs { display: flex; gap: var(--sp-2); overflow-x: auto; scrollbar-width: none; }
.bp-tabs::-webkit-scrollbar { display: none; }
.bp-tab {
  padding: 10px 20px; border-radius: var(--pill);
  font-weight: 600; font-size: var(--fs-sm); color: var(--n6);
  white-space: nowrap; border: 1.5px solid transparent;
  min-height: 42px; display: inline-flex; align-items: center; gap: 8px;
}
.bp-tab[aria-selected="true"] { background: var(--white); color: var(--navy); border-color: var(--n3); }
.bp-tab__count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--pill);
  background: var(--n2); color: var(--n7); font-size: var(--fs-xs);
  display: inline-flex; align-items: center; justify-content: center;
}
.bp-tab[aria-selected="true"] .bp-tab__count { background: var(--orange-soft); color: var(--orange-text); }

/* Segment control (filtri stato incarichi) */
.bp-segment {
  display: flex; background: var(--n2); border-radius: var(--pill); padding: 4px;
  gap: 2px; overflow-x: auto; scrollbar-width: none;
}
.bp-segment__btn {
  flex: 1; padding: 8px 14px; border-radius: var(--pill);
  font-size: var(--fs-sm); font-weight: 600; color: var(--n6);
  white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px;
}
.bp-segment__btn.is-active { background: var(--white); color: var(--navy); box-shadow: var(--shadow-card); }

/* --- Tabelle responsive: tabella su desktop, card stack su mobile --- */
.bp-table { width: 100%; border-collapse: collapse; background: var(--white); }
.bp-table th {
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--n6); font-weight: 700;
  padding: 12px 16px; border-bottom: 1.5px solid var(--n3);
}
.bp-table td { padding: 14px 16px; border-bottom: 1px solid var(--n2); font-size: var(--fs-sm); vertical-align: middle; }
.bp-table tbody tr:hover { background: var(--n1); }
.bp-table-wrap { border: 1px solid var(--n3); border-radius: var(--radius); overflow: hidden; }

@media (max-width: 767px) {
  .bp-table-wrap.bp-table--stack thead { display: none; }
  .bp-table-wrap.bp-table--stack tbody { display: grid; gap: var(--sp-2); padding: var(--sp-2); background: var(--n2); }
  .bp-table-wrap.bp-table--stack tr {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
    background: var(--white); border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4);
    border-bottom: none;
  }
  .bp-table-wrap.bp-table--stack td { border-bottom: none; padding: 2px 0; }
  .bp-table-wrap.bp-table--stack td[data-label]::before {
    content: attr(data-label);
    display: block; font-size: var(--fs-xs); color: var(--n6); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .bp-table-wrap.bp-table--stack td:first-child { grid-column: 1 / -1; }
}

/* --- Alert / banner --- */
.bp-alert {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-4); border-radius: var(--radius);
  background: var(--info-bg); color: var(--info); font-size: var(--fs-sm);
}
.bp-alert--warn { background: var(--warn-bg); color: var(--warn); }
.bp-alert--danger { background: var(--danger-bg); color: var(--danger); }
.bp-alert--ok { background: var(--ok-bg); color: var(--ok); }

/* --- Empty state --- */
.bp-empty {
  text-align: center; padding: var(--sp-8) var(--sp-4);
  display: grid; gap: var(--sp-3); justify-items: center;
}
.bp-empty__icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--n2); color: var(--sky);
  display: grid; place-items: center;
}
.bp-empty__title { font-family: var(--serif); font-size: var(--fs-xl); color: var(--navy-deep); font-weight: 700; }
.bp-empty__text { color: var(--n6); max-width: 420px; }

/* --- Avatar --- */
.bp-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--navy); color: var(--white);
  display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm);
  overflow: hidden; flex: none;
}
.bp-avatar--sm { width: 32px; height: 32px; font-size: var(--fs-xs); }
.bp-avatar--lg { width: 56px; height: 56px; }
.bp-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* --- Pallino notifica --- */
.bp-dot {
  position: absolute; top: -2px; right: -2px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: var(--pill);
  background: var(--orange); color: var(--white);
  font-size: 0.6875rem; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--white);
}
.bp-dot--plain { min-width: 12px; width: 12px; height: 12px; padding: 0; border-width: 2px; }

/* --- Modale --- */
.bp-modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--sp-4);
  background: rgba(11, 37, 71, 0.55);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-med) var(--ease-out);
}
.bp-modal.is-open { opacity: 1; pointer-events: auto; }
.bp-modal__panel {
  background: var(--white); border-radius: var(--radius-lg);
  width: min(480px, 100%); max-height: 86dvh; overflow-y: auto;
  padding: var(--sp-5); box-shadow: var(--shadow-panel);
  transform: translateY(14px) scale(0.98);
  transition: transform var(--t-med) var(--ease-out);
}
.bp-modal.is-open .bp-modal__panel { transform: none; }
.bp-modal__title { font-family: var(--serif); font-size: var(--fs-xl); color: var(--navy-deep); font-weight: 700; }
.bp-modal__close { position: absolute; margin-left: auto; }

/* --- Chat --- */
.bp-msg { display: flex; gap: var(--sp-2); max-width: 86%; }
.bp-msg--me { margin-left: auto; flex-direction: row-reverse; }
.bp-msg__bubble {
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  background: var(--white); border: 1px solid var(--n3);
  font-size: var(--fs-sm);
}
.bp-msg--me .bp-msg__bubble { background: var(--navy); color: var(--white); border-color: var(--navy); }
.bp-msg__time { font-size: var(--fs-xs); color: var(--n5); margin-top: 4px; }
.bp-msg__name { font-size: var(--fs-xs); font-weight: 700; color: var(--sky-deep); margin-bottom: 2px; }

/* Card allegato */
.bp-attach {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3); border-radius: var(--radius-sm);
  background: var(--n1); border: 1px solid var(--n3);
}
.bp-attach__icon {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: var(--info-bg); color: var(--info);
  display: grid; place-items: center; flex: none;
}
.bp-attach__ext {
  font-size: var(--fs-xs); font-weight: 700; color: var(--n6);
  background: var(--n2); padding: 2px 8px; border-radius: var(--pill);
}

/* --- Hero --- */
.bp-hero {
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy) 60%, var(--sky-deep) 100%);
  color: var(--white);
  border-radius: var(--radius-lg);
  padding: var(--sp-6) var(--sp-5);
  position: relative; overflow: hidden;
}
.bp-hero__title { font-family: var(--serif); font-size: var(--fs-2xl); font-weight: 700; line-height: 1.2; }
.bp-hero__text { color: var(--on-navy); margin-top: var(--sp-2); font-size: var(--fs-sm); }

/* --- Utility --- */
.bp-stack { display: grid; gap: var(--sp-4); }
.bp-row { display: flex; align-items: center; gap: var(--sp-3); }
.bp-muted { color: var(--n6); }
.bp-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
