/*
 * Manifest Propshaft: stile globale del Del Mar Operations Hub, un file per ora.
 * Palette brand Del Mar: navy #26327e (pesce del logo), azzurro #aadcf2 (accento chiaro),
 * grigio #7d8689 (scritta DelMar del logo).
 * Font: Inter variable (self-hosted in app/assets/fonts/inter, licenza OFL), fallback
 * system stack. I PDF NON lo usano: pdf.css e' inlinato a parte con font propri.
 * Linguaggio visivo "app": card bianche su fondo freddo, bottoni pill, badge, accenti
 * gradiente navy, elevazione a 3 livelli (--shadow-1/2/3). Mobile-first: gli agenti usano
 * l'app da telefono durante le visite.
 * Regole: una property per riga; ombre SOLO dalla scala di elevazione (design system).
 */

@font-face {
  font-family: "Inter";
  src: url("/assets/inter/InterVariable-884c49a1.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("/assets/inter/InterVariable-Italic-0aa7a4b3.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

/* NIENTE BARRE DI SCORRIMENTO visibili, in tutta l'app (richiesta Mattias 2026-07-20):
 * lo scroll (rotella, touch, tastiera) continua a funzionare ovunque — spariscono solo
 * le barre, verticali e orizzontali, pagina e contenitori interni inclusi. */
* {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

:root {
  --navy: #26327e;
  --navy-dark: #1d2661;
  --navy-bright: #3547ab;
  --azure: #aadcf2;
  /* accento azzurro chiaro (evidenze, righe selezionate) */
  --azure-soft: #e9f5fc;
  --gray-logo: #7d8689;
  --gray-text: #5f6368;
  --border: #dee5ee;
  --border-soft: #e9eef5;
  --ink: #1a1d21;
  --surface: #ffffff;
  --bg: #eef2f8;
  --danger: #b3261e;
  --semaforo-verde: #1b873f;
  --semaforo-arancio: #e8710a;
  --radius: 16px;
  --radius-small: 12px;
  --assistant-panel-width: 380px;
  /* Altezza condivisa tra header dell'app e testata del pannello Marina: le due linee
   * di confine devono combaciare al pixel. */
  --header-height: 58px;
  --gradient-brand: linear-gradient(120deg, #26327e 0%, #3547ab 60%, #4f8fca 100%);
  /* Scala di elevazione a 3 livelli, unica per tutta l'app (prima viveva in procurement.css
   * scoped a .procurement-page). Ombre SOLO da qui; focus ring e barre-indicatore via
   * outline/border, mai box-shadow fuori scala. Vedi docs/design_system.md. */
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --shadow-2: 0 4px 8px -2px rgba(16, 24, 40, 0.1), 0 2px 4px -2px rgba(16, 24, 40, 0.06);
  --shadow-3: 0 20px 32px -8px rgba(16, 24, 40, 0.18), 0 8px 12px -4px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-optical-sizing: auto;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a,
button,
input {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

:focus-visible {
  outline: 2px solid var(--navy-bright);
  outline-offset: 2px;
}

::selection {
  background: var(--azure);
}

.page-placeholder {
  max-width: 640px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--surface);
  border-radius: var(--radius);
  text-align: center;
}

.flash {
  max-width: 720px;
  margin: 1rem auto 0;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-small);
  font-size: 0.9rem;
  font-weight: 500;
}

.flash-notice {
  background: #e2f5e9;
  color: #176b32;
}

.flash-alert {
  background: #fdecea;
  color: var(--danger);
}

/* Etichette e badge */

.eyebrow {
  margin: 0 0 0.15rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gray-logo);
}

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.15rem 0.6rem;
  background: var(--azure-soft);
  border: 1px solid var(--azure);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
}

/* Variante del badge per il prezzo negoziato del cliente (vince sul prezzo di listino) */

.badge-negotiated {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--surface);
}

/* Variante per i prodotti FRESCO nel flusso cliente nuovo: listino del giorno, prezzo
 * non personalizzabile */

.badge-daily-price {
  background: var(--surface);
  border-color: var(--gray-logo);
  color: var(--gray-text);
}

/* Dialog di conferma custom (sostituisce window.confirm, vedi application.js) */

.app-confirm {
  width: min(360px, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-3);
}

.app-confirm::backdrop {
  background: rgba(16, 22, 46, 0.45);
  backdrop-filter: blur(2px);
}

.app-confirm-box {
  padding: 1.5rem 1.4rem 1.25rem;
}

.app-confirm-message {
  margin: 0 0 1.25rem;
  font-size: 1rem;
  line-height: 1.45;
}

.app-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.app-confirm-actions .btn-primary,
.app-confirm-actions .btn-secondary {
  min-height: 42px;
  padding: 0.55rem 1.3rem;
  font-size: 0.9rem;
}

/* Login */

.auth-form {
  max-width: 400px;
  margin: 9vh auto 2rem;
  padding: 2.25rem 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
}

.auth-logo {
  display: block;
  width: 200px;
  max-width: 70%;
  height: auto;
  margin: 0 auto 1.5rem;
}

.auth-form h2 {
  margin: 0 0 1.25rem;
  text-align: center;
  color: var(--navy);
}

.auth-form .field {
  margin-bottom: 1rem;
}

.auth-form .field label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.auth-form .field input[type="email"],
.auth-form .field input[type="password"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  font-size: 1rem;
  background: var(--bg);
}

.auth-form .field input[type="email"]:focus,
.auth-form .field input[type="password"]:focus {
  background: var(--surface);
  border-color: var(--navy);
}

.auth-form .actions {
  margin-top: 1.5rem;
}

.auth-form .actions input[type="submit"] {
  width: 100%;
}

#error_explanation {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: #fdecea;
  color: var(--danger);
  border-radius: var(--radius-small);
  font-size: 0.9rem;
}

