/* ============================================================
   Fattureper - Design System
   ============================================================ */

:root {
  /* Brand */
  --brand: #6366f1;
  --brand-hover: #4f46e5;
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  /* Status accents */
  --success: #10b981;
  --success-50: #d1fae5;
  --warning: #f59e0b;
  --warning-50: #fef3c7;
  --danger: #ef4444;
  --danger-50: #fee2e2;
  --info: #0ea5e9;
  --info-50: #e0f2fe;

  /* Neutrals */
  --bg: #f5f6fb;
  --surface: #ffffff;
  --border: #e6e8f0;
  --border-strong: #d6d9e6;
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-light: #9ca3af;

  /* Layout */
  --sidebar-w: 248px;
  --topbar-h: 72px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

/* ============================================================
   App shell: sidebar + topbar + content
   ============================================================ */

.app-shell {
  min-height: 100vh;
  position: relative;
}

/* Sidebar */
.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 24px 8px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.35);
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  flex-grow: 1;
}

.sidebar-nav .nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
  padding: 16px 12px 6px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  margin: 2px 0;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a i { font-size: 1.15rem; width: 20px; text-align: center; }

.sidebar-nav a:hover {
  background: var(--brand-50);
  color: var(--brand-700);
}

.sidebar-nav a.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.3);
}

.sidebar-nav a.active:hover { background: var(--brand-hover); color: #fff; }

.sidebar-upgrade {
  margin: 16px 4px 0;
  padding: 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
  border: 1px solid var(--brand-100);
}

.sidebar-upgrade .crown {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--brand);
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

.sidebar-upgrade h6 { margin: 0 0 4px; font-weight: 700; }
.sidebar-upgrade p { font-size: 0.78rem; color: var(--text-muted); margin: 0 0 12px; }

/* Topbar */
.app-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.search-box {
  flex-grow: 1;
  max-width: 520px;
  position: relative;
}

.search-box input {
  width: 100%;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 0 14px 0 44px;
  font-size: 0.9rem;
  color: var(--text);
  transition: border 0.15s, background 0.15s;
}

.search-box input:focus {
  outline: none;
  background: #fff;
  border-color: var(--brand-100);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-box .bi-search {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--brand-50); color: var(--brand); }

.icon-btn .badge-dot {
  position: absolute;
  top: 8px; right: 8px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}

.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  font-weight: 500;
}

.user-chip:hover { background: var(--brand-50); }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  display: inline-flex; align-items: center; justify-content: center;
}

.sidebar-toggle {
  display: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  align-items: center; justify-content: center;
  cursor: pointer;
}

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

