/* ============================================================
   Ennebi CRM — CrmStyle.css
   Design: Corporate elegance, navy + steel + accent orange
   ============================================================ */

/* Nasconde le freccine su/giù dagli input numerici */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
}

:root {
  --crm-primary:       #1a3a5c;
  --crm-primary-light: #1d5fa0;
  --crm-accent:        #e8590c;
  --crm-accent-light:  #f5884f;
  --crm-bg:            #f4f6f9;
  --crm-surface:       #ffffff;
  --crm-border:        #dde3ed;
  --crm-text:          #1c2b3a;
  --crm-muted:         #6b7c93;
  --crm-success:       #198754;
  --crm-warning:       #fd7e14;
  --crm-danger:        #dc3545;
  --crm-info:          #0ea5e9;
  --sidebar-w:         260px;
  --topbar-h:          64px;
  --radius:            12px;
  --radius-sm:         8px;
  --shadow:            0 2px 12px rgba(26,58,92,.10);
  --shadow-md:         0 4px 24px rgba(26,58,92,.14);
  --transition:        all .2s ease;
  --font-sans:         'DM Sans', system-ui, sans-serif;
  --font-serif:        'DM Serif Display', Georgia, serif;
}

/* ─── RESET / BASE ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  background: var(--crm-bg);
  color: var(--crm-text);
  margin: 0;
  font-size: .9375rem;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--crm-primary-light); text-decoration: none; }
a:hover { color: var(--crm-accent); }

/* ─── LAYOUT ────────────────────────────────────────────── */
.crm-sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--crm-primary);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  overflow-x: hidden;
}

.crm-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin .28s ease;
}

/* ─── SIDEBAR BRAND ────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  padding: 1.6rem 1.5rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  color: #fff;
  letter-spacing: -.5px;
  line-height: 1;
}
.sidebar-tag {
  font-size: .65rem;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,.45);
  font-weight: 500;
  padding: 2px 6px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 4px;
}

/* ─── SIDEBAR NAV ──────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 1.2rem .8rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-section-label {
  font-size: .7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  font-weight: 600;
  padding: .6rem .6rem .3rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.7);
  font-size: .875rem;
  font-weight: 400;
  transition: var(--transition);
  cursor: pointer;
  text-decoration: none;
}
.nav-item i { font-size: 1rem; width: 20px; text-align: center; }
.nav-item:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
  text-decoration: none;
}
.nav-item.active {
  background: var(--crm-accent);
  color: #fff;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(232,89,12,.35);
}
.nav-item.active i { color: #fff; }

/* ─── SIDEBAR FOOTER ───────────────────────────────────── */
.sidebar-footer {
  padding: 1rem .8rem;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.sidebar-user {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
}
.sidebar-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--crm-accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  flex-shrink: 0;
  text-transform: uppercase;
}
.sidebar-user-name {
  font-size: .82rem;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: .7rem;
  color: rgba(255,255,255,.4);
}
.btn-logout {
  color: rgba(255,255,255,.45);
  font-size: 1.1rem;
  padding: .3rem;
  border-radius: 6px;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-logout:hover { color: var(--crm-accent); background: rgba(255,255,255,.06); }

/* ─── TOPBAR ───────────────────────────────────────────── */
.crm-topbar {
  height: var(--topbar-h);
  background: var(--crm-surface);
  border-bottom: 1px solid var(--crm-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-left { display: flex; align-items: center; gap: .8rem; }
.topbar-page-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--crm-text);
}
.topbar-right { display: flex; align-items: center; gap: .5rem; }

.btn-hamburger {
  background: none; border: none;
  font-size: 1.3rem;
  color: var(--crm-muted);
  display: none;
  cursor: pointer;
  padding: .3rem .5rem;
  border-radius: 6px;
  transition: var(--transition);
}
.btn-hamburger:hover { color: var(--crm-primary); background: var(--crm-bg); }

.topbar-icon-btn {
  background: none; border: none;
  font-size: 1.15rem;
  color: var(--crm-muted);
  padding: .45rem .5rem;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
}
.topbar-icon-btn:hover { color: var(--crm-primary); background: var(--crm-bg); }

.topbar-avatar-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--crm-primary);
  color: #fff;
  border: none;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
  transition: var(--transition);
}
.topbar-avatar-btn:hover { background: var(--crm-accent); }

