/* ============================================================
   SNS Hub — Design System (ported from SNS_BP)
   Palette: Navy/Gold | Font: system-ui
   ============================================================ */

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

:root {
  --navy-900: #1a2543;
  --navy-800: #243156;
  --navy-700: #2f3f6a;
  --navy-600: #3d4f80;
  --gold:     #c9a961;
  --gold-lt:  #e8d49a;
  --gold-dk:  #b08f4a;
  --gold-bg:  #f9f3e3;
  --green:    #047857;
  --green-bg: #ecfdf5;
  --red:      #dc2626;
  --red-bg:   #fef2f2;
  --red-bd:   #fecaca;
  --amber:    #d97706;
  --amber-bg: #fffbeb;
  --gray-50:  #f4f6fa;
  --gray-100: #eef1f6;
  --gray-200: #e5e8ee;
  --gray-300: #d4d9e2;
  --gray-400: #9aa3b2;
  --gray-500: #6b7382;
  --gray-700: #3a4257;
  --white:    #ffffff;
  --shadow-sm: 0 1px 2px rgba(20,30,55,.04), 0 1px 1px rgba(20,30,55,.03);
  --shadow-md: 0 4px 16px rgba(20,30,55,.06), 0 1px 3px rgba(20,30,55,.04);
  --shadow-lg: 0 10px 30px rgba(20,30,55,.08), 0 4px 8px rgba(20,30,55,.04);
  --radius:    10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --sidebar-w: 220px;
  --sidebar-cw: 68px;
  --topbar-h:  56px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: #111827;
  background: var(--gray-50);
  line-height: 1.45;
}

/* =================== LOGIN =================== */
.login-overlay {
  position: fixed; inset: 0;
  background: var(--navy-900);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.login-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 8px;
}
.login-logo img { width: 48px; height: 48px; object-fit: contain; }
.login-brand-name {
  font-size: 18px; font-weight: 700;
  color: var(--navy-900); letter-spacing: -.3px;
}
.login-brand-sub {
  font-size: 12px; color: var(--gold-dk);
  font-weight: 500; letter-spacing: .08em; text-transform: uppercase;
}
/* legacy login form classes */
.login-subtitle { color: var(--gray-500); font-size: 13px; margin-bottom: 24px; }
.logo-sns { color: var(--navy-900); font-size: 2rem; font-weight: 700; }
.logo-hub { color: var(--gold); font-size: 2rem; font-weight: 700; }

.form-field { margin-bottom: 16px; }
.form-field label, .form-group label {
  display: block; font-weight: 500; font-size: 12.5px;
  color: var(--gray-700); margin-bottom: 5px;
}
.form-field input, .form-field select, .form-field textarea,
.form-group input {
  width: 100%; height: 36px; border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm); padding: 0 12px;
  background: var(--white); font-family: inherit; font-size: 13px;
  color: #111; transition: border-color .15s, box-shadow .15s;
}
.form-field textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus,
.form-group input:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,169,97,.18);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { margin-bottom: 16px; }
.login-error {
  color: var(--red); font-size: 13px; margin-bottom: 12px;
  padding: 8px 12px; background: var(--red-bg); border-radius: 6px;
}