/* Bottoni */

.btn-primary {
  display: inline-block;
  min-height: 46px;
  padding: 0.7rem 1.6rem;
  border: none;
  border-radius: 999px;
  background: var(--gradient-brand);
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--navy-dark);
}

.btn-secondary {
  display: inline-block;
  min-height: 46px;
  padding: 0.7rem 1.6rem;
  border: 1.5px solid var(--navy);
  border-radius: 999px;
  background: var(--surface);
  color: var(--navy);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--azure-soft);
}

/* Header applicazione (utente autenticato) */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: var(--header-height);
  padding: 0 1.1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}

.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: var(--gradient-brand);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
  text-decoration: none;
}

.app-logo {
  height: 38px;
  width: auto;
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* "Operations Hub" (piattaforma): il marchio "Del Mar" lo dice gia' il logo accanto. */
.app-brand-tail {
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-logo);
}

/* Etichetta del modulo corrente, separata da una barretta. */
.app-brand-module {
  padding-left: 0.65rem;
  margin-left: 0.1rem;
  border-left: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-text);
  white-space: nowrap;
}

/* Gruppo sinistro dell'header: hamburger + frecce cronologia, compatti. */
.header-left {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Frecce indietro/avanti della cronologia: quadrate e compatte, accanto all'hamburger. */
.header-history {
  display: inline-flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-nav-arrow {
  padding: 0.45rem 0.65rem;
}

.btn-nav-arrow .icon {
  width: 16px;
  height: 16px;
  display: block;
}

.btn-header {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0.45rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--navy);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-header:hover {
  background: var(--azure-soft);
  border-color: var(--navy);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4.5rem;
}

/* Storico liste generate */

.history-entry {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 0.6rem;
  padding: 0.9rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.history-body {
  flex: 1;
  min-width: 0;
}

.history-download {
  flex-shrink: 0;
  min-height: 42px;
  padding: 0.5rem 1.2rem;
}

/* Indicatore ultimo sync */

.sync-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 1.5rem 0 0;
  font-size: 0.82rem;
  color: var(--gray-text);
}

.sync-status-dot {
  width: 0.55rem;
  height: 0.55rem;
  flex-shrink: 0;
  background: #1e7e34;
  border-radius: 999px;
}

/* Ricerca cliente */

.client-search h2,
.client-page h2 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--navy);
}

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-form input[type="text"] {
  flex: 1;
  min-width: 0;
  min-height: 50px;
  padding: 0.7rem 1.25rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 1rem;
  background: var(--surface);
}

.search-form input[type="text"]:focus {
  outline: none;
  border-color: var(--navy);
  background: var(--surface);
}

.search-form input[type="submit"] {
  flex-shrink: 0;
}

/* Call to action "cliente nuovo": un bottone vero, ben visibile */

