:root {
    --primary: #0b5cad;
    --primary-dark: #084a8c;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #d8dee4;
    --text: #1c2733;
    --muted: #6b7885;
    --ok: #1a7f37;
    --ko: #b42318;
    --warn: #b25e09;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.hidden { display: none !important; }

/* --- Login --- */
.login-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: var(--surface);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
    text-align: center;
    max-width: 360px;
}
.login-card h1 { margin-top: 0; color: var(--primary); }
.login-card p { color: var(--muted); }
.login-card input {
    width: 100%;
    padding: 0.6rem 0.7rem;
    margin-bottom: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
}
.login-card .btn { width: 100%; margin-top: 0.4rem; }
.login-status { margin-top: 0.8rem; font-size: 0.85rem; min-height: 1.2rem; }

/* --- Buttons --- */
.btn {
    border: none;
    border-radius: 8px;
    padding: 0.55rem 1.1rem;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #eef1f4; }

/* --- Topbar --- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: var(--surface);
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-title { font-weight: 700; color: var(--primary); font-size: 1.1rem; }
.topbar-nav { display: flex; gap: 0.5rem; flex: 1; }
.nav-link {
    background: none;
    border: none;
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
}
.nav-link.active { background: #e7f0fa; color: var(--primary); }
.topbar-user { display: flex; align-items: center; gap: 0.8rem; }
#current-user {
    color: var(--muted);
    font-size: 0.9rem;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    font-family: inherit;
}
#current-user:hover { background: #eef1f4; color: var(--text); }
#current-user.active { background: #e7f0fa; color: var(--primary); }

/* --- Content --- */
.content { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
/* La sezione statistiche usa tutta la larghezza disponibile (grafici/tabelle ampie). */
.content.content--wide { max-width: none; }
.section { display: block; }

/* --- Filters --- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1rem;
}
.filters input, .filters select {
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

/* --- Table --- */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: 10px; border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    text-align: left;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.data-table th { background: #f7f9fb; color: var(--muted); font-weight: 600; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f2f7fc; }

/* --- Stato badges --- */
.badge { padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge-nuovo { background: #e7f0fa; color: var(--primary); }
.badge-in_lavorazione { background: #fff3e0; color: var(--warn); }
.badge-da_richiamare { background: #fdecea; color: var(--ko); }
.badge-chiuso_ok { background: #e6f4ea; color: var(--ok); }
.badge-chiuso_ko { background: #eceff1; color: var(--muted); }

/* --- Pagination --- */
.pagination { display: flex; align-items: center; gap: 1rem; justify-content: center; margin-top: 1rem; }
#page-info { color: var(--muted); font-size: 0.9rem; }

/* --- Cards (admin) --- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.3rem 1.5rem;
    margin-bottom: 1.2rem;
}
.card h2 { margin-top: 0; }
.import-result { margin-top: 1rem; font-size: 0.9rem; }

/* --- Modal --- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
    z-index: 100;
    overflow-y: auto;
}
.modal-box {
    background: var(--surface);
    border-radius: 12px;
    max-width: 800px;
    width: 100%;
    padding: 1.8rem;
    position: relative;
}
/* Il modale gestione campagna è più largo: molti campi (destinatari, filtri). */
#campagna-modal .modal-box {
    max-width: none;
    width: 80%;
}
.modal-close {
    position: absolute;
    top: 0.8rem;
    right: 1rem;
    border: none;
    background: none;
    font-size: 1.6rem;
    cursor: pointer;
    color: var(--muted);
}
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem 1.5rem; margin: 1rem 0; }
.detail-field { font-size: 0.9rem; }
.detail-field .label { color: var(--muted); display: block; font-size: 0.78rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin: 1rem 0; padding: 1rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.note-list { margin-top: 1rem; }
.note-item { padding: 0.6rem 0.8rem; background: #f7f9fb; border-radius: 8px; margin-bottom: 0.5rem; }
.note-item .meta { color: var(--muted); font-size: 0.78rem; }
.note-form { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.note-form input { flex: 1; padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; }

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: 0.7rem 1.2rem;
    border-radius: 8px;
    z-index: 200;
    font-size: 0.9rem;
}
.toast.error { background: var(--ko); }
.toast.success { background: var(--ok); }

@media (max-width: 700px) {
    .detail-grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; }
}

/* --- Statistiche: layout con menu laterale --- */
.stat-layout {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}
.stat-sidebar {
    flex: 0 0 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
    position: sticky;
    top: 1rem;
}
.stat-sidebar-title {
    margin: 0.25rem 0.5rem 0.75rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.stat-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.25rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
}
.stat-menu-item:hover { background: var(--bg); }
.stat-menu-item.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}
.stat-content { flex: 1 1 auto; min-width: 0; }

@media (max-width: 720px) {
    .stat-layout { flex-direction: column; }
    .stat-sidebar { position: static; width: 100%; flex-basis: auto; }
}

/* --- Heatmap fatturato campagna --- */
.heatmap { border-collapse: collapse; font-size: 0.8rem; }
.heatmap th, .heatmap td {
    border: 1px solid var(--border);
    padding: 4px 6px;
    text-align: center;
    white-space: nowrap;
}
.heatmap th.hm-filiale, .heatmap td.hm-filiale {
    text-align: left;
    font-weight: 600;
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
}
.heatmap thead th {
    background: var(--surface);
    font-weight: 600;
    color: var(--muted);
    font-size: 0.72rem;
}
.heatmap td.hm-cell { color: #1c2733; }
.heatmap .hm-tot { font-weight: 700; background: var(--bg); }
