
  @import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

  :root {
    --red: #cc2218;
    --red-dark: #a81a12;
    --red-light: #e8352a;
    --white: #ffffff;
    --off-white: #f7f5f4;
    --gray-100: #f0edec;
    --gray-200: #e2dedd;
    --gray-300: #c8c3c2;
    --gray-500: #8a8280;
    --gray-700: #4a4240;
    --black: #1a1210;
    --sidebar-w: 220px;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  }

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

  body {
    font-family: 'DM Sans', sans-serif;
    background: var(--off-white);
    color: var(--black);
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
  }

  /* ── SIDEBAR ── */
  #sidebar {
    width: var(--sidebar-w);
    background: var(--red);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    overflow: hidden;
  }

  #sidebar .logo-wrap {
    padding: 28px 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    display: flex;
    justify-content: center;
    align-items: center;
  }

  #sidebar .logo-wrap img {
    width: 120px;
    display: block;
  }

  #sidebar nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
  }

  #sidebar nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 20px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.75);
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    letter-spacing: 0.01em;
  }

  #sidebar nav button:hover {
    background: rgba(255,255,255,0.1);
    color: var(--white);
  }

  #sidebar nav button.active {
    background: rgba(255,255,255,0.18);
    color: var(--white);
  }

  #sidebar nav button svg {
    width: 16px; height: 16px;
    flex-shrink: 0;
    opacity: 0.85;
  }

  #sidebar .sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.85);
    font-size: 11px;
  }

  /* ── MAIN ── */
  #main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #topbar {
    height: 56px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 12px;
    flex-shrink: 0;
  }

  #topbar h1 {
    font-size: 15px;
    font-weight: 600;
    color: var(--black);
    flex: 1;
  }

  #content {
    flex: 1;
    overflow-y: auto;
    padding: 28px;
  }

  /* ── VIEWS ── */
  .view { display: none; }
  .view.active { display: block; animation: viewFadeIn 0.2s ease; }
  #view-crm.active { display: block; }
  @keyframes viewFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* ── CARDS ── */
  .card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    margin-bottom: 20px;
  }

  .card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .card-header h2 {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  .card-body { padding: 20px; }

  /* ── FORM ELEMENTS ── */
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
  }

  .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

  .field {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .field.full { grid-column: 1 / -1; }

  label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  input[type=text], input[type=email], input[type=tel],
  input[type=number], input[type=date], select, textarea {
    padding: 9px 11px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px;
    color: var(--black);
    background: var(--white);
    transition: border 0.15s;
    outline: none;
    width: 100%;
  }

  input:focus, select:focus, textarea:focus {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(204,34,24,0.08);
  }

  textarea { resize: vertical; min-height: 80px; }

  /* ── BUTTONS ── */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    outline: none;
    line-height: 1;
  }

  .btn-primary {
    background: var(--red);
    color: var(--white);
  }
  .btn-primary:hover { background: var(--red-dark); }

  .btn-outline {
    background: transparent;
    color: var(--red);
    border: 1.5px solid var(--red);
  }
  .btn-outline:hover { background: rgba(204,34,24,0.06); }

  .btn-ghost {
    background: transparent;
    color: var(--gray-500);
    border: 1.5px solid var(--gray-200);
  }
  .btn-ghost:hover { background: var(--gray-100); color: var(--gray-700); }

  .btn-danger {
    background: transparent;
    color: #c0392b;
    border: 1.5px solid #e8c7c5;
  }
  .btn-danger:hover { background: #fff0ef; }

  .btn svg { width: 14px; height: 14px; }

  .btn-sm { padding: 6px 11px; font-size: 12px; }

  /* ── TABLE ── */
  .data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
  }

  .data-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 2px solid var(--gray-200);
    background: var(--gray-100);
  }

  .data-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
    vertical-align: middle;
  }

  .data-table tr:last-child td { border-bottom: none; }
  .data-table tr:hover td { background: var(--off-white); }

  /* ── BADGE ── */
  .badge {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
  }
  .badge-green { background: #e8f5e9; color: #2e7d32; }
  .badge-yellow { background: #fff8e1; color: #f57f17; }
  .badge-gray { background: var(--gray-100); color: var(--gray-500); }
  .badge-red { background: #fff0ef; color: var(--red-dark); }

  /* ── STATS ── */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
  }

  .stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
  }

  .stat-card .label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
    margin-bottom: 8px;
  }

  .stat-card .value {
    font-size: 26px;
    font-weight: 700;
    color: var(--black);
    line-height: 1;
    font-family: 'DM Mono', monospace;
  }

  .stat-card .sub {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 4px;
  }

  /* ── PREVENTIVO BUILDER ── */
  .righe-table input {
    border: none;
    background: transparent;
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px;
    width: 100%;
    outline: none;
    color: var(--black);
    padding: 2px 4px;
  }
  .righe-table input:focus {
    background: #fffbfa;
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(204,34,24,0.12);
  }
  .righe-table select {
    border: none;
    background: transparent;
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px;
    outline: none;
    padding: 2px 4px;
    color: var(--black);
    width: 100%;
  }
  .righe-table select:focus {
    background: #fffbfa;
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(204,34,24,0.12);
  }

  .totale-box {
    background: var(--red);
    color: var(--white);
    border-radius: var(--radius);
    padding: 20px 24px;
    text-align: right;
  }

  .totale-box .row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 13.5px;
    opacity: 0.85;
  }

  .totale-box .row.total {
    border-top: 1px solid rgba(255,255,255,0.3);
    margin-top: 8px;
    padding-top: 12px;
    font-size: 20px;
    font-weight: 700;
    opacity: 1;
    font-family: 'DM Mono', monospace;
  }

  /* ── MODAL ── */
  .modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    display: none;
  }
  .modal-overlay.open { display: flex; }

  .modal {
    background: var(--white);
    border-radius: 8px;
    width: 500px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  }

  .modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .modal-header h3 { font-size: 15px; font-weight: 700; }

  .modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    font-size: 20px;
    line-height: 1;
    padding: 2px 6px;
  }
  .modal-close:hover { color: var(--black); }

  .modal-body { padding: 24px; }
  .modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
  }

  /* ── EMPTY STATE ── */
  .empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--gray-500);
  }
  .empty-state svg { width: 40px; height: 40px; opacity: 0.3; margin-bottom: 12px; }
  .empty-state p { font-size: 13.5px; }

  /* ── LOGO UPLOAD ── */
  .logo-upload-area {
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s;
  }
  .logo-upload-area:hover { border-color: var(--red); }
  .logo-upload-area img { max-height: 60px; max-width: 200px; margin-bottom: 8px; }

  .alert {
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 14px;
  }
  .alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #c8e6c9; }
  .alert-error { background: #fff0ef; color: var(--red-dark); border: 1px solid #f8ccc9; }

  /* scrollbar */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 10px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--gray-300); }

  .section-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

  .search-bar {
    padding: 7px 12px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    outline: none;
    width: 220px;
  }
  .search-bar:focus { border-color: var(--red); }

  .numero-preventivo {
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    color: var(--red);
    font-weight: 600;
  }

  /* ── CRM KANBAN ── */
  .crm-board {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding-bottom: 16px;
    align-items: stretch;
    min-height: calc(100vh - 200px);
  }
  .crm-col {
    flex: 1 1 220px;
    min-width: 180px;
    max-width: 320px;
    background: var(--gray-100);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 200px);
  }
  .crm-col-header {
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
  }
  .crm-col-title {
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 7px;
  }
  .crm-col-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
  .crm-col-count {
    font-size: 11px; font-weight: 600;
    background: var(--gray-200); color: var(--gray-500);
    border-radius: 20px; padding: 1px 7px;
    font-family: 'DM Mono', monospace;
  }
  .crm-cards {
    flex: 1; overflow-y: auto;
    padding: 9px; display: flex;
    flex-direction: column; gap: 7px; min-height: 60px;
  }
  .crm-cards.drag-over {
    background: rgba(204,34,24,0.05);
    border-radius: 6px;
    outline: 2px dashed rgba(204,34,24,0.3);
    outline-offset: -2px;
  }
  .crm-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 10px 11px;
    cursor: grab;
    transition: box-shadow 0.15s, transform 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    user-select: none;
  }
  .crm-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); transform: translateY(-1px); }
  .crm-card.dragging { opacity: 0.45; cursor: grabbing; transform: rotate(2deg) scale(1.02); }
  .crm-card-name { font-weight: 600; font-size: 12.5px; color: var(--black); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .crm-card-sub { font-size: 11px; color: var(--gray-500); display: flex; align-items: center; gap: 4px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .crm-card-sub svg { width: 10px; height: 10px; flex-shrink: 0; }
  .crm-card-note { margin-top: 6px; font-size: 11px; color: var(--gray-700); background: var(--off-white); border-radius: 4px; padding: 5px 7px; line-height: 1.45; border-left: 3px solid var(--red); }
  .crm-card-actions { display: flex; gap: 4px; margin-top: 7px; }
  .crm-card-actions button { flex: 1; padding: 4px 0; font-size: 10.5px; font-weight: 600; border-radius: 3px; border: 1px solid var(--gray-200); background: transparent; color: var(--gray-500); cursor: pointer; font-family: 'DM Sans',sans-serif; transition: all 0.12s; }
  .crm-card-actions button:hover { background: var(--red); color: white; border-color: var(--red); }
  .crm-card-prev-count { display: inline-flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 600; color: var(--red); background: rgba(204,34,24,0.07); border-radius: 3px; padding: 1px 5px; margin-top: 4px; }
  .crm-note-input { width: 100%; min-height: 80px; padding: 10px 12px; border: 1px solid var(--gray-200); border-radius: 4px; font-family: 'DM Sans',sans-serif; font-size: 13.5px; resize: vertical; outline: none; }
  .crm-note-input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(204,34,24,0.08); }

  /* ── BACKUP ── */
  .backup-zone { border: 2px dashed var(--gray-200); border-radius: 8px; padding: 32px 20px; text-align: center; transition: border-color 0.15s; cursor: pointer; }
  .backup-zone:hover { border-color: var(--red); }
  .backup-zone p { color: var(--gray-500); font-size: 13px; margin-top: 8px; }
  /* ── SCADENZIARIO ── */
  .scad-filters {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 20px;
  }
  .scad-filter-btn {
    padding: 6px 14px; border-radius: 20px; border: 1.5px solid var(--gray-200);
    background: var(--white); font-family: 'DM Sans',sans-serif; font-size: 12.5px;
    font-weight: 600; cursor: pointer; color: var(--gray-500); transition: all 0.15s;
  }
  .scad-filter-btn.active { background: var(--red); border-color: var(--red); color: white; }
  .scad-filter-btn:hover:not(.active) { border-color: var(--red); color: var(--red); }

  .scad-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px;
  }

  .scad-card {
    background: var(--white); border: 1px solid var(--gray-200);
    border-radius: 8px; padding: 16px; box-shadow: var(--shadow);
    border-left: 4px solid var(--gray-200); transition: box-shadow 0.15s;
    position: relative;
  }
  .scad-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
  .scad-card.scad-scaduto { border-left-color: #e53935; }
  .scad-card.scad-urgente { border-left-color: #ff9800; }
  .scad-card.scad-prossimo { border-left-color: #fdd835; }
  .scad-card.scad-ok { border-left-color: #43a047; }
  .scad-card.scad-completato { border-left-color: var(--gray-300); opacity: 0.65; }

  .scad-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
  .scad-card-title { font-weight: 700; font-size: 13.5px; color: var(--black); }
  .scad-card-cliente { font-size: 12px; color: var(--red); font-weight: 600; margin-top: 2px; }

  .scad-badge { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; white-space: nowrap; flex-shrink: 0; }
  .scad-badge-scaduto { background: #ffebee; color: #c62828; }
  .scad-badge-urgente { background: #fff3e0; color: #e65100; }
  .scad-badge-prossimo { background: #fffde7; color: #f57f17; }
  .scad-badge-ok { background: #e8f5e9; color: #2e7d32; }
  .scad-badge-completato { background: var(--gray-100); color: var(--gray-500); }

  .scad-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--gray-500); margin-top: 5px; }
  .scad-row svg { width: 12px; height: 12px; flex-shrink: 0; }
  .scad-row strong { color: var(--gray-700); }

  .scad-note { margin-top: 10px; font-size: 11.5px; color: var(--gray-700); background: var(--off-white); border-radius: 4px; padding: 6px 8px; line-height: 1.5; }

  .scad-card-footer { display: flex; gap: 6px; margin-top: 12px; }
  .scad-card-footer button { flex: 1; padding: 5px 0; font-size: 11px; font-weight: 600; border-radius: 3px; border: 1px solid var(--gray-200); background: transparent; color: var(--gray-500); cursor: pointer; font-family: 'DM Sans',sans-serif; transition: all 0.12s; }
  .scad-card-footer button:hover { background: var(--red); color: white; border-color: var(--red); }
  .scad-card-footer button.btn-completato:hover { background: #43a047; border-color: #43a047; }

  .scad-empty { text-align: center; padding: 60px 20px; color: var(--gray-500); }
  .scad-empty svg { width: 48px; height: 48px; opacity: 0.2; margin-bottom: 14px; }

  /* alert badge sul menu */
  .nav-badge {
    display: inline-flex; align-items: center; justify-content: center;
    background: #ff9800; color: white; font-size: 10px; font-weight: 700;
    border-radius: 10px; padding: 1px 6px; margin-left: auto; line-height: 1.4;
  }

  /* ── MAGAZZINO ── */
  .mag-tab, .mail-tab, .ord-tab { padding:10px 18px;background:none;border:none;border-bottom:3px solid transparent;font-family:'DM Sans',sans-serif;font-size:13px;font-weight:600;color:var(--gray-500);cursor:pointer;transition:all .15s;margin-bottom:-2px; }

  /* ── APPUNTAMENTI ── */
  .app-board { display:flex;gap:14px;overflow-x:auto;padding-bottom:16px;align-items:flex-start;min-height:calc(100vh - 160px); }
  .app-col { flex:0 0 300px;background:var(--gray-100);border-radius:8px;border:1px solid var(--gray-200);display:flex;flex-direction:column;max-height:calc(100vh - 160px); }
  .app-col-header { padding:12px 14px 10px;border-bottom:1px solid var(--gray-200);display:flex;align-items:center;justify-content:space-between;flex-shrink:0; }
  .app-col-title { font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.07em;color:var(--gray-700);display:flex;align-items:center;gap:7px; }
  .app-col-dot { width:10px;height:10px;border-radius:50%;flex-shrink:0; }
  .app-col-count { font-size:11px;font-weight:600;background:var(--gray-200);color:var(--gray-500);border-radius:20px;padding:1px 8px;font-family:'DM Mono',monospace; }
  .app-cards { flex:1;overflow-y:auto;padding:9px;display:flex;flex-direction:column;gap:8px;min-height:60px; }
  .app-cards.drag-over { background:rgba(204,34,24,.05);border-radius:6px;outline:2px dashed rgba(204,34,24,.3);outline-offset:-2px; }

  .app-card { background:var(--white);border:1px solid var(--gray-200);border-radius:8px;padding:13px 14px;cursor:grab;transition:box-shadow .15s,transform .15s;box-shadow:0 1px 3px rgba(0,0,0,.06);user-select:none;position:relative; }
  .app-card:hover { box-shadow:0 4px 14px rgba(0,0,0,.1);transform:translateY(-1px); }
  .app-card.dragging { opacity:.45;cursor:grabbing;transform:rotate(1.5deg) scale(1.02); }
  .app-card-cliente { font-weight:700;font-size:13.5px;color:var(--black);margin-bottom:3px; }
  .app-card-data { font-size:12px;color:var(--gray-500);display:flex;align-items:center;gap:5px;margin-bottom:6px; }
  .app-card-data svg { width:12px;height:12px;flex-shrink:0; }
  .app-card-voce { background:var(--off-white);border-left:3px solid var(--red);border-radius:0 4px 4px 0;padding:5px 9px;font-size:12px;color:var(--gray-700);margin-bottom:4px;line-height:1.4; }
  .app-card-voce .prev-num { font-family:'DM Mono',monospace;font-size:11px;color:var(--red);font-weight:700; }
  .app-card-note { font-size:11.5px;color:var(--gray-500);margin-top:7px;font-style:italic;border-top:1px solid var(--gray-100);padding-top:6px; }
  .app-card-footer { display:flex;gap:5px;margin-top:9px;flex-wrap:wrap; }
  .app-card-footer button { flex:1;min-width:60px;padding:4px 0;font-size:10.5px;font-weight:600;border-radius:3px;border:1px solid var(--gray-200);background:transparent;color:var(--gray-500);cursor:pointer;font-family:'DM Sans',sans-serif;transition:all .12s; }
  .app-card-footer button:hover { background:var(--red);color:white;border-color:var(--red); }
  .app-card-footer button.btn-complete:hover { background:#2e7d32;border-color:#2e7d32; }
  .app-stato-badge { position:absolute;top:10px;right:10px;font-size:10px;font-weight:700;padding:2px 7px;border-radius:20px; }
  .app-badge-oggi { background:#fff3e0;color:#e65100; }
  .app-badge-scaduto { background:#ffebee;color:#c62828; }
  .app-badge-futuro { background:#e8f5e9;color:#2e7d32; }
  .app-badge-completato { background:var(--gray-100);color:var(--gray-500); }

  /* ── CONTABILITÀ ── */
  .cont-row { display:flex;justify-content:space-between;align-items:center;padding:9px 12px;border-bottom:1px solid var(--gray-100);font-size:13.5px; }
  .cont-row:last-child { border-bottom:none; }
  .cont-row-total { padding:11px 12px;margin-top:6px;border-bottom:none!important; }
  .cont-row-sub { background:rgba(0,0,0,.03);border-radius:4px;margin:6px 0; }
  .cont-val { font-family:'DM Mono',monospace;font-size:13px;font-weight:600; }
  .cont-val-total { font-family:'DM Mono',monospace;font-size:15px;font-weight:700; }
  .cont-final { padding:14px 12px;border-radius:8px;margin-top:8px; }
  .cont-final-pos { background:linear-gradient(135deg,#e8f5e9,#c8e6c9); }
  .cont-final-neg { background:linear-gradient(135deg,#ffebee,#ffcdd2); }
  .cont-period-btn { padding:6px 14px;border:1.5px solid var(--gray-200);border-radius:4px;background:none;font-family:'DM Sans',sans-serif;font-size:12.5px;font-weight:600;cursor:pointer;color:var(--gray-500);transition:all .15s; }
  .cont-period-btn:hover { border-color:var(--red);color:var(--red); }
  .cont-period-btn.active { background:var(--red);border-color:var(--red);color:white; }

  /* ── SORTABLE HEADERS ── */
  .th-sort { cursor:pointer; user-select:none; white-space:nowrap; }
  .th-sort:hover { background:rgba(0,0,0,.04); }
  .sort-icon { display:inline-block; margin-left:4px; font-size:10px; color:var(--gray-400); vertical-align:middle; }
  .sort-icon.asc { color:var(--red); }
  .sort-icon.desc { color:var(--red); }

  /* ── HELP ── */
  .help-section { margin-bottom: 10px; border: 1px solid var(--gray-200); border-radius: 8px; overflow: hidden; background: var(--white); box-shadow: var(--shadow); }
  .help-section-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; cursor: pointer; user-select: none; transition: background .15s; gap: 12px; }
  .help-section-header:hover { background: var(--off-white); }
  .help-section-header.open { background: var(--off-white); color: inherit; }
  .help-section-icon { width: 32px; height: 32px; border-radius: 8px; background: rgba(204,34,24,0.1); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; transition: background .15s; }
  .help-section-header.open .help-section-icon { background: rgba(204,34,24,0.1); }
  .help-section-title { flex: 1; }
  .help-section-title h3 { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
  .help-section-title p { font-size: 12px; color: var(--gray-500); font-weight: 400; }
  .help-section-header.open .help-section-title p { color: var(--gray-500); }
  .help-chevron { width: 18px; height: 18px; transition: transform .25s; flex-shrink: 0; }
  .help-section-header.open .help-chevron { transform: rotate(180deg); }
  .help-body { display: none; padding: 20px 24px; border-top: 1px solid var(--gray-200); line-height: 1.7; }
  .help-body.open { display: block; }
  .help-body h4 { font-size: 13px; font-weight: 700; color: var(--red); margin: 18px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
  .help-body h4:first-child { margin-top: 0; }
  .help-body p { font-size: 13.5px; color: var(--gray-700); margin-bottom: 10px; }
  .help-body ul, .help-body ol { padding-left: 20px; margin-bottom: 10px; }
  .help-body li { font-size: 13.5px; color: var(--gray-700); margin-bottom: 5px; }
  .help-body strong { color: var(--black); font-weight: 600; }
  .help-tip { background: #fffde7; border-left: 3px solid #f9a825; border-radius: 0 6px 6px 0; padding: 10px 14px; margin: 12px 0; font-size: 13px; color: #5d4037; }
  .help-tip strong { color: #e65100; }
  .help-warn { background: #fff3e0; border-left: 3px solid #ff9800; border-radius: 0 6px 6px 0; padding: 10px 14px; margin: 12px 0; font-size: 13px; color: #5d4037; }
  .help-kbd { display: inline-flex; align-items: center; gap: 4px; background: var(--gray-100); border: 1px solid var(--gray-300); border-radius: 4px; padding: 1px 7px; font-family: 'DM Mono',monospace; font-size: 12px; color: var(--gray-700); }
  .help-var { background: #fff3e0; color: #e65100; border-radius: 3px; padding: 1px 6px; font-family: 'DM Mono',monospace; font-size: 12px; font-weight: 600; }
  .help-steps { counter-reset: step; list-style: none; padding: 0; }
  .help-steps li { counter-increment: step; padding-left: 32px; position: relative; margin-bottom: 8px; font-size: 13.5px; color: var(--gray-700); }
  .help-steps li::before { content: counter(step); position: absolute; left: 0; width: 22px; height: 22px; border-radius: 50%; background: var(--red); color: white; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; top: 1px; }
  #help-nav-btn:hover { background: rgba(255,255,255,0.1) !important; color: white !important; }
  #help-nav-btn.active-nav { background: rgba(255,255,255,0.18) !important; color: white !important; }
  .mag-tab:hover, .mail-tab:hover, .ord-tab:hover { color:var(--red); }
  .mag-tab.active, .mail-tab.active, .ord-tab.active { color:var(--red);border-bottom-color:var(--red); }
  .stock-ok   { color:#2e7d32;background:#e8f5e9; }
  .stock-low  { color:#e65100;background:#fff3e0; }
  .stock-neg  { color:#c62828;background:#ffebee; }
  .stock-badge { font-size:11px;font-weight:700;padding:2px 8px;border-radius:20px; }
  .ror { display:flex;gap:8px;align-items:center;margin-bottom:8px;flex-wrap:wrap; }
  .ror select,.ror input { flex:1;min-width:80px;padding:7px 9px;border:1px solid var(--gray-200);border-radius:4px;font-family:'DM Sans',sans-serif;font-size:13px;outline:none; }
  .ror select:focus,.ror input:focus { border-color:var(--red); }

  /* ── LOGIN ── */
  #login-screen {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--red);
    display: flex; align-items: center; justify-content: center;
    flex-direction: column;
  }
  #login-screen.hidden { display: none; }

  .login-box {
    background: white; border-radius: 12px;
    padding: 36px 44px; width: 380px; max-width: 95vw;
    box-shadow: 0 16px 64px rgba(0,0,0,0.25);
  }
  .login-title { font-size: 16px; font-weight: 700; color: var(--black); margin-bottom: 4px; }
  .login-sub { font-size: 13px; color: var(--gray-500); margin-bottom: 24px; }
  .login-field { margin-bottom: 14px; }
  .login-field label { font-size: 11.5px; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; display: block; margin-bottom: 5px; }
  .login-field input { width: 100%; padding: 11px 13px; border: 1.5px solid var(--gray-200); border-radius: 6px; font-family: 'DM Sans',sans-serif; font-size: 14px; outline: none; transition: border .15s; }
  .login-field input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(204,34,24,.1); }
  .login-btn { width: 100%; padding: 13px; background: var(--red); color: white; border: none; border-radius: 6px; font-family: 'DM Sans',sans-serif; font-size: 14px; font-weight: 700; cursor: pointer; margin-top: 6px; transition: background .15s; }
  .login-btn:hover { background: var(--red-dark); }
  .login-error { background: #ffebee; border: 1px solid #f8ccc9; border-radius: 6px; padding: 10px 13px; font-size: 13px; color: #c62828; margin-top: 12px; display: none; }

  /* permessi checkbox grid */
  .perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-top: 8px; }
  .perm-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--gray-700); cursor: pointer; }
  .perm-item input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--red); cursor: pointer; flex-shrink: 0; }
  .perm-item span { font-size: 13px; }

  /* current user badge in topbar */
  #topbar-user { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--gray-500); }
  #topbar-user strong { color: var(--black); }
  #topbar-user .logout-btn { padding: 5px 12px; border: 1.5px solid var(--gray-200); border-radius: 4px; background: none; font-family: 'DM Sans',sans-serif; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--gray-500); transition: all .15s; }
  #topbar-user .logout-btn:hover { border-color: var(--red); color: var(--red); }



#memo-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 888;
}

#memo-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--red);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(204,34,24,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
#memo-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(204,34,24,0.5);
}
#memo-btn svg {
  width: 22px; height: 22px;
  color: white;
  transition: transform 0.2s;
}
#memo-btn.open svg { transform: rotate(45deg); }

#memo-count {
  position: absolute;
  top: -4px; right: -4px;
  background: #ff9800;
  color: white;
  font-size: 10px;
  font-weight: 800;
  border-radius: 10px;
  padding: 1px 5px;
  font-family: 'DM Mono', monospace;
  border: 2px solid white;
  display: none;
}

#memo-panel {
  position: absolute;
  bottom: 62px;
  right: 0;
  width: 340px;
  max-height: 480px;
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.1);
  border: 1px solid var(--gray-200);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: memoIn 0.2s ease;
}
#memo-panel.open { display: flex; }

@keyframes memoIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#memo-panel-header {
  padding: 14px 16px 12px;
  background: var(--red);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#memo-panel-header h4 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
#memo-panel-header span {
  font-size: 11px;
  opacity: 0.75;
}

#memo-tabs {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
  background: var(--white);
}
.memo-tab {
  flex: 1;
  padding: 9px 0;
  background: none;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.memo-tab.active {
  color: var(--red);
  border-bottom-color: var(--red);
}
.memo-tab:hover:not(.active) { color: var(--gray-700); }

#memo-body {
  overflow-y: auto;
  flex: 1;
}

.memo-item {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background 0.12s;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.memo-item:hover { background: var(--off-white); }
.memo-item:last-child { border-bottom: none; }

.memo-item-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.memo-item-body { flex: 1; min-width: 0; }
.memo-item-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--black);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.memo-item-sub {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.memo-item-right {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  margin-top: 3px;
  flex-shrink: 0;
}

.memo-empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--gray-400, #aaa);
  font-size: 12.5px;
}
.memo-empty svg { width: 32px; height: 32px; opacity: 0.2; margin-bottom: 10px; }

#memo-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-100);
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}
#memo-footer button {
  flex: 1;
  padding: 6px 0;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 4px;
  border: 1.5px solid var(--gray-200);
  background: white;
  color: var(--gray-700);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.12s;
}
#memo-footer button:hover { background: var(--red); color: white; border-color: var(--red); }

/* ── CALCOLATRICE DRAGGABLE ───────────────────────── */
#calcolatrice-panel {
  display: none;
  position: fixed;
  top: 100px;
  right: 32px;
  width: 240px;
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.1);
  border: 1px solid var(--gray-200);
  z-index: 1100;
  overflow: hidden;
  user-select: none;
  animation: calcIn 0.18s ease;
}
#calcolatrice-panel.open { display: block; }

@keyframes calcIn {
  from { opacity: 0; transform: scale(0.95) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

#calc-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--red);
  color: var(--white);
  font-size: 13px;
  font-weight: 600;
  cursor: grab;
}
#calc-handle:active { cursor: grabbing; }
#calc-handle button {
  background: none;
  border: none;
  color: var(--white);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.85;
}
#calc-handle button:hover { opacity: 1; }

#calc-body { padding: 10px; }

#calc-expr {
  min-height: 16px;
  font-size: 11px;
  color: var(--gray-500);
  text-align: right;
  margin-bottom: 2px;
  font-family: 'DM Mono', monospace;
}

#calc-display {
  font-size: 26px;
  font-weight: 600;
  text-align: right;
  padding: 4px 4px 10px;
  color: var(--black);
  font-family: 'DM Mono', monospace;
  word-break: break-all;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}

.calc-btn {
  padding: 10px 0;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  background: var(--gray-100);
  color: var(--black);
  transition: background 0.1s, transform 0.08s;
}
.calc-btn:active { transform: scale(0.93); }
.calc-btn:hover { background: var(--gray-200); }

.calc-btn.op {
  background: var(--gray-200);
  color: var(--red-dark);
  font-weight: 700;
}
.calc-btn.op:hover { background: var(--gray-300); }

.calc-btn.clr {
  background: #fff0ef;
  color: var(--red);
  font-weight: 700;
}
.calc-btn.clr:hover { background: #ffd9d7; }

.calc-btn.eq {
  background: var(--red);
  color: var(--white);
  font-weight: 700;
}
.calc-btn.eq:hover { background: var(--red-dark); }

.calc-btn.zero { grid-column: span 2; }

#calc-memory {
  display: flex;
  gap: 4px;
  border-top: 1px solid var(--gray-200);
  padding-top: 8px;
}
.calc-mem-btn {
  flex: 1;
  padding: 5px 0;
  font-size: 11px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  border: 1.5px solid var(--gray-200);
  border-radius: 5px;
  background: var(--white);
  color: var(--gray-700);
  cursor: pointer;
  transition: all 0.1s;
}
.calc-mem-btn:hover { background: var(--gray-100); }
.calc-mem-btn.active { background: var(--red); color: var(--white); border-color: var(--red); }

/* ── DASHBOARD WIDGETS ── */
.dash-widget {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  min-height: 120px;
  position: relative;
  transition: box-shadow .15s;
}
.dash-widget.drag-over-widget { outline: 2px dashed var(--red); outline-offset: 2px; }
.dash-widget.dragging { opacity: .4; }
.dash-widget-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 10px; border-bottom: 1px solid var(--gray-200);
  font-size: 13px; font-weight: 700; color: var(--gray-700);
}
.dash-widget-body { padding: 12px 16px; }
.dash-widget-body-flush { padding: 0; }
.dash-edit-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.03);
  display: none;
  flex-direction: column; align-items: flex-end; padding: 6px;
  gap: 4px;
}
.dash-edit-overlay.active { display: flex; }
.dash-widget-ctrl {
  background: white; border: 1px solid var(--gray-200); border-radius: 5px;
  padding: 3px 7px; font-size: 11px; cursor: pointer; font-weight: 600;
  color: var(--gray-600); white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.dash-widget-ctrl:hover { border-color: var(--red); color: var(--red); }
.dash-widget-ctrl.remove:hover { background: #ffebee; }
.dash-drag-handle {
  cursor: grab; color: var(--gray-400); padding: 2px 4px; font-size: 16px;
  line-height: 1; user-select: none;
}
.dash-widget.edit-mode { cursor: grab; }
.dash-widget.edit-mode:active { cursor: grabbing; }

/* ── IMPOSTAZIONI NAV ── */
/* ── IMPOSTAZIONI LAYOUT ── */
#view-impostazioni { width: 100%; }
.imp-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
  align-items: start;
  width: 100%;
}
.imp-sidebar { position: sticky; top: 20px; }
.imp-content { min-width: 0; }

.imp-nav-btn {
  display: block; width: 100%; text-align: left;
  padding: 11px 16px; background: none; border: none;
  font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 500;
  color: var(--gray-700); cursor: pointer;
  border-bottom: 1px solid var(--gray-200);
  transition: background .12s, color .12s;
}
.imp-nav-btn:last-child { border-bottom: none; }
.imp-nav-btn:hover { background: var(--gray-100); }
.imp-nav-btn.active { background: var(--red); color: white; font-weight: 700; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── CESTINO TOOLTIP ── */
.cestino-tooltip-wrap { position: relative; display: inline-block; }
.cestino-tooltip {
  display: none;
  position: absolute;
  left: 0; top: calc(100% + 6px);
  z-index: 999;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  padding: 12px 14px;
  min-width: 220px;
  font-size: 12px;
  white-space: nowrap;
}
.cestino-tooltip-wrap:hover .cestino-tooltip { display: block; }
.cestino-tooltip-row { display: flex; gap: 8px; margin-bottom: 4px; }
.cestino-tooltip-label { color: var(--gray-400); min-width: 60px; }
.cestino-tooltip-val { font-weight: 600; color: var(--gray-700); }