.btn-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  margin: 0 0 1.5rem;
  padding: 0.8rem 1.3rem;
  border: 1.5px solid var(--navy);
  border-radius: 999px;
  background: var(--surface);
  color: var(--navy);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
}

.btn-cta:hover {
  background: var(--azure-soft);
}

.btn-cta-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  flex-shrink: 0;
  background: var(--gradient-brand);
  border-radius: 999px;
  color: #ffffff;
}

.btn-cta-icon .icon {
  width: 1.05rem;
  height: 1.05rem;
}

.empty-state {
  padding: 1.5rem 0.25rem;
  color: var(--gray-text);
}

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

.client-result {
  display: block;
  margin-bottom: 0.6rem;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
}

.client-result:hover {
  border-color: var(--navy);
  background: var(--azure-soft);
}

.client-result-name {
  display: block;
  font-weight: 600;
  color: var(--navy);
}

.client-result-meta {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.85rem;
  color: var(--gray-text);
}

/* Selezione listino (cliente nuovo) */

.pricelist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pricelist-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  height: 100%;
  margin-bottom: 0;
}

.pricelist-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  height: 2.6rem;
  flex-shrink: 0;
  background: var(--azure-soft);
  border: 1px solid var(--azure);
  border-radius: 999px;
  color: var(--navy);
}

.pricelist-icon .icon {
  width: 1.3rem;
  height: 1.3rem;
}

.pricelist-body {
  min-width: 0;
}

.pricelist-card .badge {
  margin-left: 0;
}

/* Scheda cliente e tabella prodotti */

/* Pulsante indietro sticky: visibile anche scorrendo elenchi lunghi */

.icon {
  width: 1.25rem;
  height: 1.25rem;
  vertical-align: -0.25em;
}

.back-bar {
  position: sticky;
  top: 4rem;
  z-index: 15;
  display: flex;
  margin-bottom: 0.9rem;
  pointer-events: none;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.5rem 1.2rem 0.5rem 0.9rem;
  border: 1.5px solid var(--navy);
  border-radius: 999px;
  background: var(--surface);
  color: var(--navy);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  pointer-events: auto;
}

.btn-back:hover {
  background: var(--azure-soft);
}

.btn-back .icon {
  width: 1.35rem;
  height: 1.35rem;
}

.client-header {
  margin-bottom: 1.25rem;
}

.client-header h2 {
  margin-bottom: 0.25rem;
}

.banner-warning {
  margin: 0 0 1rem;
  padding: 0.8rem 1.1rem;
  background: #fef7e0;
  color: #7a5d00;
  border-radius: var(--radius-small);
  font-size: 0.9rem;
}

.price-builder {
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.price-builder h3 {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gray-logo);
}

.products-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.products-table th,
.products-table td {
  padding: 0.7rem 0.5rem;
  text-align: left;
  font-size: 0.93rem;
}

.products-table th {
  padding-top: 0;
  border-bottom: 2px solid var(--navy);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gray-text);
}

.products-table tbody td {
  border-bottom: 1px solid var(--border-soft);
}

.products-table tbody tr:last-child td {
  border-bottom: none;
}

/* Righe alternate bianco/azzurro come il listino PDF ufficiale: piu' leggibile */

.products-table tbody tr:nth-child(even) td {
  background: var(--azure-soft);
}

.products-table tbody tr:hover td {
  background: var(--azure);
}

.products-table .col-price {
  text-align: right;
  white-space: nowrap;
  font-weight: 600;
  color: var(--navy);
}

.price-unit {
  font-weight: 500;
  font-size: 0.85em;
  color: var(--gray-text);
}

.products-table .col-actions {
  width: 2.75rem;
  text-align: right;
}

.row-meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--gray-text);
}

.product-code {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.row-remove {
  min-width: 38px;
  min-height: 38px;
  padding: 0.2rem 0.5rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--danger);
  font-size: 0.95rem;
  cursor: pointer;
}

.row-remove:hover {
  background: #fdecea;
}

/* Componente ricerca prodotti (product-search) */

.product-search {
  position: relative;
  margin-top: 1rem;
}

.product-search-input {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 1.25rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 1rem;
  background: var(--bg);
}

.product-search-input:focus {
  outline: none;
  border-color: var(--navy);
  background: var(--surface);
}

.product-search-results {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 10;
}