/* ─── NOTIFICHE ────────────────────────────────────────── */
.notif-badge {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--crm-accent);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.notif-panel {
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
  padding: 0;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius);
}
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--crm-border);
  font-weight: 600;
  font-size: .875rem;
  background: var(--crm-bg);
  position: sticky; top: 0;
}
.notif-list { }
.notif-item {
  display: flex; gap: .75rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--crm-border);
  transition: var(--transition);
  cursor: pointer;
}
.notif-item:hover { background: var(--crm-bg); }
.notif-item.unread { background: #eff6ff; }
.notif-item-icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--crm-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
}
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-size: .82rem; font-weight: 500; color: var(--crm-text); }
.notif-item-time { font-size: .72rem; color: var(--crm-muted); margin-top: 2px; }

/* ─── MAIN CONTENT ──────────────────────────────────────── */
.crm-content {
  flex: 1;
  padding: 1.75rem;
}

/* ─── CARDS ────────────────────────────────────────────── */
.crm-card {
  background: var(--crm-surface);
  border-radius: var(--radius);
  border: 1px solid var(--crm-border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.crm-card-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--crm-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--crm-surface);
}
.crm-card-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--crm-text);
  margin: 0;
}
.crm-card-body { padding: 1.4rem; }

/* ─── KPI CARDS ─────────────────────────────────────────── */
.kpi-card {
  background: var(--crm-surface);
  border-radius: var(--radius);
  border: 1px solid var(--crm-border);
  padding: 1.4rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.kpi-icon-blue   { background: #dbeafe; color: #1d4ed8; }
.kpi-icon-green  { background: #d1fae5; color: #065f46; }
.kpi-icon-orange { background: #ffedd5; color: #9a3412; }
.kpi-icon-purple { background: #ede9fe; color: #5b21b6; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-label { font-size: .78rem; color: var(--crm-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; margin-bottom: .2rem; }
.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--crm-text); line-height: 1; }
.kpi-delta { font-size: .78rem; margin-top: .35rem; }
.kpi-delta.up { color: var(--crm-success); }
.kpi-delta.down { color: var(--crm-danger); }

/* ─── TABLES ────────────────────────────────────────────── */
.crm-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--crm-border);
  box-shadow: var(--shadow);
}
.crm-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--crm-surface);
  font-size: .875rem;
}
.crm-table thead th {
  background: #f8fafc;
  color: var(--crm-muted);
  font-weight: 600;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: .8rem 1rem;
  border-bottom: 2px solid var(--crm-border);
  white-space: nowrap;
}
.crm-table tbody tr {
  border-bottom: 1px solid #f1f4f8;
  transition: var(--transition);
}
.crm-table tbody tr:last-child { border-bottom: none; }
.crm-table tbody tr:hover { background: #f8fafd; }
.crm-table td {
  padding: .75rem 1rem;
  vertical-align: middle;
  color: var(--crm-text);
}

/* ─── BADGES ────────────────────────────────────────────── */
.badge-stato {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: .25rem .65rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
}
.badge-lead     { background: #dbeafe; color: #1e40af; }
.badge-prospect { background: #ede9fe; color: #5b21b6; }
.badge-cliente  { background: #d1fae5; color: #065f46; }
.badge-alta     { background: #fee2e2; color: #991b1b; }
.badge-media    { background: #fef3c7; color: #92400e; }
.badge-bassa    { background: #f1f5f9; color: #475569; }

/* ─── KANBAN ─────────────────────────────────────────────── */
.kanban-board {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  align-items: flex-start;
}
.kanban-col {
  flex-shrink: 0;
  width: 190px;
  background: #f1f5f9;
  border-radius: var(--radius);
  padding: .5rem;
  min-height: 400px;
}
.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
  padding: 0 .15rem;
}
.kanban-col-title {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--crm-text);
  display: flex;
  align-items: center;
  gap: .3rem;
}
.kanban-col-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.kanban-count {
  font-size: .68rem;
  color: var(--crm-muted);
  background: rgba(0,0,0,.07);
  padding: 1px 6px;
  border-radius: 10px;
}
.kanban-cards { min-height: 60px; }
.kanban-card {
  background: var(--crm-surface);
  border-radius: var(--radius-sm);
  padding: .6rem .65rem;
  margin-bottom: .45rem;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  border: 1px solid var(--crm-border);
  transition: var(--transition);
  user-select: none;
}
.kanban-card:active { cursor: grabbing; opacity: .8; }
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kanban-card.dragging { opacity: .4; }
.kanban-card.drag-over { border: 2px dashed var(--crm-primary-light); }

.kanban-card-title {
  font-size: .8rem;
  font-weight: 600;
  color: var(--crm-text);
  margin-bottom: .25rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kanban-card-client {
  font-size: .72rem;
  color: var(--crm-muted);
  margin-bottom: .3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kanban-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .3rem;
}
.kanban-card-value {
  font-size: .73rem;
  font-weight: 700;
  color: var(--crm-primary);
}
.kanban-card-date {
  font-size: .68rem;
  color: var(--crm-muted);
  display: flex;
  align-items: center;
  gap: 2px;
}
.kanban-card-date.overdue { color: var(--crm-danger); }
.kanban-card-date.urgent  { color: var(--crm-warning); }

.kanban-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .4rem;
  padding-top: .35rem;
  border-top: 1px solid #f0f0f0;
}
.kanban-user-chip {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--crm-primary);
  color: #fff;
  font-size: .62rem;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  text-transform: uppercase;
}

/* ─── FORMS ──────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: .875rem; color: var(--crm-text); }
.form-control, .form-select {
  border-color: var(--crm-border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  transition: var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--crm-primary-light);
  box-shadow: 0 0 0 3px rgba(29,95,160,.12);
}
.input-group-text {
  background: #f8fafc;
  border-color: var(--crm-border);
  color: var(--crm-muted);
}

/* ─── BUTTONS ────────────────────────────────────────────── */
.btn-primary {
  background: var(--crm-primary);
  border-color: var(--crm-primary);
  font-weight: 500;
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--crm-primary-light);
  border-color: var(--crm-primary-light);
}
.btn-accent {
  background: var(--crm-accent);
  border-color: var(--crm-accent);
  color: #fff;
  font-weight: 500;
}
.btn-accent:hover { background: #c9470a; border-color: #c9470a; color: #fff; }
.btn-outline-primary { border-color: var(--crm-primary); color: var(--crm-primary); }
.btn-outline-primary:hover { background: var(--crm-primary); border-color: var(--crm-primary); }

/* ─── PAGE HEADER ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.page-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  color: var(--crm-primary);
  margin: 0;
  line-height: 1.1;
}
.page-subtitle {
  color: var(--crm-muted);
  font-size: .875rem;
  margin-top: .25rem;
}

/* ─── FILTER BAR ─────────────────────────────────────────── */
.filter-bar {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius);
  padding: .85rem 1.2rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.filter-bar .form-control,
.filter-bar .form-select {
  flex: 1;
  min-width: 140px;
  max-width: 220px;
  font-size: .84rem;
  padding: .42rem .7rem;
}
.active-filters {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  margin-bottom: .8rem;
}
.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: #dbeafe;
  color: #1e40af;
  padding: .22rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 500;
}
.filter-tag button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: .8rem;
  line-height: 1;
}

/* ─── OFFCANVAS COME MODAL CENTRATO ──────────────────────── */
.offcanvas.offcanvas-end {
  position: fixed !important;
  top: 4vh !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  height: auto !important;
  max-height: 92vh !important;
  border-radius: 12px !important;
  border: none !important;
  box-shadow: 0 24px 64px rgba(0,0,0,.35) !important;
  transform: translateX(-50%) scale(.96) !important;
  opacity: 0 !important;
  visibility: hidden !important;
  transition: transform .22s ease, opacity .2s ease !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}
.offcanvas.offcanvas-end.show {
  transform: translateX(-50%) scale(1) !important;
  opacity: 1 !important;
  visibility: visible !important;
}
.offcanvas-header {
  background: var(--crm-primary);
  color: #fff;
  padding: 1.1rem 1.4rem;
  border-radius: 12px 12px 0 0;
  position: sticky;
  top: 0;
  z-index: 1;
}
.offcanvas-title { font-weight: 600; }
.offcanvas-header .btn-close { filter: invert(1) brightness(2); }
.btn-close-white { filter: invert(1) brightness(2); }

.modal-header { background: var(--crm-primary); color: #fff; }
.modal-title { font-weight: 600; }
.modal-header .btn-close { filter: invert(1) brightness(2); }

/* ─── BTN-CRM-PRIMARY ─────────────────────────────────────── */
.btn-crm-primary {
  background-color: var(--crm-primary);
  border-color:     var(--crm-primary);
  color:            #fff;
  font-weight:      600;
}
.btn-crm-primary:hover,
.btn-crm-primary:focus {
  background-color: var(--crm-accent);
  border-color:     var(--crm-accent);
  color:            #fff;
}
.btn-crm-primary:active {
  background-color: #c44a07;
  border-color:     #c44a07;
  color:            #fff;
}
.btn-crm-primary:disabled {
  background-color: var(--crm-primary);
  border-color:     var(--crm-primary);
  opacity:          .6;
}
.modal-content { border-radius: var(--radius); overflow: visible; box-shadow: var(--shadow-md); border: none; }
.modal-content .modal-header { border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.modal-content .modal-footer { border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }

/* ─── TIMELINE NOTA ──────────────────────────────────────── */
.timeline {
  position: relative;
  padding-left: 2.5rem;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 12px; top: 0; bottom: 0;
  width: 2px;
  background: var(--crm-border);
  border-radius: 1px;
}
.timeline-item {
  position: relative;
  margin-bottom: 1.25rem;
}
.timeline-dot {
  position: absolute;
  left: -2rem;
  top: .2rem;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--crm-surface);
  border: 2px solid var(--crm-border);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem;
  color: var(--crm-muted);
}
.timeline-dot.tipo-telefonata { border-color: #0ea5e9; color: #0ea5e9; }
.timeline-dot.tipo-email      { border-color: #8b5cf6; color: #8b5cf6; }
.timeline-dot.tipo-riunione   { border-color: #f59e0b; color: #f59e0b; }
.timeline-dot.tipo-visita     { border-color: #10b981; color: #10b981; }
.timeline-dot.tipo-promemoria { border-color: #ef4444; color: #ef4444; }
.timeline-dot.tipo-sistema    { border-color: var(--crm-border); color: var(--crm-muted); background: #f8fafc; }
.timeline-content {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem;
  box-shadow: var(--shadow);
}
.timeline-meta {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: .4rem;
}
.timeline-author { font-size: .78rem; font-weight: 600; color: var(--crm-text); }
.timeline-time   { font-size: .72rem; color: var(--crm-muted); }
.timeline-tipo   { font-size: .7rem; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; }
.timeline-text   { font-size: .875rem; color: var(--crm-text); white-space: pre-wrap; }

/* ─── PREVENTIVO RIGHE ───────────────────────────────────── */
.righe-preventivo { width: 100%; }
.riga-prev {
  display: grid;
  grid-template-columns: 1fr 80px 110px 80px 90px 108px;
  gap: .5rem;
  align-items: center;
  padding: .5rem 0;
  border-bottom: 1px solid #f0f3f7;
}
/* Colonna azioni: grip + camera + catalogo + delete */
.riga-prev-actions {
  display: flex;
  gap: .2rem;
  align-items: center;
  justify-content: flex-end;
}
.riga-prev:last-child { border-bottom: none; }
.riga-prev-head {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--crm-muted);
  letter-spacing: .5px;
}
.riga-drag-handle {
  cursor: grab;
  color: var(--crm-muted);
  padding: .2rem .15rem;
  display: flex;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  opacity: .5;
  transition: opacity .15s;
}
.riga-drag-handle:hover  { opacity: 1; }
.riga-drag-handle:active { cursor: grabbing; }
/* Riga di solo testo: input span su tutte le colonne centrali */
.riga-testo-input { grid-column: 1 / 6; }
/* Feedback drag-and-drop */
.riga-prev.dragging  { opacity: .35; }
.riga-prev.drag-over { border-top: 2px solid var(--crm-primary); margin-top: -1px; }
.tag-riservata {
  font-size: .65rem;
  background: #fef3c7;
  color: #92400e;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}
.riga-total-display { font-weight: 700; color: var(--crm-primary); }

/* ─── AUTOCOMPLETE ───────────────────────────────────────── */
.autocomplete-list {
  position: fixed;
  z-index: 9999;
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
}
.autocomplete-item {
  padding: .6rem 1rem;
  cursor: pointer;
  font-size: .875rem;
  border-bottom: 1px solid #f5f5f5;
  transition: background .15s;
}
.autocomplete-item:hover { background: #f0f6ff; }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item .item-price { float: right; color: var(--crm-muted); font-size: .78rem; }

/* ─── DRAG & DROP KANBAN ─────────────────────────────────── */
.kanban-col.drag-target { background: #e8f0fe; border: 2px dashed var(--crm-primary-light); }
.kanban-ghost { opacity: .3; background: var(--crm-bg) !important; }

/* ─── EMPTY STATE ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
}
.empty-state-icon {
  font-size: 3rem;
  color: var(--crm-border);
  margin-bottom: 1rem;
}
.empty-state-title { font-weight: 600; color: var(--crm-muted); margin-bottom: .5rem; }
.empty-state-text  { color: var(--crm-muted); font-size: .875rem; }

/* ─── LOADING SPINNER ────────────────────────────────────── */
.crm-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
}
.spin-ring {
  width: 40px; height: 40px;
  border: 3px solid var(--crm-border);
  border-top-color: var(--crm-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── ACCETTAZIONE PREVENTIVO (pubblica) ─────────────────── */
.accept-page {
  min-height: 100vh;
  background: var(--crm-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.accept-card {
  background: var(--crm-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 680px;
  width: 100%;
  overflow: hidden;
}
.accept-header {
  background: var(--crm-primary);
  color: #fff;
  padding: 2rem;
  text-align: center;
}
.accept-header h1 { font-family: var(--font-serif); font-size: 2rem; margin: 0; }
.accept-body { padding: 2rem; }

/* ─── RESPONSIVE ─────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1039;
}

@media (max-width: 991px) {
  .crm-sidebar { transform: translateX(-100%); }
  .crm-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .crm-main { margin-left: 0; }
  .btn-hamburger { display: flex; }
  .sidebar-overlay.open { display: block; }
  .crm-content { padding: 1rem; }
}

@media (max-width: 576px) {
  .page-header { flex-direction: column; }
  .kanban-board { padding-bottom: 1rem; }
  .filter-bar { gap: .4rem; }
  .filter-bar .form-control,
  .filter-bar .form-select { max-width: 100%; }

  /* ── Vista mobile card per tabelle contatti / trattative ── */
  .crm-table-mobile thead { display: none; }
  .crm-table-mobile tbody tr {
    display: block;
    background: #fff;
    border: .5px solid var(--crm-border);
    border-radius: var(--radius-sm);
    margin-bottom: .75rem;
    padding: .75rem 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
  }
  .crm-table-mobile tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .3rem 0;
    border: none;
    font-size: .85rem;
  }
  .crm-table-mobile tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--crm-muted);
    font-size: .78rem;
    flex-shrink: 0;
    margin-right: 1rem;
  }
  .crm-table-mobile tbody td:first-child {
    font-size: .95rem;
    font-weight: 700;
    color: var(--crm-primary);
    border-bottom: .5px solid var(--crm-border);
    padding-bottom: .5rem;
    margin-bottom: .25rem;
  }
  .crm-table-mobile tbody td:first-child::before { display: none; }
  .crm-table-mobile tbody td.td-actions {
    justify-content: flex-end;
    padding-top: .5rem;
    border-top: .5px solid var(--crm-border);
    margin-top: .25rem;
  }
  .crm-table-mobile tbody td.td-actions::before { display: none; }

  /* Nascondi colonne secondarie su mobile */
  .mobile-hide { display: none !important; }

  /* KPI card a piena larghezza su mobile */
  .kpi-card { flex-direction: row; gap: 1rem; }
  .kpi-value { font-size: 1.4rem; }
}

/* ─── SCROLLBAR ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--crm-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--crm-muted); }

/* ─── TOAST NOTIFICHE ────────────────────────────────────── */
.crm-toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.crm-toast {
  background: var(--crm-primary);
  color: #fff;
  padding: .75rem 1.2rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: .875rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  animation: slideInRight .25s ease;
  max-width: 340px;
}
.crm-toast.success { background: var(--crm-success); }
.crm-toast.error   { background: var(--crm-danger); }
.crm-toast.warning { background: var(--crm-warning); }
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ─── PREVENTIVI: RESPONSIVE OFFCANVAS + RIGHE ───────────────
   breakpoint tablet (≤767px): offcanvas piena larghezza          */
@media (max-width: 767px) {
  /* Offcanvas occupa tutto lo schermo */
  .offcanvas.offcanvas-end { width: 100vw !important; }

  /* Nav-tabs orizzontali scrollabili senza testo spezzato */
  .offcanvas .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .offcanvas .nav-tabs::-webkit-scrollbar { display: none; }
  .offcanvas .nav-tabs .nav-link {
    white-space: nowrap;
    padding: .45rem .8rem;
    font-size: .82rem;
  }

  /* Footer azioni: bottoni si espandono equamente */
  .offcanvas .border-top.d-flex { flex-wrap: nowrap; gap: .4rem; }
  .offcanvas .border-top.d-flex .btn {
    flex: 1;
    min-width: 0;
    font-size: .78rem;
    padding: .45rem .3rem;
  }
  .offcanvas .border-top.d-flex .btn i { display: none; }
}

/* breakpoint mobile (≤575px): layout righe e filtri              */
@media (max-width: 575px) {
  /* Pagina header: bottone "Nuovo" a piena larghezza */
  .page-header { align-items: stretch !important; }
  .page-header .btn { width: 100%; }

  /* Filter-bar: colonna singola */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-bar .form-control,
  .filter-bar .form-select { max-width: 100% !important; width: 100% !important; }

  /* Tabella preventivi: stile card mobile */
  .crm-table-wrap { overflow-x: auto; }

  /* Righe offerta: descrizione sopra, numeri sotto */
  .riga-prev-head { display: none; }
  .riga-prev {
    grid-template-columns: 1fr 1fr 1fr 108px;
    grid-template-rows: auto auto;
    gap: .4rem;
    padding: .6rem .3rem;
  }
  .riga-prev > div:first-child { grid-column: 1 / -1; } /* descrizione full-width */
  .riga-testo-input { grid-column: 1 / -2; }
  .riga-prev > div:nth-child(5) { grid-column: 1 / 3; }
  .riga-prev-actions { grid-column: 4 / 5; align-self: start; justify-content: flex-end; flex-wrap: wrap; }

  /* Template cards: 3 per riga su mobile */
  .template-selector { justify-content: flex-start; }
  .tmpl-card { min-width: 64px; }

  /* Modal: piena larghezza su mobile */
  .modal-dialog { margin: .5rem; }
  .modal-lg { max-width: calc(100vw - 1rem); }
}