/* =================== APP LAYOUT =================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; transition: grid-template-columns .22s ease; }

/* =================== SIDEBAR =================== */
.sidebar {
  background: var(--navy-900);
  color: #cbd2dd;
  padding: 18px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow: hidden;
}
.sidebar-head {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 2px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 14px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0;
  text-decoration: none;
}
.sidebar-collapse {
  background: none; border: none; cursor: pointer;
  color: var(--gold); flex-shrink: 0;
  width: 30px; height: 30px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, transform .25s ease;
}
.sidebar-collapse:hover { background: rgba(201,169,97,.15); color: var(--gold-lt); }
.sidebar-collapse svg { width: 18px; height: 18px; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; }
.brand-name { color: #fff; font-weight: 700; font-size: 14px; line-height: 1.1; letter-spacing: .04em; }
.brand-sub  { color: var(--gold-lt); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; margin-top: 2px; }

/* Legacy sidebar logo (original HTML) */
.sidebar-logo {
  padding: 4px 6px 22px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 14px;
  font-size: 1.4rem; font-weight: 700;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; padding: 0; }
.nav-section-label {
  color: #6b7382; font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; padding: 14px 10px 6px;
}
.nav-item {
  color: #cbd2dd; text-decoration: none;
  padding: 9px 10px; border-radius: 6px;
  font-size: 13.5px; display: flex; align-items: center; gap: 10px;
  transition: background .12s, color .12s;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(201,169,97,.14);
  color: #fff;
  border-left: 3px solid var(--gold);
  padding-left: 7px;
}
.nav-icon {
  width: 22px; height: 22px; flex-shrink: 0;
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  transition: color .12s;
}
.nav-icon svg { width: 20px; height: 20px; }
.nav-item:hover .nav-icon { color: var(--gold-lt); }
.nav-item.active .nav-icon { color: var(--gold-lt); }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-ext-arrow { margin-left: auto; font-size: 10px; opacity: .5; }

.sidebar-footer {
  margin-top: auto; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 8px;
}
/* Support both old .user-badge and new .user-info-row */
.user-badge, .user-info-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(201,169,97,.25); color: var(--gold-lt);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-info { min-width: 0; overflow: hidden; }
.user-name { font-weight: 600; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: #6b7382; font-size: 11px; text-transform: capitalize; }
.btn-logout {
  background: none; border: none; color: #6b7382; cursor: pointer;
  padding: 6px; border-radius: 6px; display: flex; align-items: center;
  transition: color .15s, background .15s; flex-shrink: 0;
  font-size: 16px;
}
.btn-logout:hover { color: var(--red); background: rgba(220,38,38,.12); }

/* =================== MAIN WRAP =================== */
.main-wrap, .main {
  display: flex; flex-direction: column; min-height: 100vh; overflow: hidden;
}
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  box-shadow: 0 1px 3px rgba(20,30,55,.04);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px; flex-shrink: 0;
}
.topbar-title { color: var(--navy-900); font-weight: 600; font-size: 16px; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }
.menu-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--gray-500); padding: 4px; border-radius: 6px;
  display: flex; transition: color .15s;
}
.menu-toggle:hover { color: var(--navy-900); }

.view-container { flex: 1; overflow-y: auto; padding: 20px; }

