/* ============================================================
   IOCOS Document Manager — Stile principale
   ============================================================ */

/* L'attributo hidden deve vincere su .btn/.topbar-ic (display:inline-flex), altrimenti l'elemento resta visibile. */
[hidden] { display: none !important; }

:root {
  --primary:    #1e1e50;
  --primary-lt: #2d2d78;
  --accent:     #e74c3c;
  --accent-lt:  #ff6b5b;
  --success:    #27ae60;
  --warning:    #f39c12;
  --info:       #2980b9;
  --danger:     #c0392b;
  --gray-50:    #f8f9fa;
  --gray-100:   #f1f3f5;
  --gray-200:   #e9ecef;
  --gray-300:   #dee2e6;
  --gray-500:   #adb5bd;
  --gray-700:   #495057;
  --gray-900:   #212529;
  --sidebar-w:  250px;
  --header-h:   60px;
  --radius:     6px;
  --shadow:     0 2px 8px rgba(0,0,0,.1);
  --shadow-lg:  0 4px 20px rgba(0,0,0,.15);
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif, 'Noto Color Emoji';
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--gray-100); color: var(--gray-900); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-lt); }
img { max-width: 100%; }

/* ===================== LAYOUT ===================== */
.app-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: #11302b;
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
  transition: transform .25s;
}
.sidebar-logo {
  padding: 18px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo img { width: 36px; height: 36px; object-fit: contain; }
.sidebar-logo .logo-text { font-size: 15px; font-weight: 700; line-height: 1.2; }
.sidebar-logo .logo-sub { font-size: 10px; opacity: .6; }

.sidebar-nav { flex: 1; padding: 10px 0; }
.nav-section { padding: 16px 20px 6px; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; opacity: .5; }
.nav-item { display: block; padding: 10px 20px; color: rgba(255,255,255,.8); transition: all .15s; display: flex; align-items: center; gap: 10px; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.12); color: white; }
.nav-item.active { border-left: 3px solid white; }
.nav-item svg, .nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }

/* Voce di menu "in evidenza" (es. Bacheca in cima all'Area Clienti) */
.nav-item-primary { margin: 4px 12px 12px; padding: 12px 14px; border-radius: 10px;
                     background: rgba(255,255,255,.14); font-weight: 700; }
