/* ================================================================
   Azure Cost Management Dashboard — Esordia / Servintek
   styles.css
   ================================================================ */

/* ── Google Fonts ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@400;600;700;800&family=Raleway:wght@400;500;600;700&display=swap');

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Esordia brand palette */
  --ink:            #25282A;
  --deep:           #0E4C5E;
  --petrol:         #134B5F;
  --rust:           #DC582A;
  --ember:          #C44A1F;
  --paper:          #F8F7F2;
  --mist:           #E8EEF1;
  --sand:           #CBC1AE;

  /* Semantic tokens (mappati sul brand) */
  --azure-blue:     var(--deep);
  --azure-blue-dk:  var(--petrol);
  --azure-blue-lt:  #7AB5C8;
  --bg:             #F2EEE8;
  --bg-card:        #FFFFFF;
  --border:         #DDD8D0;
  --text-primary:   var(--ink);
  --text-secondary: #556068;
  --text-muted:     #9CA3AF;
  --success:        #10B981;
  --warning:        #F59E0B;
  --danger:         var(--rust);
  --lighthouse:     var(--deep);
  --accent:         var(--rust);
  --radius:         12px;
  --radius-sm:      8px;
  --shadow:         0 1px 3px rgba(37,40,42,.08), 0 1px 2px rgba(37,40,42,.04);
  --shadow-md:      0 4px 12px rgba(37,40,42,.10), 0 2px 4px rgba(37,40,42,.06);
  --transition:     150ms ease;
}

html { font-size: 15px; }
body {
  font-family: 'Raleway', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Grain sottile — come sito Esordia */
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none; z-index: 999;
  opacity: 0.025;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

h1, h2, h3, .brand-name, .page-title, .chart-title, .table-header {
  font-family: 'Libre Franklin', system-ui, sans-serif;
}

/* ── Header ───────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--ink);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  height: 60px;
  box-shadow: 0 2px 8px rgba(37,40,42,.25);
}

.header-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit;
  flex-shrink: 0;
}
.brand-icon { height: 32px; width: auto; display: block; }
.app-footer {
  text-align: center;
  padding: 16px 24px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  opacity: 0.55;
  border-top: 1px solid var(--border);
  background: transparent;
}
.brand-name { display: block; font-weight: 700; font-size: .95rem; line-height: 1.2; color: #F8F7F2; }
.brand-sub  { display: block; font-size: .72rem; color: var(--sand); }

.header-nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: none; border: none; cursor: pointer;
  padding: 6px 14px; border-radius: 6px;
  font-size: .875rem; font-weight: 500;
  color: rgba(248,247,242,.6);
  transition: background var(--transition), color var(--transition);
  font-family: 'Raleway', sans-serif;
}
.nav-btn:hover   { background: rgba(248,247,242,.08); color: #F8F7F2; }
.nav-btn.active  { background: rgba(220,88,42,.18); color: var(--rust); }
.nav-btn:disabled { opacity: .3; cursor: not-allowed; }

.header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-info { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--rust); color: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
}
.user-name { font-size: .875rem; font-weight: 500; color: rgba(248,247,242,.85); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn-primary, .btn-outline, .btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 6px; font-weight: 600; font-size: .875rem;
  cursor: pointer; transition: all var(--transition);
  padding: 7px 16px; border: 1.5px solid transparent;
  font-family: 'Raleway', sans-serif;
}
.btn-primary {
  background: var(--rust); color: white; border-color: var(--rust);
}
.btn-primary:hover { background: var(--ember); border-color: var(--ember); }

.btn-outline {
  background: transparent; color: var(--deep); border-color: var(--deep);
}
.btn-outline:hover { background: var(--mist); }

.btn-back {
  background: none; border: none; color: var(--text-secondary);
  padding: 6px 10px; gap: 4px;
}
.btn-back:hover { color: var(--text-primary); }
.btn-back svg { width: 16px; height: 16px; }

.btn-large { padding: 12px 28px; font-size: 1rem; border-radius: 8px; }

.btn-sm { padding: 5px 12px; font-size: .8rem; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  padding: 6px; border-radius: 6px; color: rgba(248,247,242,.6);
  transition: background var(--transition);
  display: flex; align-items: center;
}
.btn-icon:hover { background: rgba(248,247,242,.1); color: #F8F7F2; }
.btn-icon svg { width: 16px; height: 16px; }

/* ── Main ─────────────────────────────────────────────────────── */
.app-main { flex: 1; padding: 24px; max-width: 1440px; margin: 0 auto; width: 100%; }

/* ── Views ────────────────────────────────────────────────────── */
.view { display: none; flex-direction: column; gap: 20px; }
.view.active { display: flex; }

/* Login */
.view-login {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 20% 60%, rgba(14,76,94,.12) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(220,88,42,.08) 0%, transparent 50%),
              var(--bg);
}
.login-card {
  background: var(--bg-card); border-radius: 16px;
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(37,40,42,.06);
  padding: 52px 48px;
  max-width: 440px; width: 100%; text-align: center;
}
.login-logo { margin-bottom: 24px; }
.login-logo svg { width: 64px; height: 64px; }
.login-card h1 {
  font-size: 1.5rem; font-weight: 800; margin-bottom: 10px;
  font-family: 'Libre Franklin', sans-serif; color: var(--ink);
}
.login-card p  { color: var(--text-secondary); margin-bottom: 28px; line-height: 1.65; }
.login-note {
  font-size: .8rem !important; color: var(--text-muted) !important;
  margin-top: 18px !important; margin-bottom: 0 !important;
  padding-top: 16px !important;
  border-top: 1px solid var(--border);
}
.ms-icon { width: 18px; height: 18px; }

