/* ============================================================
   YoPlan — Design System
   Principi: componenti consistenti, tipografia forte,
   niente decorazioni gratuite, zero gradienti superflui.
   ============================================================ */

/* ─── Token ─────────────────────────────────────────────── */
:root {
  --c-bg:         #f5f5f4;
  --c-surface:    #ffffff;
  --c-border:     #e7e5e4;
  --c-border-2:   #d6d3d1;
  --c-text-1:     #1c1917;
  --c-text-2:     #57534e;
  --c-text-3:     #a8a29e;
  --c-accent:     #2563eb;
  --c-accent-bg:  #eff6ff;
  --c-accent-border: #bfdbfe;
  --c-green:      #16a34a;
  --c-green-bg:   #f0fdf4;
  --c-red:        #dc2626;
  --c-red-bg:     #fef2f2;
  --c-amber:      #d97706;
  --c-amber-bg:   #fffbeb;
  --sidebar-w:    240px;
  --topbar-h:     52px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  --r-sm: 4px; --r-md: 6px; --r-lg: 8px;
  --shadow:    0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --t: 120ms ease;
}

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: var(--font); font-size: 1rem; line-height: 1.6;
  color: var(--c-text-1); background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ─── Layout ─────────────────────────────────────────────── */
.app-layout  { display: flex; min-height: 100vh; }
.app-main    { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.app-content { padding: 24px; flex: 1; }

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--c-text-1);
  display: flex; flex-direction: column;
  z-index: 200;
  border-right: 1px solid rgba(255,255,255,.05);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 9px;
  padding: 0 16px; height: var(--topbar-h);
  border-bottom: 1px solid rgba(255,255,255,.06);
  text-decoration: none;
}
.sidebar-logo-mark {
  width: 26px; height: 26px; background: var(--c-accent);
  border-radius: var(--r-sm); display: grid; place-items: center;
  flex-shrink: 0; color: #fff; font-size: .75rem;
}
.sidebar-logo-name { font-size: .9375rem; font-weight: 700; color: #fff; letter-spacing: -.02em; }
.sidebar-company { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar-company-name { font-size: .8125rem; font-weight: 600; color: rgba(255,255,255,.85); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-company-plan { font-size: .6875rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: #93c5fd; margin-top: 1px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; scrollbar-width: none; }
.sidebar-nav::-webkit-scrollbar { display: none; }
.sidebar-section { margin-bottom: 20px; }
.sidebar-section-label { font-size: .625rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: rgba(255,255,255,.22); padding: 0 8px 4px; display: block; }
.sidebar-link {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: var(--r-md);
  font-size: .875rem; font-weight: 500;
  color: rgba(255,255,255,.45); text-decoration: none;
  transition: color var(--t), background var(--t);
  margin-bottom: 1px; line-height: 1;
}
.sidebar-link i { font-size: .9375rem; flex-shrink: 0; width: 18px; }
.sidebar-link span { flex: 1; }
.sidebar-link:hover { color: rgba(255,255,255,.9); background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar-link.active { color: #fff; background: rgba(255,255,255,.1); }
.sidebar-token { font-size: .6875rem; font-weight: 600; background: rgba(37,99,235,.25); color: #93c5fd; padding: 2px 7px; border-radius: 20px; flex-shrink: 0; }
.sidebar-footer { padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.06); display: flex; align-items: center; gap: 8px; }
.sidebar-footer-notif { position: relative; width: 32px; height: 32px; border-radius: var(--r-md); display: grid; place-items: center; color: rgba(255,255,255,.4); font-size: .9375rem; text-decoration: none; flex-shrink: 0; transition: color var(--t); }
.sidebar-footer-notif:hover { color: #fff; text-decoration: none; }
.sidebar-footer-notif-dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; background: var(--c-red); border-radius: 50%; border: 1.5px solid var(--c-text-1); }
.sidebar-user-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: var(--r-md); text-align: left; transition: background var(--t); }
.sidebar-user-btn::after { display: none !important; }
.sidebar-user-btn:hover { background: rgba(255,255,255,.07); }
.sidebar-user-avatar { width: 28px; height: 28px; border-radius: var(--r-sm); background: rgba(255,255,255,.15); display: grid; place-items: center; font-size: .6875rem; font-weight: 700; color: rgba(255,255,255,.8); flex-shrink: 0; letter-spacing: .03em; }
.sidebar-user-name { font-size: .8125rem; font-weight: 600; color: rgba(255,255,255,.75); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: .6875rem; color: rgba(255,255,255,.3); text-transform: capitalize; }

/* ─── Topbar ─────────────────────────────────────────────── */
.topbar { height: var(--topbar-h); background: var(--c-surface); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 100; flex-shrink: 0; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-search { display: flex; align-items: center; gap: 6px; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: 5px 10px; width: 240px; }
.topbar-search i { color: var(--c-text-3); font-size: .875rem; }
.topbar-search input { background: none; border: none; outline: none; font-family: var(--font); font-size: .8125rem; color: var(--c-text-1); flex: 1; min-width: 0; }
.topbar-search input::placeholder { color: var(--c-text-3); }
.topbar-search:focus-within { border-color: var(--c-accent); background: var(--c-surface); }
.topbar-search kbd { font-family: var(--font-mono); font-size: .625rem; color: var(--c-text-3); background: var(--c-border); padding: 1px 5px; border-radius: 3px; }
.topbar-icon-btn { position: relative; width: 32px; height: 32px; border-radius: var(--r-md); display: grid; place-items: center; color: var(--c-text-2); font-size: .9375rem; text-decoration: none; transition: background var(--t), color var(--t); }
.topbar-icon-btn:hover { background: var(--c-bg); color: var(--c-text-1); text-decoration: none; }
.topbar-icon-btn-dot { position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; background: var(--c-red); border-radius: 50%; border: 1.5px solid var(--c-surface); }
.topbar-ai-badge { display: flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; color: var(--c-accent); background: var(--c-accent-bg); border: 1px solid var(--c-accent-border); padding: 3px 10px; border-radius: 20px; text-decoration: none; transition: background var(--t); }
.topbar-ai-badge:hover { background: #dbeafe; text-decoration: none; }
.topbar-menu-btn { width: 32px; height: 32px; background: none; border: 1px solid var(--c-border); border-radius: var(--r-md); display: grid; place-items: center; cursor: pointer; color: var(--c-text-2); font-size: 1.0625rem; transition: background var(--t); }
.topbar-menu-btn:hover { background: var(--c-bg); }

/* ─── Flash ──────────────────────────────────────────────── */
.flash-wrap { padding: 0 24px; margin-top: 16px; }
.alert { border-radius: var(--r-md); font-size: .875rem; padding: 10px 14px; }

/* ─── Breadcrumb ─────────────────────────────────────────── */
.breadcrumb { margin: 0; padding: 0; font-size: .8125rem; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--c-text-3); }
.breadcrumb-item a { color: var(--c-text-3); text-decoration: none; }
.breadcrumb-item a:hover { color: var(--c-text-2); }
.breadcrumb-item.active { color: var(--c-text-2); font-weight: 500; }

/* ─── Page header ────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: 1.3125rem; font-weight: 700; letter-spacing: -.025em; color: var(--c-text-1); margin: 0; line-height: 1.2; }
.page-subtitle { font-size: .8125rem; color: var(--c-text-3); margin: 3px 0 0; line-height: 1.5; }
.page-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; flex-wrap: wrap; }

/* ─── Card ───────────────────────────────────────────────── */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); overflow: hidden; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: .9375rem; font-weight: 600; color: var(--c-text-1); margin: 0; letter-spacing: -.01em; }
.card-body { padding: 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--c-border); background: var(--c-bg); }

/* ─── Stat ───────────────────────────────────────────────── */
.stat { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); padding: 18px; }
.stat-label { font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-text-3); margin-bottom: 6px; }
.stat-value { font-size: 1.625rem; font-weight: 700; letter-spacing: -.04em; color: var(--c-text-1); line-height: 1; }
.stat-delta { font-size: .75rem; font-weight: 500; color: var(--c-text-3); margin-top: 5px; display: flex; align-items: center; gap: 3px; }
.stat-delta.up { color: var(--c-green); }
.stat-delta.down { color: var(--c-red); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font); font-size: .875rem; font-weight: 600;
  border-radius: var(--r-md); padding: 6px 12px;
  border: 1px solid transparent; cursor: pointer;
  text-decoration: none; line-height: 1.4; white-space: nowrap;
  transition: background var(--t), border-color var(--t), color var(--t);
}
.btn i { font-size: .9375rem; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--c-text-1); border-color: var(--c-text-1); color: #fff; }
.btn-primary:hover { background: #292524; border-color: #292524; color: #fff; }
.btn-secondary, .btn-ghost { background: var(--c-surface); border-color: var(--c-border-2); color: var(--c-text-2); }
.btn-secondary:hover, .btn-ghost:hover { background: var(--c-bg); color: var(--c-text-1); }
.btn-danger { background: var(--c-red-bg); border-color: #fca5a5; color: var(--c-red); }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: var(--c-green-bg); border-color: #86efac; color: var(--c-green); }
.btn-success:hover { background: #dcfce7; }
.btn-accent { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
.btn-accent:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.btn-sm { font-size: .8125rem; padding: 4px 9px; }
.btn-sm i { font-size: .875rem; }
.btn-lg { font-size: .9375rem; padding: 8px 16px; }
.btn-icon { padding: 5px; width: 32px; height: 32px; justify-content: center; }
.btn-icon.btn-sm { width: 28px; height: 28px; padding: 4px; }
.btn-block { width: 100%; justify-content: center; }

/* ─── Badge ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  font-family: var(--font); font-size: .6875rem; font-weight: 600;
  letter-spacing: .02em; padding: 2px 8px;
  border-radius: var(--r-sm); border: 1px solid;
}
.badge-green   { background: var(--c-green-bg);  color: var(--c-green);  border-color: #86efac; }
.badge-red     { background: var(--c-red-bg);    color: var(--c-red);    border-color: #fca5a5; }
.badge-amber   { background: var(--c-amber-bg);  color: var(--c-amber);  border-color: #fcd34d; }
.badge-blue    { background: var(--c-accent-bg); color: var(--c-accent); border-color: #93c5fd; }
.badge-neutral { background: var(--c-bg);        color: var(--c-text-2); border-color: var(--c-border-2); }

/* ─── Table ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table thead th { padding: 8px 12px; text-align: left; font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-text-3); background: var(--c-bg); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t); }
.table tbody tr:hover { background: var(--c-bg); }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table .col-num { text-align: right; }
.table .cell-mono { font-family: var(--font-mono); font-size: .8125rem; }

/* ─── Forms ──────────────────────────────────────────────── */
.form-label { display: block; font-size: .8125rem; font-weight: 600; color: var(--c-text-2); margin-bottom: 5px; }
.form-hint  { font-size: .75rem; color: var(--c-text-3); margin-top: 4px; }
.form-control, .form-select { display: block; width: 100%; font-family: var(--font); font-size: .875rem; color: var(--c-text-1); background: var(--c-surface); border: 1px solid var(--c-border-2); border-radius: var(--r-md); padding: 6px 10px; line-height: 1.5; transition: border-color var(--t), box-shadow var(--t); }
.form-control:focus, .form-select:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-control::placeholder { color: var(--c-text-3); }
.form-control-lg { font-size: .9375rem; padding: 8px 12px; }
.form-control[readonly] { background: var(--c-bg); color: var(--c-text-2); cursor: default; }
.input-group { display: flex; }
.input-group .form-control { flex: 1; }
.input-group .form-control:not(:first-child) { border-left: none; border-radius: 0 var(--r-md) var(--r-md) 0; }
.input-group .form-control:not(:last-child) { border-radius: var(--r-md) 0 0 var(--r-md); }
.input-group-text { display: flex; align-items: center; padding: 6px 10px; font-size: .8125rem; color: var(--c-text-3); background: var(--c-bg); border: 1px solid var(--c-border-2); }
.input-group-text:first-child { border-right: none; border-radius: var(--r-md) 0 0 var(--r-md); }
.input-group-text:last-child  { border-left:  none; border-radius: 0 var(--r-md) var(--r-md) 0; }
.form-check { display: flex; align-items: center; gap: 7px; }
.form-check-input { width: 15px; height: 15px; flex-shrink: 0; cursor: pointer; accent-color: var(--c-accent); }
.form-check-label { font-size: .875rem; color: var(--c-text-2); cursor: pointer; }
textarea.form-control { resize: vertical; }

/* ─── Modal — struttura fissa, identica in tutta l'app ────── */
.modal { z-index: 1050; }
.modal-dialog     { max-width: 480px; margin: 48px auto; padding: 0 16px; }
.modal-dialog-lg  { max-width: 680px; }
.modal-dialog-sm  { max-width: 360px; }
.modal-content {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
}
.modal-title { font-size: .9375rem; font-weight: 600; color: var(--c-text-1); margin: 0; letter-spacing: -.01em; }
.modal-body   { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--c-border); background: var(--c-bg); }
/* Bootstrap .btn-close override */
.btn-close { filter: none; opacity: .4; transition: opacity var(--t); }
.btn-close:hover { opacity: 1; }

/* ─── Progress ───────────────────────────────────────────── */
.progress { height: 5px; background: var(--c-border); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--c-accent); border-radius: 99px; transition: width .5s ease; }
.progress-bar.green { background: var(--c-green); }

/* ─── Empty state ────────────────────────────────────────── */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 56px 24px; }
.empty-icon { width: 44px; height: 44px; border-radius: var(--r-lg); background: var(--c-bg); display: grid; place-items: center; font-size: 1.125rem; color: var(--c-text-3); margin-bottom: 14px; border: 1px solid var(--c-border); }
.empty-title { font-size: 1rem; font-weight: 600; color: var(--c-text-1); margin-bottom: 6px; }
.empty-text  { font-size: .875rem; color: var(--c-text-3); max-width: 320px; margin-bottom: 20px; line-height: 1.65; }

/* ─── Overlay mobile ─────────────────────────────────────── */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199; }
.overlay.open { display: block; }