/* =================== BUTTONS =================== */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost, .btn-gold, .btn-dark {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer;
  transition: all .15s; white-space: nowrap; text-decoration: none;
}
.btn-primary { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
.btn-primary:hover:not(:disabled) { background: var(--navy-800); }
.btn-secondary { background: var(--gray-100); color: #111827; border-color: var(--gray-200); }
.btn-secondary:hover:not(:disabled) { border-color: var(--gold); color: var(--gold-dk); }
.btn-ghost { background: transparent; color: var(--navy-900); border-color: var(--gray-200); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-300); }
.btn-danger { background: var(--white); color: var(--red); border-color: var(--red-bd); }
.btn-danger:hover:not(:disabled) { background: var(--red-bg); }
.btn-gold { background: var(--gold); color: #fff; border-color: var(--gold-dk); }
.btn-gold:hover:not(:disabled) { background: var(--gold-dk); }
.btn-dark { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
.btn-full { width: 100%; padding: 10px; font-size: 14px; }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 5px; }
.btn-icon { padding: 6px; border-radius: 6px; }
.btn-active { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
button:disabled, .btn-primary:disabled { opacity: .55; cursor: not-allowed; }

/* =================== CARDS =================== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin-bottom: 16px;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600; font-size: 13.5px;
  color: var(--navy-900);
  display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 20px; }

/* card-header colour variants */
.hc-navy  { background: var(--navy-900); color: #fff; border-bottom: none; }
.hc-blue  { background: var(--navy-700); color: #fff; border-bottom: none; }
.hc-teal  { background: #0d9488;         color: #fff; border-bottom: none; }
.hc-green { background: var(--green);    color: #fff; border-bottom: none; }
.hc-amber { background: var(--amber);    color: #fff; border-bottom: none; }
.hc-red   { background: var(--red);      color: #fff; border-bottom: none; }
.hc-pink  { background: #db2777;         color: #fff; border-bottom: none; }
.hc-gray  { background: var(--gray-500); color: #fff; border-bottom: none; }
.hc-gold  { background: var(--gold);     color: #111; border-bottom: none; }

/* =================== KPI CARDS =================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.kpi-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 20px 24px;
  border-top: 3px solid var(--navy-700);
}
.kpi-card.kc-teal   { border-top-color: #0d9488; }
.kpi-card.kc-green  { border-top-color: var(--green); }
.kpi-card.kc-amber  { border-top-color: var(--amber); }
.kpi-card.kc-red    { border-top-color: var(--red); }
.kpi-card.kc-pink   { border-top-color: #db2777; }
.kpi-card.kc-gold   { border-top-color: var(--gold); }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--navy-900); line-height: 1.1; }
.kpi-label {
  font-size: 12px; color: var(--gray-500); font-weight: 500;
  margin-top: 4px; text-transform: uppercase; letter-spacing: .04em;
}
.kpi-sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* =================== BADGES / FLAGS =================== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.fl-red    { background: var(--red-bg); color: var(--red); }
.fl-yellow { background: var(--amber-bg); color: var(--amber); }
.fl-green  { background: var(--green-bg); color: var(--green); }
.fl-blue   { background: rgba(26,37,67,.08); color: var(--navy-700); }
.fl-gray   { background: var(--gray-100); color: var(--gray-500); }
.fl-teal   { background: #f0fdfa; color: #0d9488; }
.fl-pink   { background: #fdf2f8; color: #db2777; }

/* SNS_BP tag classes */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.tag-gold   { background: var(--gold-bg); color: var(--gold-dk); }
.tag-navy   { background: var(--navy-900); color: #fff; }
.tag-gray   { background: var(--gray-100); color: var(--gray-500); }
.tag-green  { background: var(--green-bg); color: var(--green); }
.tag-red    { background: var(--red-bg); color: var(--red); }
.tag-amber  { background: var(--amber-bg); color: var(--amber); }

/* =================== KANBAN =================== */
.kanban-board {
  display: flex; gap: 14px;
  overflow-x: auto; padding-bottom: 12px;
  align-items: flex-start;
  min-height: calc(100vh - 160px);
}
.kanban-col {
  min-width: 240px; max-width: 260px; flex-shrink: 0;
  background: var(--gray-50); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
.kanban-col-header {
  background: var(--navy-900); color: #fff;
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 13px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.kanban-col-count {
  background: rgba(255,255,255,.2); color: #fff;
  border-radius: 20px; padding: 1px 8px; font-size: 11px; font-weight: 700;
}
.kanban-cards {
  padding: 8px; display: flex; flex-direction: column; gap: 8px;
  min-height: 60px; flex: 1;
}
.kanban-cards.drag-over { background: rgba(201,169,97,.08); border-radius: 6px; }
.kanban-card {
  background: var(--white); border-radius: 8px;
  padding: 12px; box-shadow: 0 2px 8px rgba(20,30,55,.07);
  cursor: grab; transition: box-shadow .15s, transform .1s;
  border-left: 3px solid var(--navy-700);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: .5; transform: rotate(2deg); }
.kanban-card.drag-target { box-shadow: 0 0 0 2px var(--gold); }
.kanban-card.priority-alta  { border-left-color: var(--red); }
.kanban-card.priority-media { border-left-color: var(--gold); }
.kanban-card.priority-bassa { border-left-color: var(--green); }
.kanban-card-title { font-weight: 600; font-size: 13px; color: var(--navy-900); margin-bottom: 4px; }
.kanban-card-sub   { font-size: 12px; color: var(--gray-500); }
.kanban-card-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.kanban-add-btn {
  margin: 8px; background: none; border: 1.5px dashed var(--gray-200);
  border-radius: 8px; padding: 8px; font-size: 13px; color: var(--gray-500);
  cursor: pointer; width: calc(100% - 16px); text-align: center;
  transition: all .15s;
}
.kanban-add-btn:hover { border-color: var(--gold); color: var(--gold-dk); background: var(--gold-bg); }

/* =================== TABLES =================== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
thead th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 600; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 2px solid var(--gray-200); background: var(--gray-50);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); font-size: 13.5px; }
tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

/* =================== FILTER BAR =================== */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 12px 16px; background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}
.filter-bar input, .filter-bar select {
  padding: 7px 12px; border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm); font-family: inherit; font-size: 13px;
  color: #111; background: var(--white);
}
.filter-bar input:focus, .filter-bar select:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,169,97,.18);
}
.filter-bar input[type="text"] { min-width: 200px; }

/* =================== PAGINATION =================== */
.pagination {
  display: flex; gap: 6px; align-items: center;
  padding: 12px 16px; justify-content: flex-end;
}
.page-btn {
  padding: 5px 12px; border-radius: 6px;
  border: 1px solid var(--gray-200); background: var(--white);
  font-family: inherit; font-size: 13px; cursor: pointer; transition: all .15s;
}
.page-btn.active { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
.page-btn:hover:not(.active) { background: var(--gray-50); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* =================== MODAL =================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,41,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 900; padding: 20px;
}
.modal-content {
  background: var(--white); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-weight: 700; font-size: 16px; color: var(--navy-900); }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); font-size: 22px; line-height: 1;
  border-radius: 6px; padding: 2px 6px; transition: color .15s;
}
.modal-close:hover { color: #111; }
.modal-body { padding: 20px 22px; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--gray-100);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* =================== TOAST =================== */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13.5px; font-weight: 500; color: var(--white);
  box-shadow: var(--shadow-md);
  animation: slideIn .2s ease; max-width: 320px;
}
.toast-success { background: var(--green); }
.toast-error   { background: var(--red); }
.toast-info    { background: var(--navy-900); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* =================== LOADING / SPINNER =================== */
.loading-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 60px;
  color: var(--gray-500);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--navy-900);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =================== EMPTY STATE =================== */
.empty-state {
  text-align: center; padding: 48px 20px;
  background: var(--white); border: 2px dashed var(--gray-200);
  border-radius: var(--radius-lg); color: var(--gray-500);
}
.empty-state h3 { font-size: 16px; color: var(--navy-900); margin-bottom: 8px; }
.empty-state p  { font-size: 13px; margin-bottom: 20px; }

/* =================== PIPELINE BAR CHART =================== */
.pipeline-chart { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.pipeline-row { display: flex; align-items: center; gap: 10px; }
.pipeline-label { font-size: 12px; color: var(--gray-500); width: 120px; text-align: right; flex-shrink: 0; }
.pipeline-bar-wrap { flex: 1; background: var(--gray-200); border-radius: 4px; height: 18px; overflow: hidden; }
.pipeline-bar { height: 100%; background: var(--navy-700); border-radius: 4px; transition: width .5s ease; min-width: 4px; }
.pipeline-bar.stato-aggiudicato { background: var(--green); }
.pipeline-bar.stato-in_offerta  { background: var(--gold); }
.pipeline-count { font-size: 12px; font-weight: 600; color: var(--gray-700); width: 28px; }

/* =================== CHAT / AUTOMAZIONI =================== */
.chat-input-wrap {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 14px 16px; border-top: 1px solid var(--gray-200);
}
.chat-input-wrap textarea {
  flex: 1; resize: none; min-height: 60px; max-height: 200px;
  border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: inherit; font-size: 14px;
}
.chat-input-wrap textarea:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,169,97,.18);
}
.chat-messages { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg-out, .chat-msg-in {
  max-width: 75%; padding: 10px 14px; border-radius: 12px;
  font-size: 13.5px; line-height: 1.5;
}
.chat-msg-out { background: var(--navy-900); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg-in  { background: var(--gray-100); color: #111827; align-self: flex-start; border-bottom-left-radius: 4px; }

/* =================== SECTION HEADER =================== */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 18px; font-weight: 700; color: var(--navy-900); }
.section-sub   { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* =================== DETAIL PANEL =================== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-field dt {
  font-size: 11px; font-weight: 600; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px;
}
.detail-field dd { font-size: 14px; color: #111827; }

/* =================== ALERT =================== */
.alert {
  padding: 11px 13px; border-radius: 8px; font-size: 12.5px;
  display: flex; gap: 9px; align-items: flex-start; margin-bottom: 14px;
}
.alert-info    { background: #f0f6ff; border: 1px solid #d6e6ff; color: #1e3a5f; }
.alert-warn    { background: var(--amber-bg); border: 1px solid #fde68a; color: #78350f; }
.alert-error   { background: var(--red-bg); border: 1px solid var(--red-bd); color: #7f1d1d; }
.alert-success { background: var(--green-bg); border: 1px solid #a7f3d0; color: #064e3b; }

/* =================== UTILITIES =================== */
.muted   { color: var(--gray-500); }
.nowrap  { white-space: nowrap; }
.right   { text-align: right; }
.center  { text-align: center; }
.hide    { display: none !important; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 10px; }
.mt-3 { margin-top: 16px; } .mt-4 { margin-top: 22px; }

/* =================== RESPONSIVE =================== */
@media (max-width: 768px) {
  .app { display: flex; }
  .sidebar {
    position: fixed; left: -220px; z-index: 200;
    width: 220px; transition: left .25s; height: 100vh;
  }
  .sidebar.open { left: 0; }
  .sidebar-collapse { display: none; }
  .main-wrap, .main { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
/* =================== SIDEBAR COLLAPSED (desktop) =================== */
@media (min-width: 769px) {
  .app.collapsed { grid-template-columns: var(--sidebar-cw) 1fr; }
  .app.collapsed .sidebar { padding-left: 8px; padding-right: 8px; }

  /* Header: logo + chevron centrati in colonna */
  .app.collapsed .sidebar-head { flex-direction: column; gap: 12px; padding-bottom: 14px; }
  .app.collapsed .brand { justify-content: center; gap: 0; }
  .app.collapsed .brand-text { display: none; }
  .app.collapsed .sidebar-collapse { transform: rotate(180deg); }

  /* Voci: solo icona, centrata */
  .app.collapsed .nav-label,
  .app.collapsed .nav-ext-arrow { display: none; }
  .app.collapsed .nav-section-label {
    text-indent: -9999px; overflow: hidden;
    padding: 8px 0 4px; height: 14px;
  }
  .app.collapsed .nav-section-label::after {
    content: ""; display: block; text-indent: 0;
    width: 22px; height: 1px; margin: 6px auto 0;
    background: rgba(255,255,255,.1);
  }
  .app.collapsed .nav-item {
    justify-content: center; gap: 0; padding: 11px 0;
  }
  .app.collapsed .nav-item.active {
    border-left: 0; padding-left: 0;
    border-radius: 8px;
    background: rgba(201,169,97,.16);
  }

  /* Footer: avatar + logout centrati in colonna */
  .app.collapsed .sidebar-footer { flex-direction: column; gap: 10px; }
  .app.collapsed .user-meta { display: none; }
  .app.collapsed .user-info-row { justify-content: center; flex: none; }
}

/* =================== ADMIN-ONLY =================== */
.admin-only { display: flex; }
body.role-consulente .admin-only { display: none; }


/* ═══════════════════════════════════════════
   IMMOBILI — Layout dashboard-annunci style
   ═══════════════════════════════════════════ */

/* Layout principale 3 colonne */
.imm-layout {
  display: grid;
  grid-template-columns: 220px 1fr 0px;
  gap: 0;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
  transition: grid-template-columns .25s ease;
}
.imm-layout.detail-open {
  grid-template-columns: 220px 1fr 400px;
}

/* Filtri sinistra */
.imm-filters {
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.imm-filters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--gray-200);
}
.filter-group { margin-bottom: 12px; }
.filter-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 5px;
}
.filter-input {
  width: 100%;
  padding: 7px 10px;
  border: 1.5px solid var(--gray-200);
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  color: var(--navy-900);
  background: var(--white);
  transition: border-color .15s;
  box-sizing: border-box;
}
.filter-input:focus { outline: none; border-color: var(--navy-600); }
.filter-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--navy-900);
  cursor: pointer;
  margin-bottom: 8px;
}
.filter-check input[type=checkbox] { accent-color: var(--navy-900); width: 15px; height: 15px; }

/* Area risultati */
.imm-results-wrap {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.imm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  padding: 16px;
  align-content: start;
}

/* Card immobile */
.imm-card {
  background: var(--white);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 14px;
  cursor: pointer;
  transition: box-shadow .15s, transform .1s, border-color .15s;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.imm-card:hover {
  box-shadow: 0 6px 24px rgba(20,30,55,.13);
  transform: translateY(-1px);
}
.imm-card--selected {
  border-color: var(--navy-900);
  box-shadow: 0 0 0 3px rgba(26,37,67,.12);
}
.imm-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.imm-card-location strong { font-size: 14px; color: var(--navy-900); display: block; }
.imm-card-prov { font-size: 11px; color: var(--gray-500); }
.imm-card-address {
  font-size: 12px;
  color: var(--navy-900);
  margin: 2px 0 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.imm-card-cat {
  font-size: 12px;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.imm-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  flex-wrap: wrap;
  gap: 4px;
}
.imm-card-price { font-size: 14px; font-weight: 700; color: var(--navy-900); }
.imm-card-date { font-size: 11px; color: var(--gray-500); display: flex; align-items: center; gap: 4px; }
.imm-card-trib { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

/* Paginazione */
.imm-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--gray-100);
  margin-top: auto;
}

/* Pannello dettaglio destra */
.imm-detail {
  background: var(--white);
  border-left: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.imm-layout:not(.detail-open) .imm-detail {
  display: none;
}
.imm-detail-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--gray-50);
  flex-shrink: 0;
}
.imm-detail-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--navy-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.imm-detail-tabs {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  background: var(--white);
  flex-shrink: 0;
}
.imm-tab {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s;
}
.imm-tab:hover { color: var(--navy-900); }
.imm-tab.active { color: var(--navy-900); border-bottom-color: var(--gold); font-weight: 600; }
.imm-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
}

/* Campi dettaglio */
.detail-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.detail-field dt {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 2px;
}
.detail-field dd { font-size: 13.5px; color: var(--navy-900); }
.detail-section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--gray-100); }
.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

/* ===== DATI STRUTTURATI PERIZIA (Track 3 — backport dashboard-annunci) ===== */
.ds-section .ds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px 14px;
  margin-bottom: 4px;
}
.ds-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--gray-50);
  border: 1px solid var(--gray-100);
  border-radius: 8px;
  padding: 7px 10px;
}
.ds-k {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.ds-v { font-size: 14px; color: var(--navy-900); }
.ds-v.ds-strong { font-weight: 700; font-size: 15px; }
.ds-sub { margin-top: 12px; }
.ds-sub-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}
.ds-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gold-dk);
  background: var(--gold-bg);
  border: 1px solid var(--gold-lt);
  border-radius: 14px;
  padding: 3px 10px;
}
.ds-badge em { font-style: normal; font-weight: 500; color: var(--gray-700); }
.ds-piani { display: flex; flex-direction: column; gap: 8px; }
.ds-piano {
  border-left: 3px solid var(--gold);
  background: var(--gray-50);
  border-radius: 0 8px 8px 0;
  padding: 8px 12px;
}
.ds-piano-nome { font-size: 13px; font-weight: 700; color: var(--navy-900); }
.ds-piano-vani { margin: 4px 0 0; padding-left: 18px; }
.ds-piano-vani li { font-size: 12.5px; color: var(--gray-700); line-height: 1.5; }
.ds-note { font-size: 12.5px; color: var(--gray-700); margin: 2px 0; }

/* CRM rows */
.crm-section { margin-bottom: 16px; }
.crm-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--gray-100);
}
.crm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--gray-100);
  gap: 8px;
}
.crm-row:last-child { border-bottom: none; }
.crm-row-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crm-row-label {
  font-size: 13px;
  color: var(--navy-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-row-date { font-size: 11px; color: var(--gray-500); flex-shrink: 0; }
.crm-empty { font-size: 13px; color: var(--gray-500); font-style: italic; padding: 6px 0; }

/* tag aggiuntivi */
.tag-gray { background: var(--gray-100); color: var(--gray-700); }
.tag-gold { background: var(--gold-bg); color: var(--gold-dk); border: 1px solid var(--gold-lt); }
.tag-navy { background: var(--navy-900); color: #fff; }
.tag-green { background: var(--green-bg); color: var(--green); }
.tag-red { background: var(--red-bg); color: var(--red); }
.tag-amber { background: var(--amber-bg); color: var(--amber); }

/* Responsive */
@media (max-width: 900px) {
  .imm-layout { grid-template-columns: 0 1fr 0 !important; }
  .imm-layout.detail-open { grid-template-columns: 0 0 100% !important; }
  .imm-layout.detail-open .imm-results-wrap { display: none; }
  .imm-detail {
    display: flex !important;
  }

  /* Bottone "Filtri" fluttuante (solo mobile) */
  .imm-filters-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    left: 14px;
    bottom: 16px;
    z-index: 240;
    padding: 10px 16px;
    border: none;
    border-radius: 999px;
    background: var(--navy-900);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
  }
  .imm-layout.detail-open .imm-filters-toggle { display: none; }

  /* Drawer filtri off-canvas */
  .imm-filters {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 86%;
    max-width: 320px;
    z-index: 260;
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  .imm-layout.imm-filters--open .imm-filters { transform: translateX(0); }

  /* Backdrop */
  .imm-filters-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(15, 23, 42, .45);
  }
  .imm-layout.imm-filters--open .imm-filters-backdrop { display: block; }

  /* Bottone chiusura interno al drawer */
  .imm-filters-close { display: inline-flex !important; }
}

/* Desktop: il toggle/close/backdrop del drawer restano nascosti */
@media (min-width: 901px) {
  .imm-filters-toggle,
  .imm-filters-close,
  .imm-filters-backdrop { display: none !important; }
}


/* BP Manager external nav link */
.nav-external { opacity: .9; }
.nav-external:hover { opacity: 1; background: rgba(201,169,97,.08); }
.nav-external .nav-icon { filter: none; }

/* ═══ CRM CRITERI — checkbox tipologie ═══ */
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-top: 4px; }
.check-inline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--gray-700); cursor: pointer; }
.check-inline input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--gold); flex-shrink: 0; }