/* Loading */
.view-loading {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
}
.loader-container { text-align: center; }
.loader-ring {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--rust);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-container p { color: var(--text-secondary); }

/* Error */
.view-error {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
}
.error-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 40px;
  max-width: 420px; width: 100%; text-align: center;
}
.error-icon { width: 48px; height: 48px; color: var(--danger); margin: 0 auto 16px; }
.error-card h2 { margin-bottom: 8px; }
.error-card p { color: var(--text-secondary); margin-bottom: 24px; }

/* ── Toolbar ──────────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
}
.toolbar-left  { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.page-title { font-size: 1.35rem; font-weight: 700; }
.detail-sub-id { font-size: .8rem; color: var(--text-muted); font-family: monospace; }
.data-timestamp { font-size: .78rem; color: var(--text-muted); }

.filter-label  { font-size: .8rem; color: var(--text-secondary); }
.select-filter {
  background: var(--bg-card); border: 1.5px solid var(--border);
  border-radius: 6px; padding: 5px 10px;
  font-size: .85rem; color: var(--text-primary); cursor: pointer;
}
.select-filter:focus { outline: none; border-color: var(--deep); }

/* ── KPI Cards ────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-grid-4 { grid-template-columns: repeat(4, 1fr); }

.kpi-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 24px;
  display: flex; flex-direction: column; gap: 6px;
  border-left: 4px solid var(--border);
}
.kpi-total    { border-left-color: var(--deep); }
.kpi-forecast { border-left-color: var(--warning); }
.kpi-burnrate { border-left-color: var(--success); }

.kpi-label { font-size: .8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--text-primary); }
.kpi-sm    { font-size: 1.1rem; }
.kpi-delta { font-size: .8rem; font-weight: 500; }
.kpi-delta.up   { color: var(--danger); }
.kpi-delta.down { color: var(--success); }

/* ── Advisor Recommendations ──────────────────────────────────── */
.advisor-section {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 24px;
}
.advisor-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.advisor-title-group { display: flex; align-items: center; gap: 10px; }
.advisor-icon { width: 22px; height: 22px; color: var(--warning); flex-shrink: 0; }
.advisor-section-header h3 { font-size: .95rem; font-weight: 700; }
.advisor-savings-badge {
  background: #D1FAE5; color: #065F46;
  padding: 4px 12px; border-radius: 999px;
  font-size: .8rem; font-weight: 700;
  font-family: 'Raleway', sans-serif;
}
.advisor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.advisor-empty { color: var(--text-muted); font-size: .9rem; padding: 12px 0; }
.advisor-card {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  background: #FAFAFA; transition: box-shadow var(--transition);
}
.advisor-card:hover { box-shadow: var(--shadow-md); background: white; }
.advisor-card-header { display: flex; align-items: center; gap: 8px; }
.impact-badge { padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.impact-high   { background: #FEE2E2; color: #991B1B; }
.impact-medium { background: #FEF3C7; color: #92400E; }
.impact-low    { background: #DBEAFE; color: #1E40AF; }
.advisor-saving { margin-left: auto; font-size: .8rem; font-weight: 700; color: var(--success); }
.advisor-problem { font-size: .85rem; font-weight: 600; color: var(--text-primary); line-height: 1.45; }
.advisor-solution { font-size: .8rem; color: var(--text-secondary); line-height: 1.5; }
.advisor-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.advisor-resource-type {
  font-size: .72rem; background: #F3F4F6; color: var(--text-secondary);
  padding: 2px 6px; border-radius: 4px;
}
.advisor-resource-name {
  font-size: .82rem; color: var(--text-primary); font-family: monospace; font-weight: 700;
}
.advisor-resource {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.advisor-resource-name { word-break: break-all; }
.advisor-resource-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.advisor-resource-rg {
  font-size: .72rem; background: #FEF3C7; color: #92400E;
  padding: 2px 6px; border-radius: 4px; font-weight: 600;
}
.advisor-count-badge {
  margin-left: auto; font-size: .72rem; background: #E5E7EB; color: #374151;
  padding: 2px 8px; border-radius: 999px; font-weight: 700;
}
.advisor-items {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
  border-top: 1px solid var(--border); padding-top: 10px;
}
.advisor-items li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-size: .78rem;
}
.advisor-item-saving { margin-left: auto; color: var(--success); font-weight: 700; }
.advisor-more { color: var(--text-muted); font-style: italic; }
.advisor-description {
  font-size: .85rem; color: var(--text-primary); line-height: 1.45;
}
.advisor-savings {
  font-size: .82rem; font-weight: 700; color: var(--success);
}
.advisor-link { font-size: .78rem; color: var(--azure-blue); font-weight: 500; text-decoration: none; margin-top: 4px; }
.advisor-link:hover { text-decoration: underline; }

/* ── Matrice costi storici ────────────────────────────────────── */
.matrix-section {
  display: flex; flex-direction: column; gap: 24px;
  background: transparent; border: none; padding: 0; margin-top: 20px;
}
.matrix-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.matrix-block {
  background: white; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.matrix-block-title {
  font-size: .82rem; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px;
  padding-bottom: 10px; border-bottom: 2px solid var(--azure-blue);
}
.matrix-scroll { overflow-x: auto; }
.matrix-table { min-width: 100%; border-collapse: collapse; font-size: .85rem; }
.matrix-table th,
.matrix-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  text-align: right; white-space: nowrap;
}
.matrix-table thead th {
  background: #F9FAFB; font-weight: 700; color: var(--text-secondary);
  font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  text-align: right;
}
.matrix-table th:first-child,
.matrix-table td:first-child,
.matrix-table thead th:first-child {
  text-align: left; font-weight: 600;
  position: sticky; left: 0; background: white; z-index: 1;
}
.matrix-table thead th:first-child { background: #F9FAFB; }
.matrix-table tfoot td {
  font-weight: 700; background: #F9FAFB; border-top: 2px solid var(--border);
}
.matrix-table th.matrix-extra,
.matrix-table td.matrix-extra {
  text-align: left; font-weight: 500; color: var(--text-secondary);
}
.matrix-cell { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; line-height: 1.2; }
.matrix-cost { font-weight: 600; color: var(--text-primary); }
.matrix-delta { font-size: .72rem; font-weight: 600; }
.matrix-delta.up { color: #B91C1C; }
.matrix-delta.down { color: #047857; }
.matrix-delta.flat { color: var(--text-secondary); }

/* ── Charts ───────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
.charts-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
}

.chart-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 24px;
}
.chart-wide { grid-column: 1 / -1; }

.chart-title { font-size: .9rem; font-weight: 600; margin-bottom: 16px; color: var(--text-primary); }
.chart-wrap  { position: relative; height: 240px; }
.chart-wrap-sm { height: 200px; }

/* ── Tables ───────────────────────────────────────────────────── */
.tables-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.table-card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.table-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-size: .9rem; font-weight: 600;
}
.table-scroll { overflow-x: auto; }

.data-table {
  width: 100%; border-collapse: collapse; font-size: .875rem;
}
.data-table th {
  background: var(--mist); padding: 10px 16px;
  text-align: left; font-size: .78rem; font-weight: 700;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  font-family: 'Libre Franklin', sans-serif;
}
.data-table td {
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--paper); }
.row-loading td { opacity: .65; }

/* Dettaglio RG: prima colonna a sinistra (nome), resto a destra */
.detail-rg-table th,
.detail-rg-table td { text-align: right; }
.detail-rg-table th:first-child,
.detail-rg-table td:first-child { text-align: left; }

/* Dettaglio Servizio: prime due colonne a sinistra (servizio + RG), resto a destra */
.detail-svc-table th,
.detail-svc-table td { text-align: right; }
.detail-svc-table th:nth-child(1),
.detail-svc-table td:nth-child(1),
.detail-svc-table th:nth-child(2),
.detail-svc-table td:nth-child(2) { text-align: left; }

/* Skeleton shimmer per celle in caricamento */
.skeleton-text {
  display: inline-block; width: 80px; height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border) 25%, var(--mist) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.table-empty { text-align: center; color: var(--text-muted); padding: 32px !important; }

/* Cost cells */
.cost-cell { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.cost-ok      { color: var(--success); }
.cost-warning { color: var(--warning); }
.cost-danger  { color: var(--danger); }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 600; letter-spacing: .03em;
}
.badge-own        { background: var(--mist); color: var(--deep); }
.badge-lighthouse { background: rgba(19,75,95,.12); color: var(--petrol); }
.badge-enabled    { background: #D1FAE5; color: #065F46; }
.badge-disabled   { background: #F3F4F6; color: var(--text-muted); }

/* ── Toast ────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px; z-index: 9999;
}
.toast {
  background: var(--text-primary); color: white;
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: .875rem; max-width: 320px;
  box-shadow: var(--shadow-md);
  animation: slideIn .25s ease;
}
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--success); }
@keyframes slideIn { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform: none; } }

/* Print report header (visible only during stampa) */
.print-page-header { display: none; }

@media print {
  @page { size: A4; margin: 12mm; }

  body {
    background: #fff !important;
    color: #111827;
  }
  body::after,
  .app-header,
  .app-footer,
  #toastContainer,
  #viewLogin,
  #viewLoading,
  #viewOverview,
  #viewError,
  #viewAdmin,
  #viewMatrix,
  body.printing #viewDetail > .toolbar,
  body.printing #viewDetail .advisor-section {
    display: none !important;
  }

  /* Trucco table-header-group: l'header viene ripetuto in cima ad ogni pagina
     stampata senza coprire il contenuto (riserva spazio nel flusso). */
  body.printing {
    display: table;
    width: 100%;
  }
  body.printing .app-main {
    display: table-row-group;
    max-width: none;
    padding: 0;
  }

  .print-page-header {
    display: table-header-group !important;
  }
  .print-page-header__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12mm;
    padding: 0 0 4mm 0;
    margin-bottom: 6mm;
    border-bottom: 1px solid #D1D5DB;
  }
  .print-page-header__left,
  .print-page-header__right {
    height: 12mm;
    width: auto;
    max-width: 35mm;
    object-fit: contain;
    flex: 0 0 auto;
  }
  .print-page-header__title {
    flex: 1 1 auto;
    text-align: center;
    font-family: 'Libre Franklin', sans-serif;
    font-size: 16pt;
    font-weight: 800;
    color: #25282A;
    letter-spacing: 0.01em;
    text-transform: uppercase;
  }

  body.printing .kpi-card,
  body.printing .chart-card,
  body.printing .table-card {
    box-shadow: none;
    border: 1px solid #D1D5DB;
    break-inside: avoid;
  }

  body.printing .charts-grid,
  body.printing .charts-grid-3,
  body.printing .tables-row,
  body.printing .kpi-grid,
  body.printing .kpi-grid-3,
  body.printing .kpi-grid-4 {
    gap: 8px;
  }

  /* Fit-to-A4: blocca larghezza, evita overflow a destra */
  body.printing {
    table-layout: fixed;
    max-width: 100%;
  }
  body.printing .app-main,
  body.printing .view,
  body.printing .kpi-grid,
  body.printing .kpi-grid-3,
  body.printing .kpi-grid-4,
  body.printing .charts-grid,
  body.printing .charts-grid-3,
  body.printing .tables-row,
  body.printing .kpi-card,
  body.printing .chart-card,
  body.printing .table-card {
    max-width: 100%;
    box-sizing: border-box;
  }
  body.printing .kpi-grid-4,
  body.printing .kpi-grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
  body.printing .charts-grid-3,
  body.printing .charts-grid {
    grid-template-columns: 1fr;
  }
  body.printing .chart-card { padding: 10px 12px; }
  body.printing .chart-card canvas { max-width: 100% !important; height: auto !important; }
  body.printing .kpi-card { padding: 10px 12px; }
  body.printing .kpi-value { font-size: 1.2rem; }
  body.printing .kpi-sm { font-size: .95rem; }

  /* Allineamento a destra di label e valori */
  body.printing .kpi-card,
  body.printing .kpi-label,
  body.printing .kpi-value,
  body.printing .kpi-delta,
  body.printing .kpi-sm {
    text-align: right;
    align-items: flex-end;
  }
  body.printing .data-table th,
  body.printing .data-table td {
    text-align: right;
  }
  body.printing .data-table th:first-child,
  body.printing .data-table td:first-child {
    text-align: left;
  }
}

/* ── Responsive ───────────────────────────────────────────────── */

/* Hamburger + drawer infrastructure (visible only on mobile breakpoint) */
.nav-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  padding: 8px; border-radius: 6px;
  color: #F8F7F2; align-items: center; justify-content: center;
  margin-right: 4px;
}
.nav-toggle:hover { background: rgba(248,247,242,.1); }
.nav-toggle svg { width: 22px; height: 22px; display: block; }
.nav-backdrop {
  display: none;
  position: fixed; inset: 60px 0 0 0;
  background: rgba(15,18,20,.45);
  z-index: 90;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

/* Tablet (≤ 1024) */
@media (max-width: 1024px) {
  .app-main      { padding: 20px; }
  .charts-grid   { grid-template-columns: 1fr; }
  .charts-grid-3 { grid-template-columns: 1fr 1fr; }
  .tables-row    { grid-template-columns: 1fr; }
}

/* Tablet portrait / large mobile (≤ 900) */
@media (max-width: 900px) {
  .charts-grid-3 { grid-template-columns: 1fr; }
  .kpi-grid-3, .kpi-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .app-main      { padding: 16px; }
  .toolbar-right { gap: 8px; }
}

/* Mobile (≤ 720) — drawer e adattamenti completi */
@media (max-width: 720px) {
  html { font-size: 14px; }

  .app-header {
    padding: 0 14px;
    height: 56px;
    gap: 8px;
  }
  .brand-sub { display: none; }
  .brand-icon { height: 26px; }

  .nav-toggle { display: inline-flex !important; }
  .nav-backdrop { display: block; inset: 56px 0 0 0; }

  /* Drawer */
  .header-nav {
    position: fixed;
    top: 56px; left: 0;
    width: min(82vw, 320px);
    height: calc(100vh - 56px);
    background: var(--ink);
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 16px 12px;
    box-shadow: 4px 0 16px rgba(0,0,0,.25);
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 95;
    overflow-y: auto;
  }
  body.nav-open .header-nav { transform: translateX(0); }
  .nav-btn {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: .95rem;
    text-align: left;
    width: 100%;
  }

  .header-actions { gap: 6px; }
  .header-actions .btn-primary,
  .header-actions .btn-outline { padding: 6px 12px; font-size: .8rem; }
  .user-name { display: none; }

  .app-main { padding: 14px; }

  /* Toolbar verticale */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .toolbar-left,
  .toolbar-right {
    width: 100%;
    flex-wrap: wrap;
  }
  .toolbar-right { gap: 8px; }
  .select-filter { flex: 1 1 140px; min-width: 0; padding: 8px 10px; font-size: .9rem; }
  .filter-label  { flex: 0 0 auto; }
  .btn-outline, .btn-primary {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 38px;
  }
  .btn-back { padding: 8px 10px; }

  .page-title { font-size: 1.15rem; }

  /* KPI: 1 colonna piena su mobile */
  .kpi-grid,
  .kpi-grid-3,
  .kpi-grid-4 { grid-template-columns: 1fr; gap: 12px; }
  .kpi-card { padding: 16px 18px; }
  .kpi-value { font-size: 1.45rem; }

  /* Charts compatti */
  .chart-card { padding: 16px 14px; }
  .chart-wrap { height: 220px; }
  .chart-wrap-sm { height: 180px; }

  /* Advisor: 1 colonna */
  .advisor-grid { grid-template-columns: 1fr; }
  .advisor-section { padding: 16px 14px; }

  /* Tabelle: scroll orizzontale sempre disponibile + tap target maggiori */
  .table-card { border-radius: var(--radius); }
  .table-header { padding: 14px 14px; flex-wrap: wrap; gap: 8px; }
  .data-table { font-size: .82rem; }
  .data-table th,
  .data-table td { padding: 10px 12px; }
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Matrice scorrevole con gradient hint */
  .matrix-block { padding: 14px; }
  .matrix-table { font-size: .8rem; }
  .matrix-table th,
  .matrix-table td { padding: 6px 10px; }

  /* Login card compatta */
  .login-card { padding: 36px 24px; border-radius: 12px; }
  .login-card h1 { font-size: 1.3rem; }
  .btn-large { padding: 12px 20px; font-size: .95rem; width: 100%; justify-content: center; }

  /* Toast: full-width in basso */
  .toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
}

/* Mobile small (≤ 420) */
@media (max-width: 420px) {
  .header-brand > div { display: none; }
  .header-actions .btn-outline { display: none; } /* "Esci" -> resta in drawer eventualmente */
  .data-timestamp { font-size: .72rem; }
}

/* Touch target hint: ingrandisco un po' i bottoni primari su touch */
@media (hover: none) and (pointer: coarse) {
  .nav-btn { min-height: 44px; }
  .btn-primary, .btn-outline, .btn-back, .btn-icon { min-height: 40px; }
  .select-filter { min-height: 40px; }
}