.product-search-list {
  margin: 0.35rem 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1.5px solid var(--navy);
  border-radius: var(--radius-small);
  max-height: min(320px, 50vh);
  overflow-y: auto;
}

.product-search-result {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  width: 100%;
  min-height: 48px;
  padding: 0.65rem 0.9rem;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}

.product-search-result:hover {
  background: var(--azure-soft);
}

.product-search-result .result-name {
  flex: 1;
  min-width: 8rem;
}

.product-search-result .result-meta {
  color: var(--gray-text);
  font-size: 0.82rem;
  white-space: nowrap;
}

.product-search-result .result-price {
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
}

.product-search-empty {
  margin: 0.35rem 0 0;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  color: var(--gray-text);
  font-size: 0.9rem;
}

/* Inserimento per categoria */

.category-add {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.category-add-select {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0.55rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.95rem;
}

.category-add-select:focus {
  outline: none;
  border-color: var(--navy);
  background: var(--surface);
}

.category-add-button {
  flex-shrink: 0;
}

/* Prezzo di vendita editabile con semaforo (flusso cliente nuovo, controller sale-price) */

.price-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.price-input {
  width: 5.5rem;
  min-height: 40px;
  padding: 0.35rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: right;
}

.price-input:focus {
  outline: none;
  border-color: var(--navy);
}

.price-input:invalid {
  border-color: var(--danger);
}

.price-light {
  flex-shrink: 0;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--border);
}

.price-light-green {
  background: var(--semaforo-verde);
}

.price-light-orange {
  background: var(--semaforo-arancio);
}

.price-light-blocked {
  background: var(--danger);
}

.col-price .price-limits {
  display: block;
  margin-top: 0.25rem;
}

/* Selettore del range temporale dei prodotti abituali (pill-link, nessun JS) */

.range-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}

.range-option {
  padding: 0.35rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--gray-text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.range-option:hover {
  border-color: var(--navy);
  background: var(--azure-soft);
  color: var(--navy);
}

.range-option.is-active {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--surface);
}

/* Nome del cliente nuovo (facoltativo): prefillabile dal deep-link, finisce sul documento */

.builder-client-name {
  margin-bottom: 1rem;
}

.builder-client-name label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--gray-text);
}

/* Stile base condiviso con .assistant-panel-input (vedi sezione pannello assistente) */
.builder-client-name input {
  width: 100%;
  border-radius: var(--radius-small);
}

/* L'hint "nessun prodotto" sparisce appena la tabella ha almeno una riga */

.price-builder .builder-hint {
  padding: 0.5rem 0.25rem 0.75rem;
}

.price-builder:has(tbody tr) .builder-hint {
  display: none;
}

/* Azioni di generazione documento: visibili solo con almeno una riga in tabella */

.builder-actions {
  display: none;
}

.price-builder:has(tbody tr) .builder-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

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

/* ---------------------------------------------------------------------------
 * Pannello assistente AI: aside destro full-height, data-turbo-permanent nel
 * layout (controller Stimulus assistant-panel). Si apre dal bottone Assistente
 * nell'header e si chiude con la X interna; aperto affianca il contenuto
 * spostando main e header via :has().
 * ------------------------------------------------------------------------- */

.assistant-panel {
  /* Linee strutturali del pannello piu' marcate del resto dell'app (richiesta Mattias) */
  --marina-line: #b9c5de;
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: var(--assistant-panel-width);
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  border-left: 2px solid var(--marina-line);
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.assistant-panel.is-open {
  transform: translateX(0);
}

/* Bottone di apertura nell'header (fuori dall'aside: delegazione [data-assistant-toggle]) */
.btn-assistant {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-assistant .icon {
  width: 1em;
  height: 1em;
}

.assistant-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 1.1rem;
  border-bottom: 2px solid var(--marina-line);
}

.assistant-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.assistant-panel-reset-form {
  display: flex;
}

/* Bottoni-icona della testata del pannello (nuova conversazione, chiudi) */
.assistant-panel-iconbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--gray-text);
  cursor: pointer;
}

.assistant-panel-iconbtn:hover {
  background: var(--azure-soft);
  color: var(--navy);
}

.assistant-panel-iconbtn .icon {
  width: 1.1em;
  height: 1.1em;
}

.assistant-panel-heading {
  display: flex;
  flex-direction: column;
}