/* ═══ DETTAGLIO CLIENTE — azioni rapide ═══ */
.azioni-rapide { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.btn-azione {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 14px 6px; font-size: 22px; line-height: 1;
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: 10px;
  cursor: pointer; color: var(--navy-900); transition: all .15s;
}
.btn-azione span { font-size: 12px; font-weight: 600; }
.btn-azione:hover { border-color: var(--gold); background: var(--gold-bg); }

/* ═══ TIMELINE ATTIVITÀ ═══ */
.timeline { display: flex; flex-direction: column; gap: 2px; }
.timeline-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.timeline-item:last-child { border-bottom: none; }
.timeline-ico { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.timeline-head strong { font-size: 13.5px; color: var(--navy-900); }
.timeline-date { font-size: 11.5px; color: var(--gray-400); white-space: nowrap; }
.timeline-desc { font-size: 13px; color: var(--gray-700); margin: 4px 0 2px; line-height: 1.5; white-space: pre-wrap; }
.timeline-op { font-size: 11.5px; color: var(--gray-400); }

/* ═══ MATCHING IMMOBILI ═══ */
.match-banner { font-size: 12.5px; padding: 8px 10px; border-radius: 8px; margin-bottom: 10px; background: var(--gold-bg); color: var(--gold-dk); border: 1px solid var(--gold-lt); }
.match-banner--ok { background: var(--green-bg); color: var(--green); border-color: #a7f3d0; }
.match-dist { display: inline-block; font-size: 11px; font-weight: 600; color: var(--gold-dk); background: var(--gold-bg); border-radius: 6px; padding: 0 5px; }
.match-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.match-row:last-child { border-bottom: none; }
.match-main { flex: 1; min-width: 0; }
.match-title { font-size: 13.5px; font-weight: 600; color: var(--navy-900); display: flex; align-items: center; gap: 6px; }
.match-sub { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.match-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Badge punteggio match cliente↔immobile (oro/navy) */
.match-score {
  flex-shrink: 0;
  min-width: 46px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy-900);
  background: var(--gold-bg);
  border: 1px solid var(--gold-lt);
  border-radius: 999px;
  padding: 4px 10px;
}
/* Chip criteri di matching */
.match-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.match-chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  padding: 2px 7px;
  line-height: 1.5;
}
.match-chip--ok      { background: var(--green-bg); color: var(--green); border: 1px solid #a7f3d0; }
.match-chip--miss    { background: var(--gray-100); color: var(--gray-500); border: 1px solid var(--gray-200); }
.match-chip--relaxed { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* Sprint 1 / C2 — Toggle attivo/inattivo inline nella lista clienti */
.cliente-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; user-select: none; }
.cliente-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.cliente-toggle-track { position: relative; width: 28px; height: 16px; background: #cbd5e1; border-radius: 9999px; transition: background .15s ease; flex-shrink: 0; }
.cliente-toggle-thumb { position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; background: #fff; border-radius: 50%; transition: transform .15s ease; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.cliente-toggle input:checked + .cliente-toggle-track { background: #16a34a; }
.cliente-toggle input:checked + .cliente-toggle-track .cliente-toggle-thumb { transform: translateX(12px); }
.cliente-toggle-text { font-weight: 600; color: var(--gray-700); white-space: nowrap; }
.cliente-toggle input:checked ~ .cliente-toggle-text { color: #16a34a; }
.cliente-prio-sel { background: #fff; border: 1px solid var(--gray-200); cursor: pointer; }

/* Badge "🎯 N clienti" sulla card immobile */
.imm-match-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  margin: 4px 0 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold-dk);
  background: var(--gold-bg);
  border: 1px solid var(--gold-lt);
  border-radius: 6px;
  padding: 2px 7px;
}

/* Toolbar dettaglio (es. scarica perizia) */
.imm-detail-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

/* Toggle/close/backdrop drawer filtri (mostrati solo su mobile) */
.imm-filters-toggle { display: none; }
.imm-filters-close { display: none; }
.imm-filters-backdrop { display: none; }
.filter-input--multi { height: auto; min-height: 96px; padding: 4px; }
.filter-hint { display: block; font-size: 10.5px; color: var(--gray-400); margin-top: 4px; }

/* ═══ DOCUMENTI OFFERTA (Fase 7) ═══ */
.doc-checklist { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.doc-row { padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: 8px; background: var(--gray-50); }
.doc-row--ok { background: var(--green-bg); border-color: #bbf7d0; }
.doc-check-label { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--navy-900); cursor: pointer; }
.doc-check-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--green); flex-shrink: 0; }
.doc-extra { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; padding-left: 28px; }
.doc-extra input { height: 34px; border: 1px solid var(--gray-200); border-radius: 6px; padding: 0 8px; font-size: 13px; }
.doc-extra input[type="number"] { width: 120px; }

/* ═══ AGENDA / OGGI (Fase 6) ═══ */
.agenda-wrap { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.agenda-section .card-body { padding: 6px 16px; }
.agenda-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--gray-100); }
.agenda-row:last-child { border-bottom: none; }
.agenda-row-main { flex: 1; min-width: 0; }
.agenda-row-title { font-size: 14px; font-weight: 600; color: var(--navy-900); }
.agenda-row-sub { font-size: 12px; color: var(--gray-500); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.agenda-row-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: center; }
.agenda-contact {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 9px; font-size: 18px; text-decoration: none;
  background: var(--gray-50); border: 1px solid var(--gray-200);
}
.agenda-contact:hover { border-color: var(--gold); background: var(--gold-bg); }

@media (max-width: 768px) {
  .azioni-rapide { grid-template-columns: repeat(2, 1fr); }
  .match-row, .agenda-row { flex-direction: column; align-items: stretch; }
  .match-actions, .agenda-row-actions { justify-content: flex-end; }
}