.nav-item-primary:hover, .nav-item-primary.active { background: rgba(255,255,255,.24); }
.nav-item-primary svg { opacity: 1; }
.nav-item-primary.nav-item-accent { background: var(--accent); color: #fff; }
.nav-item-primary.nav-item-accent:hover, .nav-item-primary.nav-item-accent.active { background: var(--accent-lt); color: #fff; }
.nav-item-primary.nav-item-ai { background: linear-gradient(135deg, #7c3aed, #db2777); color: #fff;
                                box-shadow: 0 2px 10px rgba(124,58,237,.35); }
.nav-item-primary.nav-item-ai:hover, .nav-item-primary.nav-item-ai.active { background: linear-gradient(135deg, #8b5cf6, #ec4899); color: #fff; }
.nav-item-primary.nav-item-ai.active { border-left: 0; }
/* Voci del menu principale, ognuna con il suo colore */
.nav-item-primary.nav-item-blue   { background: linear-gradient(135deg, #4338ca, #6366f1); color: #fff; }
.nav-item-primary.nav-item-blue:hover, .nav-item-primary.nav-item-blue.active { background: linear-gradient(135deg, #4f46e5, #818cf8); color: #fff; }
.nav-item-primary.nav-item-amber  { background: linear-gradient(135deg, #b45309, #d97706); color: #fff; }
.nav-item-primary.nav-item-amber:hover, .nav-item-primary.nav-item-amber.active { background: linear-gradient(135deg, #c2410c, #f59e0b); color: #fff; }
.nav-item-primary.nav-item-cyan   { background: linear-gradient(135deg, #0e7490, #0891b2); color: #fff; }
.nav-item-primary.nav-item-cyan:hover, .nav-item-primary.nav-item-cyan.active { background: linear-gradient(135deg, #0891b2, #06b6d4); color: #fff; }
/* Voce attiva: bordo bianco attorno al riquadro invece della barra a sinistra */
.nav-item-primary.active { border-left: 0; box-shadow: inset 0 0 0 2px rgba(255,255,255,.9); }
.nav-item-primary.nav-item-ai.active { box-shadow: inset 0 0 0 2px rgba(255,255,255,.9), 0 2px 10px rgba(124,58,237,.35); }
.nav-item-primary + .nav-item-primary { margin-top: -4px; }
.nav-badge-ai { margin-left: auto; padding: 2px 6px; border-radius: 999px; background: rgba(255,255,255,.22);
                font-size: 10px; font-weight: 700; letter-spacing: .5px; line-height: 1.2; }

/* Sidebar — sezioni comprimibili (accordion) */
.nav-group { display: block; }
.nav-group + .nav-group { margin-top: 2px; }
button.nav-section {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 14px 20px 6px;
  background: none; border: 0; opacity: 1;
  font-family: var(--font); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; line-height: 1;
  text-align: left; cursor: pointer;
  color: rgba(255,255,255,.5);
  transition: color .15s;
}
button.nav-section:hover { color: rgba(255,255,255,.85); }
.nav-sec-label { flex: 1 1 auto; }
button.nav-section svg,
.nav-chevron {
  width: 10px; height: 10px; flex: 0 0 auto; display: block;
  color: rgba(255,255,255,.55);
  transition: transform .2s ease;
}
.nav-group:not(.is-collapsed) > button.nav-section .nav-chevron { transform: rotate(90deg); }
.nav-group.is-collapsed > .nav-group-items { display: none; }
.nav-sec-badge {
  flex: 0 0 auto;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; letter-spacing: 0; line-height: 1;
  border-radius: 8px;
}

.sidebar-footer { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.1); font-size: 12px; opacity: .6; }

/* Main content */
.main-wrapper { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }

/* Top header */
.topbar {
  height: var(--header-h);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-title { font-size: 18px; font-weight: 600; color: var(--primary); }
.topbar-domain-select {
  font-size: 18px; font-weight: 600; color: var(--primary);
  border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 2px 6px; max-width: 320px; cursor: pointer;
}
.topbar-domain-select:hover, .topbar-domain-select:focus { border-color: var(--gray-200); background: var(--gray-50); outline: none; }
.topbar-search-select { position: relative; }
.topbar-search-input {
  font-size: 18px; font-weight: 600; color: var(--primary);
  border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 2px 6px; width: 260px; max-width: 46vw;
}
.topbar-search-input:hover, .topbar-search-input:focus { border-color: var(--gray-200); background: var(--gray-50); outline: none; }
.topbar-search-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 280px; max-width: 420px;
  max-height: 320px; overflow-y: auto; background: #fff; border: 1px solid var(--gray-200);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12); z-index: 200; padding: 4px;
}
.topbar-search-dropdown .tsd-item { padding: 7px 10px; border-radius: 6px; font-size: 14px; font-weight: 400; cursor: pointer; color: var(--gray-700); }
.topbar-search-dropdown .tsd-item:hover, .topbar-search-dropdown .tsd-item.is-active { background: var(--gray-100); }
.topbar-search-dropdown .tsd-empty { padding: 8px 10px; font-size: 13px; color: var(--gray-500); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* Page content */
.page-content { flex: 1; padding: 24px; max-width: 1300px; width: 100%; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--primary); }
.page-subtitle { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all .15s;
  line-height: 1;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary    { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-lt); }
.btn-primary.btn-static:hover { background: var(--primary); color: white; border-color: var(--primary); } /* nessun cambio colore al passaggio */
.btn-accent     { background: var(--accent); color: white; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-lt); }
.btn-success    { background: var(--success); color: white; }
.btn-success:hover { opacity: .9; }
.btn-warning    { background: var(--warning); color: white; }
.btn-danger     { background: var(--danger); color: white; }
.btn-outline    { background: white; color: var(--primary); border-color: var(--gray-300); }
.btn-outline:hover { border-color: var(--primary); background: var(--gray-50); }
.btn-ghost      { background: transparent; color: var(--gray-700); border-color: transparent; }
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

/* CTA con il "marchio" AICOS: usato per le azioni IA che meritano risalto
   (migliora SEO, genera bozza...), sia in liste compatte che in pagina. */
.btn-aicos {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; font-size: 15px; font-weight: 700; line-height: 1.2;
  color: #fff; border: none; border-radius: 9px; cursor: pointer; text-decoration: none;
  background: linear-gradient(135deg, #2a2a72, #d63e2a);
  box-shadow: 0 4px 14px rgba(42,42,114,.28);
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn-aicos:hover { transform: translateY(-1px); box-shadow: 0 7px 20px rgba(42,42,114,.4); color: #fff; }
.btn-aicos:active { transform: translateY(0); }
.btn-aicos:disabled { opacity: .6; cursor: default; transform: none; box-shadow: none; }
.btn-aicos-sm { padding: 6px 12px; font-size: 12px; border-radius: 7px; box-shadow: 0 2px 8px rgba(42,42,114,.25); white-space: nowrap; }

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

/* ===================== STATS GRID ===================== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: white; border-radius: var(--radius); border: 1px solid var(--gray-200);
  padding: 16px 20px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow);
}
.stat-card .stat-num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 12px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; }
.stat-card.accent .stat-num { color: var(--accent); }
.stat-card.success .stat-num { color: var(--success); }
.stat-card.warning .stat-num { color: var(--warning); }
.stat-card.info .stat-num { color: var(--info); }

/* ===================== TABLE ===================== */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: var(--gray-50); color: var(--gray-700); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; padding: 10px 12px; text-align: left; border-bottom: 2px solid var(--gray-200); }
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--gray-200); vertical-align: middle; }
.data-table tr:hover td { background: var(--gray-50); }
.data-table tr:last-child td { border-bottom: none; }

/* ===================== BADGES ===================== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.badge-gray   { background: var(--gray-200); color: var(--gray-700); }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-yellow { background: #fef3c7; color: #b45309; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-purple { background: #f3e8ff; color: #7c3aed; }
.badge-red    { background: #fee2e2; color: #991b1b; }

/* ===================== FORMS ===================== */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 5px; }
.form-label .req { color: var(--accent); margin-left: 2px; }
.form-control {
  width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: 13px; color: var(--gray-900);
  background: white; transition: border-color .15s;
  font-family: var(--font);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,30,80,.08); }
.form-control:disabled { background: var(--gray-100); cursor: not-allowed; }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 11px; color: var(--gray-500); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Checkbox / Radio */
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.form-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.form-check label { cursor: pointer; font-size: 13px; }

/* Toggle switch */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; width: 42px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--gray-300); border-radius: 22px; transition: .3s; }
.toggle-slider:before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .3s; }
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }

/* ===================== WIZARD ===================== */
.wizard-layout { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.wizard-sidebar {
  background: white; border-radius: var(--radius); border: 1px solid var(--gray-200);
  box-shadow: var(--shadow); position: sticky; top: 80px; overflow: hidden;
}
.wizard-sidebar-header { background: var(--primary); color: white; padding: 14px 16px; }
.wizard-sidebar-header h4 { font-size: 14px; font-weight: 600; }
.wizard-progress { font-size: 12px; opacity: .8; margin-top: 2px; }
.wizard-steps-list { padding: 8px 0; }
.wizard-step-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; cursor: pointer; transition: background .15s;
  font-size: 13px; color: var(--gray-700); border-left: 3px solid transparent;
}
.wizard-step-item:hover { background: var(--gray-50); }
.wizard-step-item.active { background: var(--gray-100); color: var(--primary); font-weight: 600; border-left-color: var(--primary); }
.wizard-step-item.done { color: var(--success); }
.wizard-step-num { width: 22px; height: 22px; border-radius: 50%; background: var(--gray-200); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.wizard-step-item.active .wizard-step-num { background: var(--primary); color: white; }
.wizard-step-item.done .wizard-step-num { background: var(--success); color: white; }

.wizard-content { background: white; border-radius: var(--radius); border: 1px solid var(--gray-200); box-shadow: var(--shadow); }
.wizard-content-header { padding: 20px 24px; border-bottom: 1px solid var(--gray-200); }
.wizard-step-title { font-size: 18px; font-weight: 700; color: var(--primary); }
.wizard-step-desc { font-size: 13px; color: var(--gray-500); margin-top: 3px; }
.wizard-content-body { padding: 24px; }
.wizard-content-footer { padding: 16px 24px; background: var(--gray-50); border-top: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }

/* Progress bar */
.progress-bar-wrap { height: 6px; background: var(--gray-200); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }

/* ===================== ALERTS ===================== */
.alert { padding: 12px 16px; border-radius: var(--radius); border: 1px solid; margin-bottom: 16px; display: flex; gap: 10px; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fed7aa; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* ===================== DYNAMIC TABLES ===================== */
.dynamic-table-wrap { border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.dynamic-table-header { background: var(--gray-50); padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--gray-200); }
.dynamic-table-header h4 { font-size: 13px; font-weight: 600; color: var(--gray-700); }
table.dynamic-table { width: 100%; border-collapse: collapse; }
.dynamic-table th { background: var(--gray-100); padding: 8px 10px; font-size: 11px; text-transform: uppercase; color: var(--gray-500); border-bottom: 1px solid var(--gray-200); text-align: left; }
.dynamic-table td { padding: 8px 10px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.dynamic-table tr:last-child td { border-bottom: none; }
.dynamic-table input, .dynamic-table select { width: 100%; padding: 5px 8px; border: 1px solid var(--gray-200); border-radius: 4px; font-size: 12px; }
.dynamic-table input:focus, .dynamic-table select:focus { outline: none; border-color: var(--primary); }

/* ===================== COMPLETENESS CHECK ===================== */
.check-section { border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.check-section-header { background: var(--gray-50); padding: 10px 16px; font-size: 13px; font-weight: 600; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-top: 1px solid var(--gray-100); font-size: 13px; }
.check-item.ok   { color: var(--success); }
.check-item.err  { color: var(--danger); }
.check-item.warn { color: var(--warning); }
.check-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.check-item.ok   .check-dot { background: var(--success); }
.check-item.err  .check-dot { background: var(--danger); }
.check-item.warn .check-dot { background: var(--warning); }

/* ===================== AUTH ===================== */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-lt) 100%); }
.auth-card { background: white; width: 380px; border-radius: 10px; box-shadow: var(--shadow-lg); padding: 40px; }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-name { font-size: 22px; font-weight: 700; color: var(--primary); }
.auth-logo .logo-sub { font-size: 13px; color: var(--gray-500); }
.auth-card h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--gray-900); }

/* ===================== SEARCH BOX ===================== */
.search-box { display: flex; gap: 8px; align-items: center; }
.search-box .form-control { max-width: 260px; }

/* ===================== SECTION TABS ===================== */
.section-tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; }
.section-tab { padding: 8px 16px; font-size: 13px; font-weight: 500; color: var(--gray-500); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.section-tab.active, .section-tab:hover { color: var(--primary); border-bottom-color: var(--primary); }

/* ===================== MODALS ===================== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 999; display: none; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 8px; box-shadow: var(--shadow-lg); width: 560px; max-width: 95vw; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 16px; font-weight: 600; color: var(--primary); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; background: var(--gray-50); border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-500); line-height: 1; }
.cp-item { display: block; width: 100%; text-align: left; background: white; border: 1px solid var(--gray-200); border-radius: 6px; padding: 9px 12px; cursor: pointer; font-size: 13.5px; color: var(--gray-700); }
.cp-item:hover { border-color: var(--primary); background: var(--gray-100); }

/* ===================== MISC ===================== */
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.w-full { width: 100%; }
.divider { border: none; border-top: 1px solid var(--gray-200); margin: 20px 0; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 20px; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .4; }
.empty-state h3 { font-size: 16px; color: var(--gray-700); margin-bottom: 8px; }
.empty-state p { font-size: 13px; color: var(--gray-500); margin-bottom: 16px; }

/* Warning box */
.warning-box { background: #fffbeb; border: 1px solid var(--warning); border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; font-size: 13px; color: #92400e; }
.info-box { background: #eff6ff; border: 1px solid #93c5fd; border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; font-size: 13px; color: #1e40af; }

/* Gruppo di pulsanti uniti (bordo condiviso, angoli arrotondati solo agli estremi) */
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn:first-child { border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); }
.btn-group .btn:last-child { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); }

/* ===================== RESPONSIVE ===================== */
.sidebar-backdrop { display: none; }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); width: min(var(--sidebar-w), 84vw); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.4);
                      opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar.open ~ .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.sidebar-locked { overflow: hidden; }
  #menu-toggle { display: inline-flex !important; font-size: 20px; width: 40px; height: 40px; padding: 0; justify-content: center; flex: none; }
  .main-wrapper { margin-left: 0; min-width: 0; }
  .wizard-layout { grid-template-columns: 1fr; }
  .wizard-sidebar { position: static; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }

  /* Topbar: titolo/selettore che si accorcia invece di spingere fuori i pulsanti */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar > div:first-child { min-width: 0; flex: 1 1 auto; gap: 6px !important; }
  .topbar-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .topbar-domain-select { font-size: 15px; max-width: 100%; min-width: 0; }
  .topbar-search-select { min-width: 0; }
  .topbar-search-input { font-size: 15px; width: 100%; max-width: none; }
  .topbar-search-dropdown { position: fixed; left: 12px; right: 12px; top: calc(var(--header-h) + 4px); min-width: 0; max-width: none; max-height: 60vh; }
  .topbar-actions { gap: 6px; flex: none; }

  .page-header { flex-wrap: wrap; gap: 12px; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .section-tabs { overflow-x: auto; scrollbar-width: none; }
  .section-tabs::-webkit-scrollbar { display: none; }
  .section-tab { white-space: nowrap; }
}
@media (max-width: 600px) {
  /* Topbar su due righe: titolo sopra, pulsanti sotto; non resta fissa per lasciare spazio al contenuto */
  :root { --header-h: 0px; }
  .topbar { position: relative; height: auto; flex-wrap: wrap; padding: 8px 12px; row-gap: 6px; }
  .topbar > div:first-child { flex-basis: 100%; }
  .topbar-actions { width: 100%; flex-wrap: wrap; row-gap: 8px; }
  .topbar-actions > * { flex: none; }
  .topbar-search-dropdown { top: 56px; position: absolute; left: 0; right: 0; }
  .mega-panel, .notif-panel { position: fixed !important; left: 12px !important; right: 12px !important; top: 100px !important;
                              width: auto !important; max-width: none !important; max-height: calc(100vh - 116px); overflow-y: auto; }
  .notif-list { max-height: none; }

  .page-content { padding: 14px; }
  .page-header { margin-bottom: 16px; }
  .page-title { font-size: 19px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 12px 14px; }
  .stat-card .stat-num { font-size: 22px; }
  .card-header { padding: 12px 14px; }
  .card-body { padding: 14px; }
  .card-footer { padding: 12px 14px; }
  .data-table th, .data-table td { padding: 9px 10px; }
  .alert { padding: 10px 12px; }

  /* Form: 16px evita lo zoom automatico di iOS sui campi */
  .form-row, .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .form-control, .dynamic-table input, .dynamic-table select { font-size: 16px; }
  .form-check input { width: 20px; height: 20px; }
  .search-box { flex-wrap: wrap; }
  .search-box .form-control { max-width: none; flex: 1 1 180px; }
  .btn { min-height: 38px; }
  .btn-sm { min-height: 34px; padding: 6px 12px; }

  .wizard-content-header, .wizard-content-body { padding: 16px; }
  .wizard-content-footer { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }

  /* Modali a tutta larghezza, ancorate in basso */
  .modal-overlay.open { align-items: flex-end; }
  .modal { width: 100%; max-width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0; }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; }

  .auth-card { width: calc(100% - 28px); padding: 28px 20px; }
  .empty-state { padding: 32px 12px; }
}