.assistant-panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--navy);
}

.assistant-panel-subtitle {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.2;
  color: var(--gray-text);
}

.assistant-panel-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  overflow-y: auto;
}

.assistant-panel-empty {
  margin: 0;
  font-size: 0.9rem;
  color: var(--gray-text);
}

.assistant-panel-messages:has(.assistant-message) .assistant-panel-empty {
  display: none;
}

.assistant-message {
  max-width: 85%;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-small);
  font-size: 0.95rem;
  line-height: 1.4;
  overflow-wrap: break-word;
}

.assistant-message-user {
  align-self: flex-end;
  background: var(--navy);
  color: #ffffff;
}

/* Le risposte di Marina non stanno in una bolla: testo pieno a tutta larghezza, stile AI */
.assistant-message-assistant {
  align-self: stretch;
  max-width: 100%;
  padding: 0.15rem 0.1rem;
  background: transparent;
  color: var(--ink);
}

/* Contenuto Markdown delle risposte (paragrafi, grassetti, elenchi) */
.assistant-message p {
  margin: 0 0 0.45rem;
}

.assistant-message p:last-child {
  margin-bottom: 0;
}

.assistant-message ul,
.assistant-message ol {
  margin: 0.2rem 0 0.45rem;
  padding-left: 1.15rem;
}

.assistant-message ul:last-child,
.assistant-message ol:last-child {
  margin-bottom: 0;
}

.assistant-message li {
  margin-bottom: 0.2rem;
}

/* Card di stato "Marina sta lavorando": spinner + passi del ragionamento in tempo reale.
 * Appesa ottimistica dal client al submit e sostituita dal server (dedup per id); a fine
 * turno sparisce o diventa il riepilogo collassato .assistant-steps-done. */
.assistant-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.5rem;
  row-gap: 0.35rem;
  align-self: stretch;
  font-size: 0.9rem;
  color: var(--gray-text);
}

.assistant-status-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg, #4f8fca 240deg, var(--navy) 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  animation: assistant-spin 0.8s linear infinite;
}

@keyframes assistant-spin {
  to {
    transform: rotate(360deg);
  }
}

.assistant-status-text {
  margin: 0;
  font-weight: 500;
}

.assistant-status-steps {
  flex-basis: 100%;
  margin: 0;
  padding: 0 0 0 1.6rem;
  list-style: none;
}

.assistant-status-step {
  margin-bottom: 0.15rem;
  font-size: 0.85rem;
  animation: assistant-step-in 0.25s ease;
}

@keyframes assistant-step-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Riepilogo collassato dei passi a turno concluso */
.assistant-steps-done {
  align-self: stretch;
  font-size: 0.8rem;
  color: var(--gray-text);
}

.assistant-steps-done summary {
  cursor: pointer;
  user-select: none;
}

.assistant-steps-done ol {
  margin: 0.25rem 0 0;
  padding-left: 1.4rem;
  list-style: none;
}

.assistant-steps-done li {
  margin-bottom: 0.1rem;
}

@media (prefers-reduced-motion: reduce) {
  .assistant-status-spinner,
  .assistant-status-step {
    animation: none;
  }
}

/* Barra input su due righe: icone vocali sopra, casella + Invia sotto (sulla stessa riga
   la casella restava troppo schiacciata). */
.assistant-panel-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 2px solid var(--marina-line);
}

.assistant-panel-voice-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Nessun bottone visibile (niente Web Speech API e realtime spento): via la riga, o resta
   solo il gap orfano della colonna. */
.assistant-panel-voice-controls:not(:has(.assistant-panel-mic:not([hidden]))) {
  display: none;
}

.assistant-panel-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Microfono dei comandi vocali: tondo, si accende (navy) quando attivo e pulsa in ascolto. */

.assistant-panel-mic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--gray-text);
  cursor: pointer;
}

.assistant-panel-mic:hover {
  border-color: var(--navy);
  color: var(--navy);
}

.voice-active .assistant-panel-mic {
  background: var(--gradient-brand);
  border-color: transparent;
  color: #ffffff;
}

.voice-listening .assistant-panel-mic {
  animation: mic-pulse 1.1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  .voice-listening .assistant-panel-mic {
    animation: none;
  }
}

/* Modalita' realtime (esperimento): il bottone si accende in viola quando attiva e pulsa quando
   la sessione speech-to-speech e' aperta. */