.app-content {
  padding: 32px;
  flex-grow: 1;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* ============================================================
   Buttons (override bootstrap)
   ============================================================ */

.btn {
  border-radius: 10px;
  font-weight: 600;
  padding: 8px 16px;
  font-size: 0.9rem;
  transition: all 0.15s;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-sm { padding: 5px 10px; font-size: 0.82rem; border-radius: 8px; }
.btn-lg { padding: 10px 20px; font-size: 1rem; border-radius: 12px; }

.btn-primary, .btn-brand {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-primary:hover, .btn-brand:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: #fff;
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.3);
}

.btn-outline-primary {
  border-color: var(--border-strong);
  color: var(--brand);
  background: #fff;
}
.btn-outline-primary:hover {
  background: var(--brand-50);
  border-color: var(--brand-100);
  color: var(--brand-700);
}

.btn-outline-success { border-color: var(--border-strong); color: var(--success); background: #fff; }
.btn-outline-success:hover { background: var(--success-50); border-color: var(--success); color: var(--success); }

.btn-outline-danger { border-color: var(--border-strong); color: var(--danger); background: #fff; }
.btn-outline-danger:hover { background: var(--danger-50); border-color: var(--danger); color: var(--danger); }

.btn-outline-warning { border-color: var(--border-strong); color: var(--warning); background: #fff; }
.btn-outline-warning:hover { background: var(--warning-50); border-color: var(--warning); color: var(--warning); }

.btn-outline-info { border-color: var(--border-strong); color: var(--info); background: #fff; }
.btn-outline-info:hover { background: var(--info-50); border-color: var(--info); color: var(--info); }

.btn-outline-secondary { border-color: var(--border-strong); color: var(--text-muted); background: #fff; }
.btn-outline-secondary:hover { background: var(--bg); color: var(--text); }

.btn-secondary { background: var(--bg); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--border); color: var(--text); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #059669; border-color: #059669; color: #fff; }

.btn-group .btn { margin-left: 0; }

/* ============================================================
   Cards
   ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  font-weight: 600;
  font-size: 1rem;
}

.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }

/* ============================================================
   KPI cards (dashboard)
   ============================================================ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.15s;
}

.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 1.25rem;
}

.kpi-icon.brand { background: var(--brand-50); color: var(--brand); }
.kpi-icon.success { background: var(--success-50); color: var(--success); }
.kpi-icon.warning { background: var(--warning-50); color: var(--warning); }
.kpi-icon.info { background: var(--info-50); color: var(--info); }

.kpi-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.kpi-value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 4px;
}

.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }
.kpi-trend small { color: var(--text-muted); font-weight: 400; }

/* ============================================================
   Dashboard grid
   ============================================================ */

.dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.dash-grid-bottom {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 20px;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-wrap.sm { height: 120px; }

.donut-wrap {
  position: relative;
  height: 220px;
  display: flex; align-items: center; justify-content: center;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}

.donut-center .label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.donut-center .value { font-size: 1.8rem; font-weight: 700; }

.legend-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-list li {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.88rem;
}

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-list .count {
  margin-left: auto;
  font-weight: 600;
  color: var(--text);
}

.reminder-card {
  border-radius: var(--radius);
  background: var(--danger-50);
  border: 1px solid #fecaca;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.reminder-card .ric {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: #fff;
  color: var(--danger);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
}

.quick-action:last-child { margin-bottom: 0; }

.quick-action:hover {
  background: var(--brand-50);
  border-color: var(--brand-100);
  color: var(--brand-700);
}

.quick-action i {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--brand-50);
  color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.quick-action:hover i { background: var(--brand); color: #fff; }

.quick-action .chev { margin-left: auto; color: var(--text-light); }

/* ============================================================
   Tables
   ============================================================ */

.table {
  margin: 0;
  color: var(--text);
}

.table thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: none;
  padding: 12px 16px;
  white-space: nowrap;
}

.table tbody td {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
  font-size: 0.9rem;
}

.table tbody tr:first-child td { border-top: 1px solid var(--border); }

.table-hover tbody tr:hover { background: var(--brand-50); }

.table-compact th, .table-compact td { padding: 8px 12px; font-size: 0.85rem; }

/* Onboarding mode: nasconde sidebar/topbar per UX focalizzata */
body.onboarding-mode .app-sidebar,
body.onboarding-mode .app-topbar,
body.onboarding-mode .sidebar-backdrop { display: none !important; }
body.onboarding-mode .app-main { margin-left: 0 !important; padding-top: 2rem !important; }

/* Wizard onboarding: card di selezione regime */
.onb-regime-card { display: block; }
.onb-regime-card .card { transition: all 0.15s ease; }
.onb-regime-card:hover .card { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15,23,42,0.08); }
.onb-regime-card.active .card { box-shadow: 0 0 0 2px var(--brand); }

/* Tabella documenti responsive: riduce padding/font su schermi piccoli
   per evitare lo scroll orizzontale. */
.docs-table th, .docs-table td { vertical-align: middle; }
@media (max-width: 991.98px) {
  .docs-table { font-size: 0.85rem; }
  .docs-table th, .docs-table td { padding: 0.5rem 0.4rem; }
}
@media (max-width: 575.98px) {
  .docs-table { font-size: 0.8rem; }
  .docs-table th, .docs-table td { padding: 0.4rem 0.3rem; }
  .docs-table .btn-sm { padding: 0.2rem 0.35rem; font-size: 0.7rem; }
}

/* ============================================================
   Badges & status pills
   ============================================================ */

.badge {
  font-weight: 600;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.text-bg-primary  { background: var(--brand-50)   !important; color: var(--brand-700) !important; border-color: var(--brand-100); }
.text-bg-success  { background: var(--success-50) !important; color: #047857 !important; border-color: #a7f3d0; }
.text-bg-warning  { background: var(--warning-50) !important; color: #b45309 !important; border-color: #fde68a; }
.text-bg-danger   { background: var(--danger-50)  !important; color: #b91c1c !important; border-color: #fecaca; }
.text-bg-info     { background: var(--info-50)    !important; color: #0369a1 !important; border-color: #bae6fd; }
.text-bg-secondary{ background: var(--bg)         !important; color: var(--text-muted) !important; border-color: var(--border); }

.badge-td {
  font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
  font-size: 0.72em;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ============================================================
   Forms
   ============================================================ */

.form-label {
  font-weight: 500;
  color: var(--text);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.form-control, .form-select {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 9px 12px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
  transition: border 0.15s, box-shadow 0.15s;
}

.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
  outline: none;
}

.form-control-sm, .form-select-sm { padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; }

.required::after { content: " *"; color: var(--danger); }

.summary-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.summary-box .row { margin: 0; padding: 4px 0; }
.summary-box .total-row {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 1.2rem;
  font-weight: 700;
}

/* ============================================================
   Alerts
   ============================================================ */

.alert {
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 14px 18px;
  font-size: 0.9rem;
}

.alert-success { background: var(--success-50); border-color: #a7f3d0; color: #047857; }
.alert-warning { background: var(--warning-50); border-color: #fde68a; color: #92400e; }
.alert-danger  { background: var(--danger-50); border-color: #fecaca; color: #991b1b; }
.alert-info    { background: var(--info-50); border-color: #bae6fd; color: #075985; }

.error-list { list-style: none; padding-left: 0; margin: 0; }
.error-list li { padding: 4px 0; }
.error-list li::before { content: "\26A0  "; color: var(--danger); }

/* ============================================================
   Modals & misc
   ============================================================ */

.modal-content {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
}

.modal-body { padding: 20px 24px; }
.modal-footer { border-top: 1px solid var(--border); padding: 14px 24px; }

.dropdown-menu {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
}

.dropdown-item {
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.9rem;
  color: var(--text);
}

.dropdown-item:hover { background: var(--brand-50); color: var(--brand-700); }
.dropdown-item.text-danger:hover { background: var(--danger-50); color: var(--danger); }

.toast { border-radius: var(--radius); border: 1px solid var(--border); }

.bg-brand-soft { background: var(--brand-50); color: var(--brand-700); }

.spinner-border { color: var(--brand); }

/* ============================================================
   Compat: vecchi titoli h2 nelle viste interne
   ============================================================ */
.app-content > h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
}
.app-content > h2 i { color: var(--brand); }

.text-muted { color: var(--text-muted) !important; }
.text-primary { color: var(--brand) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-info { color: var(--info) !important; }

hr { border-color: var(--border); opacity: 1; margin: 1rem 0; }

.list-group-item {
  border-color: var(--border);
  padding: 14px 16px;
  background: transparent;
}

.list-group-flush > .list-group-item:last-child { border-bottom: 0; }

.input-group-text {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text-muted);
  border-radius: 10px 0 0 10px;
}
.input-group .form-control { border-radius: 0 10px 10px 0; }

.nav-tabs {
  border-bottom: 1px solid var(--border);
  gap: 4px;
}
.nav-tabs .nav-link {
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  font-weight: 500;
  border-radius: 8px 8px 0 0;
}
.nav-tabs .nav-link.active {
  color: var(--brand);
  background: var(--brand-50);
  border-bottom: 2px solid var(--brand);
}

.btn-link { color: var(--brand); text-decoration: none; font-weight: 500; }
.btn-link:hover { color: var(--brand-hover); text-decoration: underline; }

.btn-close { filter: none; opacity: 0.6; }
.btn-close:hover { opacity: 1; }

/* Chat bubbles (form chat fattura) */
.chat-msg.user .chat-bubble {
  background: var(--brand) !important;
  color: #fff;
}
.chat-msg.assistant .chat-bubble {
  background: var(--bg) !important;
  border: 1px solid var(--border) !important;
  color: var(--text);
}

/* Pagination Bootstrap */
.page-link { color: var(--brand); border-color: var(--border); border-radius: 8px; margin: 0 2px; }
.page-link:hover { background: var(--brand-50); color: var(--brand-700); }
.page-item.active .page-link { background: var(--brand); border-color: var(--brand); }

/* Editable inline fields */
.editable-total, .editable-vat, .editable-due-date {
  font-weight: 600;
}
.editable-total:hover, .editable-vat:hover, .editable-due-date:hover {
  color: var(--brand);
}

/* Spinner di caricamento */
.spinner-border-sm { color: inherit; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 991.98px) {
  .app-main { margin-left: 0; }

  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  .app-sidebar.is-open { transform: translateX(0); }

  .sidebar-toggle { display: inline-flex; }

  .app-content { padding: 20px; }

  .app-topbar { padding: 0 20px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  .dash-grid, .dash-grid-bottom { grid-template-columns: 1fr; }

  .search-box { max-width: none; }

  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 25;
    display: none;
  }

  .sidebar-backdrop.is-open { display: block; }
}

@media (max-width: 575.98px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.4rem; }
  .page-title { font-size: 1.3rem; }
  .topbar-actions .user-chip span { display: none; }
}

/* ============================================================
   Mobile: layout responsive globale
   ============================================================ */
@media (max-width: 767.98px) {
  .app-main { padding-left: 12px !important; padding-right: 12px !important; padding-top: 12px !important; }
  .app-topbar { padding: 10px 12px !important; gap: 8px !important; }
  .app-topbar .search-box { display: none !important; }
  .company-switcher button { font-size: 0.85rem !important; padding: 6px 10px !important; }
  .company-switcher #companySwitcherLabel { max-width: 120px !important; }
  .card-body { padding: 14px !important; }
  .card-header { padding: 12px 14px !important; font-size: 0.95rem; }
  h2 { font-size: 1.4rem !important; }
  h5 { font-size: 1.05rem !important; }
  .btn-group.flex-wrap > * { flex: 1 1 auto; }
  /* Touch-friendly inputs; 16px previene zoom su iOS */
  .form-control, .form-select { font-size: 16px !important; }
  .form-control-sm, .form-select-sm { font-size: 15px !important; min-height: 38px; }
  .form-label { font-size: 0.85rem; margin-bottom: 0.25rem; }
  .table-responsive { -webkit-overflow-scrolling: touch; }
  /* Tabella righe fattura: compatta orizzontale ma scrollabile */
  .invoice-lines-table { font-size: 14px; min-width: 720px; }
  .invoice-lines-table th, .invoice-lines-table td { padding: 6px 4px !important; }
  .invoice-lines-table input, .invoice-lines-table select { font-size: 14px !important; padding: 4px 6px !important; min-height: 32px; }
  /* Bottoni di azione full-width nei form principali */
  .form-actions-mobile-full .btn { width: 100%; margin-bottom: 8px; }
  /* Sticky action bar per form lunghi su mobile */
  .form-action-sticky {
    position: sticky; bottom: 0;
    background: #fff;
    margin: 0 -12px -12px;
    padding: 12px;
    border-top: 1px solid var(--border);
    z-index: 10;
    display: flex;
    gap: 8px;
  }
  .form-action-sticky .btn { flex: 1 1 auto; }
  /* Modali full-width */
  .modal-dialog { margin: 8px !important; }
  /* Stat cards 2 per riga invece di 4 */
  .stat-card .value { font-size: 1.4rem !important; }
}
