/* ============================================================
   KCRM Catalogo Pubblico - style.css
   Design moderno, responsive, professionale
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --navy:    #105c87;
  --accent:  #ed6c05;
  --navy-dark: #0a4a70;
  --accent-dark: #d45f04;
  --bg:      #f4f6f9;
  --surface: #ffffff;
  --border:  #e6eaef;
  --text:    #1f2937;
  --muted:   #6b7280;
  --success: #16a34a;
  --danger:  #dc2626;
  --radius:  14px;
  --shadow-sm: 0 1px 2px rgba(16,42,67,.06), 0 1px 3px rgba(16,42,67,.05);
  --shadow-md: 0 4px 14px rgba(16,42,67,.08);
  --shadow-lg: 0 14px 40px rgba(16,42,67,.14);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Header ---- */
.site-header {
  background: var(--navy);
  color: #fff;
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo a {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 2px;
  text-decoration: none;
}

.logo span {
  display: block;
  font-size: .72rem;
  color: rgba(255,255,255,.5);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.header-title {
  flex: 1;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-decoration: none;
  transition: opacity .15s;
}
.header-title:hover { opacity: .8; text-decoration: none; }

@media (max-width: 640px) {
  /* Su schermo stretto il titolo "Catalogo prodotti" veniva tagliato accanto al
     logo. È ridondante con il grande "Esplora il nostro catalogo" subito sotto,
     quindi su mobile lo nascondiamo e lasciamo header pulito (logo + carrello). */
  .header-title { display: none; }
  .header-inner { gap: .5rem; }
  .btn-cart { padding: .45rem .8rem; font-size: .82rem; }
}

.btn-cart {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: .5rem 1.25rem;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}
.btn-cart:hover { background: var(--accent); color: var(--navy); border-color: var(--accent); }

.cart-count {
  background: var(--accent);
  color: var(--navy);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
}

.btn-back {
  color: rgba(255,255,255,.8);
  font-size: .9rem;
  padding: .4rem .875rem;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 7px;
  transition: all .15s;
}
.btn-back:hover { color: #fff; border-color: rgba(255,255,255,.6); text-decoration: none; }

/* ---- Hero ---- */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: #fff;
  padding: 3rem 0 2.5rem;
  text-align: center;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: .5rem;
}

.hero p {
  color: rgba(255,255,255,.7);
  font-size: 1.05rem;
  margin-bottom: 1.75rem;
}

.hero-lead {
  max-width: 720px;
  margin: 0 auto 1.75rem;
  background: #1c7fb5;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 12px;
  padding: 1.1rem 1.5rem;
  color: #fff;
  font-size: 1.125rem;
  line-height: 1.6;
  font-weight: 500;
}

.search-form {
  display: flex;
  gap: .5rem;
  max-width: 640px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: .75rem 1.25rem;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  outline: none;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}

.btn-search {
  background: var(--accent);
  color: var(--navy);
  border: none;
  border-radius: 999px;
  padding: .75rem 1.5rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-search:hover { background: #d45f04; }

.btn-reset {
  background: rgba(255,255,255,.15);
  color: #fff;
  border-radius: 999px;
  padding: .75rem 1.25rem;
  font-size: .9rem;
  transition: background .15s;
}
.btn-reset:hover { background: rgba(255,255,255,.25); text-decoration: none; }

/* ---- Layout principale ---- */
.main-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.75rem;
  padding: 2rem 1.5rem;
  align-items: start;
}

@media (max-width: 768px) {
  .main-layout { grid-template-columns: 1fr; }
  /* NB: l'override dello sticky del menu categorie sta più in basso, SUBITO DOPO
     la definizione di .sidebar-cats — se stesse qui verrebbe annullato, perché a
     parità di specificità in CSS vince la regola che compare per ultima. */
}

/* ---- Interruttore Prodotti / Servizi ---- */
.view-switch {
  display: flex;
  gap: .4rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.view-switch-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .6rem .5rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
  text-decoration: none;
  transition: all .15s;
}
.view-switch-btn:hover { border-color: var(--navy); color: var(--navy); text-decoration: none; }
.view-switch-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.view-switch-count {
  background: rgba(0,0,0,.08);
  color: inherit;
  border-radius: 999px;
  padding: .05rem .5rem;
  font-size: .78rem;
  font-weight: 700;
}
.view-switch-btn.active .view-switch-count { background: rgba(255,255,255,.25); }

/* ---- Sidebar categorie ---- */
.sidebar-cats {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.5rem 1.25rem;
  position: sticky;
  top: 80px;
  box-shadow: 0 1px 3px rgba(16,92,135,.06);
}

/* Su mobile il menu categorie NON deve essere "appiccicato": in colonna singola
   resterebbe fisso sopra i prodotti, coprendoli durante lo scorrimento.
   Questa regola va tenuta DOPO quella qui sopra, altrimenti viene annullata. */
@media (max-width: 768px) {
  .sidebar-cats {
    position: static;
    top: auto;
  }
}

.cats-title {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}

.cats-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.cats-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .55rem .75rem;
  border-radius: 8px;
  font-size: .9rem;
  color: var(--text);
  transition: background .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
}
.cats-list a span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cats-list a:hover { background: #f0f4f8; text-decoration: none; }
.cats-list a.active { background: var(--navy); color: #fff; font-weight: 600; }
.cats-list a.active .cat-count { background: rgba(255,255,255,.22); color: #fff; }

/* Categorie ad accordion: i livelli sotto la radice sono nascosti di default */
.cat-item { list-style: none; }
.cat-row { display: flex; align-items: stretch; gap: 0; }
.cat-row a { flex: 1; min-width: 0; }
.cat-toggle {
  width: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .65rem;
  border-radius: 8px; transition: transform .2s ease, background .15s, color .15s;
}
.cat-toggle:hover { background: #f0f4f8; color: var(--navy); }
.cat-toggle.open { transform: rotate(90deg); }
.cat-children {
  list-style: none;
  display: none;
  flex-direction: column;
  gap: .2rem;
  margin: .2rem 0 .4rem .875rem;
  padding-left: .875rem;
  border-left: 2px solid var(--border);
}
.cat-children.open { display: flex; }
.cat-children .cat-item { list-style: none; }
.cat-children .cats-list a,
.cat-children a { font-size: .84rem; padding: .45rem .65rem; color: var(--muted); }
.cat-children a:hover { color: var(--text); }
.cat-children a.active { color: #fff; }

.cat-count {
  background: #eef1f5;
  color: var(--muted);
  border-radius: 999px;
  padding: .1rem .55rem;
  font-size: .74rem;
  font-weight: 600;
  flex-shrink: 0;
}

/* ---- Results bar ---- */
.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .875rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}

/* ---- Griglia prodotti ---- */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform .22s cubic-bezier(.2,.7,.3,1), box-shadow .22s ease, border-color .22s ease;
}
.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: #d3dde6;
}

.product-img {
  position: relative;
  height: 190px;
  background: linear-gradient(160deg, #fbfcfe 0%, #eef2f6 100%);
  overflow: hidden;
}

.product-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .35s ease;
}
.product-card:hover .product-img img { transform: scale(1.05); }

.product-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: linear-gradient(135deg, #f0f4f8, #e2e6ea);
}

.product-type-badge {
  position: absolute;
  top: .625rem;
  right: .625rem;
  background: var(--navy);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  padding: .2rem .625rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.product-info {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

.product-cat {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.product-code {
  font-family: 'Courier New', monospace;
  font-size: .78rem;
  color: var(--muted);
  background: #f0f2f5;
  padding: .1rem .4rem;
  border-radius: 4px;
  display: inline-block;
}

.product-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.3;
}

.product-desc {
  font-size: .9rem;
  color: #4b5563;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  /* Riserva sempre lo spazio di 3 righe: card tutte della stessa altezza,
     descrizioni corte e lunghe allineate. Prezzo/azione restano in basso. */
  min-height: calc(3 * 1.5em);
  max-height: calc(3 * 1.5em);
  margin: .1rem 0 .35rem;
}
.product-desc p { margin: 0; display: inline; }
.product-desc strong { color: var(--navy); font-weight: 600; }

.product-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .25rem;
}

.tag {
  background: #e8f0fa;
  color: var(--navy);
  font-size: .7rem;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-weight: 500;
}

.product-price {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--navy);
  margin-top: auto;
  padding-top: .5rem;
}
.price-unit { font-size: .85rem; font-weight: 400; color: var(--muted); }

.product-price-hidden {
  font-size: 1rem;
  color: var(--muted);
  font-style: italic;
  margin-top: auto;
  padding-top: .5rem;
}

.product-action {
  padding: .875rem 1rem;
  border-top: 1px solid var(--border);
}

.btn-add {
  width: 100%;
  padding: .7rem;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 9px;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(16,92,135,.25);
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn-add:hover { background: #0a4a70; box-shadow: 0 4px 12px rgba(16,92,135,.35); }
.btn-add:active { transform: translateY(1px); }

.btn-remove {
  width: 100%;
  padding: .625rem;
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn-remove:hover { background: #fee2e2; color: var(--danger); border-color: #fecaca; }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { color: var(--text); margin-bottom: .5rem; }

/* ---- Paginazione ---- */
.pagination {
  display: flex;
  gap: .5rem;
  justify-content: center;
  margin-top: 2rem;
  flex-wrap: wrap;
}
.pagination a {
  padding: .5rem .875rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .875rem;
  color: var(--navy);
  background: #fff;
  transition: all .15s;
}
.pagination a:hover { background: var(--navy); color: #fff; text-decoration: none; }
.pagination a.active { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }

/* ---- Drawer carrello ---- */
.cart-drawer {
  position: fixed;
  top: 0;
  right: -420px;
  width: 420px;
  max-width: 95vw;
  height: 100vh;
  background: #fff;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
  transition: right .3s cubic-bezier(.4,0,.2,1);
}
.cart-drawer.open { right: 0; }

.cart-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 999;
  display: none;
}
.cart-overlay.open { display: block; }

.cart-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--navy);
  color: #fff;
}
.cart-drawer-header h3 { font-size: 1rem; font-weight: 600; }
.cart-drawer-header button {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

.cart-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
}

.cart-empty { color: var(--muted); font-size: .9rem; text-align: center; padding: 2rem 0; line-height: 1.7; }

.cart-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}

.cart-item-info { flex: 1; min-width: 0; }
.cart-item-code { display: block; font-size: .72rem; color: var(--muted); font-family: monospace; }
.cart-item-name { display: block; font-size: .875rem; font-weight: 500; color: var(--text); }
.cart-item-price { display: block; font-size: .82rem; font-weight: 600; color: var(--navy); margin-top: .15rem; }
.cart-item-price-req { display: block; font-size: .78rem; color: var(--muted); font-style: italic; }
.cart-item-remove {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  padding: .1rem .3rem;
  border-radius: 4px;
}
.cart-item-remove:hover { background: #fee2e2; color: var(--danger); }

.cart-drawer-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .625rem;
  background: #f9fafb;
}

.btn-outline-white {
  padding: .625rem;
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all .15s;
}
.btn-outline-white:hover { border-color: var(--navy); }

.btn-primary-white {
  display: block;
  padding: .75rem;
  background: var(--navy);
  color: #fff;
  border-radius: 7px;
  font-size: .95rem;
  font-weight: 600;
  text-align: center;
  transition: background .15s;
}
.btn-primary-white:hover { background: #0a4a70; text-decoration: none; }

/* ---- Pagina lista / form ---- */
.request-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}
@media (max-width: 700px) { .request-layout { grid-template-columns: 1fr; } }

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1.25rem;
  padding-bottom: .625rem;
  border-bottom: 2px solid var(--border);
}

.lista-item {
  display: flex;
  align-items: flex-start;
  gap: .875rem;
  padding: .75rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: .625rem;
}

.lista-num {
  width: 28px;
  height: 28px;
  background: var(--navy);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  flex-shrink: 0;
}

.lista-info { flex: 1; min-width: 0; }
.lista-code { font-size: .72rem; color: var(--muted); font-family: monospace; }
.lista-name { font-size: .9rem; font-weight: 500; }
.lista-price { font-size: .82rem; font-weight: 600; color: var(--navy); margin-top: .15rem; }
.lista-price-req { font-size: .78rem; color: var(--muted); font-style: italic; }

.lista-qty input {
  width: 60px;
  padding: .3rem .5rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  text-align: center;
  font-size: .875rem;
}

.lista-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: .2rem .4rem;
  border-radius: 4px;
}
.lista-remove:hover { background: #fee2e2; color: var(--danger); }

.request-form-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-bottom: 1rem;
}
.form-group label { font-size: .875rem; font-weight: 500; color: var(--text); }
.form-group input,
.form-group textarea {
  padding: .625rem .875rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(26,58,92,.1);
}
.form-group textarea { resize: vertical; min-height: 100px; }
.req { color: var(--danger); margin-left: 2px; }

.btn-primary {
  display: inline-block;
  padding: .75rem 1.5rem;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background .15s;
  text-decoration: none;
}
.btn-primary:hover { background: #0a4a70; text-decoration: none; }
.btn-full { width: 100%; display: block; }

.btn-outline {
  padding: .5rem 1rem;
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn-outline:hover { border-color: var(--navy); }

.btn-danger-outline {
  padding: .5rem 1rem;
  background: #fff;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 7px;
  font-size: .875rem;
  cursor: pointer;
  transition: all .15s;
}
.btn-danger-outline:hover { background: #fef2f2; }

.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: .875rem;
  margin-bottom: 1rem;
}

/* ---- Footer ---- */
.site-footer {
  background: var(--navy);
  color: rgba(255,255,255,.5);
  text-align: center;
  padding: 1.5rem 0;
  font-size: .82rem;
  margin-top: 3rem;
}

/* ---- Mobile: intestazione ----
   DEVE stare in fondo al file. La regola mobile di .btn-cart più in alto
   (riga ~94) è scritta PRIMA della regola base .btn-cart, che quindi la
   sovrascrive: su telefono il pulsante restava grande e finiva tagliato dal
   bordo destro. Qui, dopo la regola base, la correzione ha finalmente effetto. */
@media (max-width: 640px) {
  .header-inner { gap: .5rem; min-width: 0; }
  .header-inner > * { min-width: 0; }
  .logo { flex: 1 1 auto; min-width: 0; }
  .logo img { max-height: 30px; width: auto; max-width: 100%; }
  .logo a { font-size: 1.15rem; letter-spacing: 1px; }
  .header-actions { flex: 0 0 auto; }
  .btn-cart { padding: .4rem .7rem; font-size: .8rem; gap: .35rem; white-space: nowrap; }
  .cart-count { width: 20px; height: 20px; font-size: .72rem; }
}