.realtime-active .assistant-panel-realtime {
  background: var(--navy);
  border-color: transparent;
  color: #ffffff;
}

.realtime-session .assistant-panel-realtime {
  animation: mic-pulse 1.1s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .realtime-session .assistant-panel-realtime {
    animation: none;
  }
}

/* Stato dei comandi vocali sopra la barra input. */

.assistant-panel-voice-hint {
  margin: 0;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--marina-line);
  background: var(--azure-soft);
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--navy);
}

.voice-listening .assistant-panel-voice-hint {
  background: #e2f5e9;
  color: #176b32;
}

/* Base condivisa degli input testuali (chat e nome cliente nel costruttore) */
.assistant-panel-input,
.builder-client-name input {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1.5px solid var(--border);
  font-size: 0.95rem;
  background: var(--bg);
}

.assistant-panel-input {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
}

.assistant-panel-input:focus,
.builder-client-name input:focus {
  outline: none;
  border-color: var(--navy-bright);
}

/* Pannello aperto: header e contenuto si stringono invece di finire coperti (il pannello,
 * z-index 30, sta sopra l'header sticky, z-index 20). Il padding sul body preserva il
 * centraggio di .app-main (margin auto) nello spazio rimanente. */
body {
  transition: padding-right 0.2s ease;
}

body:has(.assistant-panel.is-open) {
  padding-right: var(--assistant-panel-width);
}

/* ---------------------------------------------------------------------------
 * Mobile (telefono): tabella prodotti a "righe card" con prezzo per unita',
 * bottoni a tutta larghezza, header compatto.
 * ------------------------------------------------------------------------- */

@media (max-width: 600px) {
  :root {
    --header-height: 50px;
  }

  .app-header {
    padding: 0 0.75rem;
  }

  .app-logo {
    height: 32px;
  }

  /* Su schermi stretti spariscono piattaforma e modulo: resta il logo Del Mar. */
  .app-brand-tail,
  .app-brand-module {
    display: none;
  }

  .app-main {
    padding: 1rem 0.75rem 3.5rem;
  }

  .client-search h2,
  .client-page h2 {
    font-size: 1.3rem;
  }

  .price-builder {
    padding: 1rem 0.85rem;
  }

  .products-table thead {
    display: none;
  }

  .products-table,
  .products-table tbody {
    display: block;
  }

  .products-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 0.75rem;
    padding: 0.7rem 0.25rem;
    border-bottom: 1px solid var(--border-soft);
  }

  .products-table tbody tr:last-child {
    border-bottom: none;
  }

  .products-table tbody tr:nth-child(even) {
    background: var(--azure-soft);
  }

  .products-table tbody td {
    display: block;
    padding: 0;
    border-bottom: none;
  }

  .products-table tbody tr:nth-child(even) td,
  .products-table tbody tr:hover td {
    background: transparent;
  }

  .back-bar {
    top: 3.4rem;
  }

  .products-table tbody td:first-child {
    flex: 1 1 100%;
    margin-bottom: 0.2rem;
    font-weight: 600;
  }

  .products-table .col-actions {
    width: auto;
    margin-left: auto;
  }

  .builder-actions,
  .price-builder:has(tbody tr) .builder-actions {
    flex-direction: column;
  }

  .builder-actions .btn-primary,
  .builder-actions .btn-secondary {
    width: 100%;
    text-align: center;
  }

  .product-search-result {
    flex-wrap: wrap;
  }

  .search-form input[type="submit"] {
    padding-left: 1.2rem;
    padding-right: 1.2rem;
  }

  .history-entry {
    flex-wrap: wrap;
  }

  .history-download {
    width: 100%;
    text-align: center;
  }

  /* Pannello assistente: da aperto e' un drawer a tutto schermo (il contenuto sotto
   * non si stringe, viene coperto), si chiude con la X interna. Nel bottone header
   * resta solo l'icona: lo spazio e' poco. */
  .assistant-panel {
    width: 100%;
  }

  .btn-assistant span {
    display: none;
  }

  body:has(.assistant-panel.is-open) {
    padding-right: 0;
  }
}

/* Schermi molto stretti: il titolo nell'header lascia spazio a logo e logout */

@media (max-width: 380px) {
  .app-header h1 {
    display: none;
  }
}