/* ─── Preventivo builder ─────────────────────────────────── */
.voce-row { display: grid; grid-template-columns: 24px 56px 1fr 64px 96px 96px 72px 28px; gap: 6px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--c-border); }
.voce-row:last-child { border-bottom: none; }
.voce-handle { color: var(--c-text-3); cursor: grab; display: grid; place-items: center; }
.voce-handle:active { cursor: grabbing; }
.voce-total { font-size: .8125rem; font-weight: 600; text-align: right; font-family: var(--font-mono); }
.quote-totals { border-top: 1px solid var(--c-border); padding-top: 14px; margin-top: 4px; }
.quote-totals-row { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; font-size: .875rem; color: var(--c-text-2); }
.quote-totals-row.grand { font-size: 1rem; font-weight: 700; color: var(--c-text-1); border-top: 1px solid var(--c-border); padding-top: 10px; margin-top: 6px; }

/* ─── Firma digitale ─────────────────────────────────────── */
.firma-canvas { display: block; width: 100%; height: 150px; border: 1px dashed var(--c-border-2); border-radius: var(--r-md); cursor: crosshair; touch-action: none; background: var(--c-bg); }
.firma-canvas.signed { border-style: solid; border-color: var(--c-green); background: var(--c-surface); }

/* ─── Gantt overrides ────────────────────────────────────── */
.gantt .grid-background { fill: var(--c-surface); }
.gantt .grid-header      { fill: var(--c-bg); }
.gantt .grid-row         { fill: transparent; }
.gantt .grid-row:nth-child(even) { fill: rgba(0,0,0,.015); }
.gantt .row-line, .gantt .tick { stroke: var(--c-border); stroke-width: 1; }
.gantt .today-highlight  { fill: rgba(37,99,235,.04); }
.gantt .lower-text, .gantt .upper-text { font-family: var(--font) !important; font-size: 11px !important; fill: var(--c-text-3) !important; font-weight: 500 !important; }
.gantt .upper-text { font-size: 11px !important; font-weight: 700 !important; fill: var(--c-text-2) !important; }
.gantt .bar { rx: 3; ry: 3; }
.gantt .bar-label { font-family: var(--font) !important; font-size: 11px !important; font-weight: 600 !important; fill: rgba(255,255,255,.95) !important; }
.gantt .arrow { stroke: var(--c-text-3); stroke-width: 1.5; fill: none; }
#ganttContainer { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--c-surface); padding: 4px 0; }
#ganttContainer::-webkit-scrollbar { height: 5px; }
#ganttContainer::-webkit-scrollbar-track { background: var(--c-bg); }
#ganttContainer::-webkit-scrollbar-thumb { background: var(--c-border-2); border-radius: 99px; }
.gantt-popup { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 14px; min-width: 200px; font-family: var(--font); }
.gantt-popup-title { font-size: .875rem; font-weight: 600; color: var(--c-text-1); margin-bottom: 8px; }
.gantt-popup-row { display: flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--c-text-3); margin-bottom: 4px; }
.gantt-popup-progress { height: 4px; background: var(--c-border); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.gantt-popup-progress-bar { height: 100%; background: var(--c-accent); border-radius: 99px; }
.gantt-popup-btn { width: 100%; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--r-sm); padding: 5px 10px; font-family: var(--font); font-size: .75rem; font-weight: 600; color: var(--c-text-2); cursor: pointer; display: flex; align-items: center; gap: 5px; justify-content: center; transition: background var(--t), color var(--t); margin-top: 8px; }
.gantt-popup-btn:hover { background: var(--c-text-1); color: #fff; border-color: var(--c-text-1); }

/* ─── AI panel ───────────────────────────────────────────── */
.ai-panel { background: var(--c-accent-bg); border: 1px solid var(--c-accent-border); border-radius: var(--r-lg); padding: 16px; }
.ai-token-track { height: 5px; background: var(--c-border); border-radius: 99px; overflow: hidden; }
.ai-token-fill  { height: 100%; background: var(--c-accent); border-radius: 99px; transition: width .5s ease; }

/* ─── Utility ────────────────────────────────────────────── */
.mono    { font-family: var(--font-mono); }
.fw-5    { font-weight: 500; }
.fw-6    { font-weight: 600; }
.fw-7    { font-weight: 700; }
.t-muted { color: var(--c-text-3); }
.t-green { color: var(--c-green); }
.t-red   { color: var(--c-red); }
.t-amber { color: var(--c-amber); }
.t-blue  { color: var(--c-accent); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.divider  { height: 1px; background: var(--c-border); margin: 16px 0; }
.section-label { font-size: .6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--c-text-3); margin-bottom: 10px; }
.inset-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; border-bottom: 1px solid var(--c-border); font-size: .875rem; }
.inset-row:last-child { border-bottom: none; }
.inset-row-label { color: var(--c-text-3); font-size: .8125rem; }
.inset-row-value { font-weight: 600; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .topbar, .app-content { padding-left: 16px; padding-right: 16px; }
  .flash-wrap { padding: 0 16px; }
}
@media (max-width: 767.98px) {
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-title  { font-size: 1.125rem; }
  .voce-row    { grid-template-columns: 1fr; }
  .modal-dialog { padding: 0 12px; margin-top: 24px; }
}
@media (min-width: 768px) and (max-width: 1199.98px) {
  .btn { min-height: 36px; }
  .btn-icon { min-width: 40px; min-height: 40px; width: 40px; height: 40px; }
}
@media print {
  .sidebar, .topbar, .flash-wrap { display: none !important; }
  .app-main { margin-left: 0 !important; }
  .app-content { padding: 0 !important; }
}

/* ─── Alias compatibilità classi precedenti (yp-*) ───────── */
.yp-layout, body.yp-layout { display: flex; min-height: 100vh; }
.yp-main    { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.yp-content { padding: 24px; flex: 1; }
.yp-topbar  { height: var(--topbar-h); background: var(--c-surface); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 100; flex-shrink: 0; }
.yp-topbar-left, .yp-topbar-right { display: flex; align-items: center; gap: 8px; }
.yp-flash-container { padding: 0 24px; margin-top: 16px; }
.yp-card         { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); overflow: hidden; }
.yp-card-header  { padding: 14px 18px; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.yp-card-title   { font-size: .9375rem; font-weight: 600; color: var(--c-text-1); margin: 0; letter-spacing: -.01em; }
.yp-card-body    { padding: 18px; }
.yp-card-footer  { padding: 12px 18px; border-top: 1px solid var(--c-border); background: var(--c-bg); }
.yp-stat         { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); padding: 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.yp-stat-label   { font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-text-3); margin-bottom: 6px; }
.yp-stat-value   { font-size: 1.625rem; font-weight: 700; letter-spacing: -.04em; color: var(--c-text-1); line-height: 1; }
.yp-stat-delta   { font-size: .75rem; font-weight: 500; color: var(--c-text-3); margin-top: 5px; }
.yp-stat-delta.up   { color: var(--c-green); }
.yp-stat-delta.down { color: var(--c-red); }
.yp-stat-icon    { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; font-size: 1.1rem; flex-shrink: 0; }
.yp-page-header  { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.yp-page-title   { font-size: 1.3125rem; font-weight: 700; letter-spacing: -.025em; color: var(--c-text-1); margin: 0; line-height: 1.2; }
.yp-page-subtitle { font-size: .8125rem; color: var(--c-text-3); margin: 3px 0 0; }
.yp-page-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; flex-wrap: wrap; }
.yp-table-wrap   { overflow-x: auto; }
.yp-table        { width: 100%; border-collapse: collapse; font-size: .875rem; }
.yp-table thead th { padding: 8px 12px; text-align: left; font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-text-3); background: var(--c-bg); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.yp-table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.yp-table tbody tr:last-child td { border-bottom: none; }
.yp-table tbody tr { transition: background var(--t); }
.yp-table tbody tr:hover { background: var(--c-bg); }
.yp-table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.yp-empty        { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 56px 24px; }
.yp-empty-icon   { width: 44px; height: 44px; border-radius: var(--r-lg); background: var(--c-bg); display: grid; place-items: center; font-size: 1.125rem; color: var(--c-text-3); margin-bottom: 14px; border: 1px solid var(--c-border); }
.yp-empty-title  { font-size: 1rem; font-weight: 600; color: var(--c-text-1); margin-bottom: 6px; }
.yp-empty-text   { font-size: .875rem; color: var(--c-text-3); max-width: 320px; margin-bottom: 20px; line-height: 1.65; }
.yp-progress     { height: 5px; background: var(--c-border); border-radius: 99px; overflow: hidden; }
.yp-progress-bar { height: 100%; background: var(--c-accent); border-radius: 99px; transition: width .5s ease; }
.yp-section-title { font-size: .6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--c-text-3); margin-bottom: 10px; }
.yp-divider      { height: 1px; background: var(--c-border); margin: 16px 0; }
.yp-prev-totali  { border-top: 1px solid var(--c-border); padding-top: 14px; margin-top: 4px; }
.yp-prev-totale-row { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; font-size: .875rem; color: var(--c-text-2); }
.yp-prev-totale-row.grand { font-size: 1rem; font-weight: 700; color: var(--c-text-1); border-top: 1px solid var(--c-border); padding-top: 10px; margin-top: 6px; }
.yp-firma-canvas { display: block; width: 100%; height: 150px; border: 1px dashed var(--c-border-2); border-radius: var(--r-md); cursor: crosshair; touch-action: none; background: var(--c-bg); }
.yp-firma-canvas.signed { border-style: solid; border-color: var(--c-green); background: var(--c-surface); }
.yp-overlay      { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199; }
.yp-overlay.show { display: block; }
.yp-token-bar    { display: flex; align-items: center; gap: 8px; }
.yp-token-bar-track { flex: 1; height: 5px; background: var(--c-border); border-radius: 99px; overflow: hidden; }
.yp-token-bar-fill  { height: 100%; background: var(--c-accent); border-radius: 99px; }
.yp-ai-panel     { background: var(--c-accent-bg); border: 1px solid var(--c-accent-border); border-radius: var(--r-lg); padding: 16px; }
.yp-sidebar      { position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh; background: var(--c-text-1); display: flex; flex-direction: column; z-index: 200; }
.yp-brand        { display: flex; align-items: center; gap: 9px; padding: 0 16px; height: var(--topbar-h); border-bottom: 1px solid rgba(255,255,255,.06); text-decoration: none; }
.yp-brand-mark   { width: 26px; height: 26px; background: var(--c-accent); border-radius: var(--r-sm); display: grid; place-items: center; flex-shrink: 0; color: #fff; font-size: .75rem; }
.yp-brand-name   { font-size: .9375rem; font-weight: 700; color: #fff; }
.yp-voce-row-wrap { border-bottom: 1px solid var(--c-border); padding: 8px 0; }
/* Badge status map */
.badge.bg-success-subtle  { background: var(--c-green-bg) !important; color: var(--c-green) !important; border: 1px solid #86efac; }
.badge.bg-danger-subtle   { background: var(--c-red-bg)   !important; color: var(--c-red)   !important; border: 1px solid #fca5a5; }
.badge.bg-warning-subtle  { background: var(--c-amber-bg) !important; color: var(--c-amber) !important; border: 1px solid #fcd34d; }
.badge.bg-primary-subtle  { background: var(--c-accent-bg)!important; color: var(--c-accent)!important; border: 1px solid #93c5fd; }
.badge.bg-secondary-subtle{ background: var(--c-bg)       !important; color: var(--c-text-2)!important; border: 1px solid var(--c-border-2); }
.badge.bg-info-subtle     { background: #ecfeff           !important; color: #0891b2        !important; border: 1px solid #a5f3fc; }
.text-success { color: var(--c-green)  !important; }
.text-danger  { color: var(--c-red)    !important; }
.text-warning { color: var(--c-amber)  !important; }
.text-primary { color: var(--c-accent) !important; }
/* btn-outline-primary override */
.btn-outline-primary { background: var(--c-surface); border-color: var(--c-accent); color: var(--c-accent); }
.btn-outline-primary:hover { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
/* Gantt touch targets */
.gantt-touch-btn { min-height: 36px; min-width: 36px; }
/* Token pill (topbar) */
.yp-ai-pill { display: flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; color: var(--c-accent); background: var(--c-accent-bg); border: 1px solid var(--c-accent-border); padding: 3px 10px; border-radius: 20px; text-decoration: none; }
.yp-topbar-icon { position: relative; width: 32px; height: 32px; border-radius: var(--r-md); display: grid; place-items: center; color: var(--c-text-2); font-size: .9375rem; text-decoration: none; }
.yp-topbar-icon:hover { background: var(--c-bg); }
.yp-badge-dot { position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; background: var(--c-red); border-radius: 50%; border: 1.5px solid var(--c-surface); }
.yp-menu-btn { width: 32px; height: 32px; background: none; border: 1px solid var(--c-border); border-radius: var(--r-md); display: grid; place-items: center; cursor: pointer; color: var(--c-text-2); font-size: 1rem; }
/* Modale override Bootstrap */
.modal-content { border-radius: var(--r-lg); border: 1px solid var(--c-border); box-shadow: var(--shadow-md); }
.modal-header  { padding: 16px 20px; border-bottom: 1px solid var(--c-border); }
.modal-title   { font-size: .9375rem; font-weight: 600; letter-spacing: -.01em; }
.modal-body    { padding: 20px; }
.modal-footer  { padding: 14px 20px; border-top: 1px solid var(--c-border); background: var(--c-bg); }
/* Dropdown dark override */
.dropdown-menu-dark { background: #1c1917; border: 1px solid rgba(255,255,255,.1); border-radius: var(--r-lg); }
.dropdown-menu-dark .dropdown-item { font-size: .875rem; color: rgba(255,255,255,.65); border-radius: var(--r-sm); }
.dropdown-menu-dark .dropdown-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.dropdown-menu-dark .dropdown-divider { border-color: rgba(255,255,255,.08); }
/* Standard dropdown */
.dropdown-menu { border: 1px solid var(--c-border); border-radius: var(--r-lg); box-shadow: var(--shadow-md); font-size: .875rem; }
.dropdown-item { color: var(--c-text-2); padding: 7px 14px; border-radius: var(--r-sm); transition: background var(--t); }
.dropdown-item:hover { background: var(--c-bg); color: var(--c-text-1); }
/* form-range */
.form-range { accent-color: var(--c-accent); }
/* Spinner */
.spinner-border { border-color: var(--c-border); border-right-color: var(--c-accent); }
