:root {
    --bg: #0b0f17;
    --sidebar-bg: #0a0e15;
    --card-bg: #131826;
    --card-bg-2: #161c2c;
    --border: rgba(255, 255, 255, 0.07);
    --text: #f2f4f8;
    --text-muted: #8890a0;
    --accent: #fbb431;
    --accent-ink: #2a1c00;
    --accent-soft: rgba(251, 180, 49, 0.16);
    --blue-pale: #c7d3f7;
    --gray-mid: #4c5468;
    --green-pale: #b8e6b6;
    --orange-pale: #f3b583;
    --danger: #e2685f;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

/* ---------- layout shell : mobile first ---------- */

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar { display: none; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
}
.brand .dot {
    width: 30px; height: 30px;
    border-radius: 9px;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.brand .dot svg { width: 19px; height: 19px; }
.brand .wordmark {
    font-family: 'Baloo 2', 'Segoe UI', sans-serif;
    font-weight: 700;
    font-size: 19px;
    color: var(--text);
    letter-spacing: .01em;
    -webkit-text-stroke: .5px rgba(0,0,0,.35);
}

.topbar-icons { display: flex; align-items: center; gap: 10px; }
.icon-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    font-size: 15px;
}
.avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--orange-pale), var(--accent));
}

main.content {
    flex: 1;
    padding: 16px;
    padding-bottom: 88px; /* spazio per bottom nav mobile */
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    margin: 4px 0 18px;
}

.page-sub { color: var(--text-muted); font-size: 13px; margin-top: -14px; margin-bottom: 18px; }

/* bottom nav mobile */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 30;
    display: flex;
    justify-content: space-around;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
}
.bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--text-muted);
    font-size: 10px;
    padding: 4px 10px;
    border-radius: 10px;
}
.bottom-nav a.active { color: var(--text); background: var(--accent-soft); }
.bottom-nav .ic { font-size: 17px; }

/* grid */
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }

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

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
}

.card-head {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 14px;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-head .period { color: var(--text-muted); font-size: 11px; display: block; margin-top: 2px;}
.card-head .big-number { font-size: 20px; font-weight: 700; }

.kpi {
    padding: 16px;
}
.kpi .label { color: var(--text-muted); font-size: 12px; margin-bottom: 8px; }
.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .value.email { color: var(--green-pale); }
.kpi .value.tel { color: var(--blue-pale); }
.kpi .value.senza { color: var(--danger); }
.kpi .value.coda { color: var(--orange-pale); }

canvas { max-width: 100%; }

.mini-stat {
    background: var(--card-bg-2);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex; flex-direction: column; gap: 6px;
}
.mini-stat .lbl { font-size: 11px; color: var(--text-muted); }
.mini-stat .bar-wrap { height: 4px; background: rgba(255,255,255,0.08); border-radius: 4px; overflow: hidden; }
.mini-stat .bar { height: 100%; background: var(--accent); border-radius: 4px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 8px 6px;
    border-bottom: 1px solid var(--border);
}
tbody td { padding: 10px 6px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--text-muted); font-size: 11px; }

.badge {
    display: inline-block;
    font-size: 10px;
    padding: 3px 9px;
    border-radius: 999px;
    font-weight: 600;
}
.badge.email { background: rgba(184,230,182,0.15); color: var(--green-pale); }
.badge.tel { background: rgba(199,211,247,0.15); color: var(--blue-pale); }
.badge.senza { background: rgba(226,104,95,0.15); color: var(--danger); }

.section-link { color: var(--accent); font-size: 12px; font-weight: 600; }

.hidden { display: none !important; }

.empty-msg { color: var(--text-muted); font-size: 13px; text-align: center; padding: 30px 10px; }

/* ---------- nuovi componenti: viste, liste, import ---------- */
[data-view] { animation: fade-in .12s ease; }
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }

.kpi-link { display: block; text-decoration: none; color: inherit; transition: transform .1s; }
.kpi-link:hover { transform: translateY(-2px); border-color: var(--accent); }

.legenda-donut { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 14px; font-size: 12px; color: var(--text-muted); }
.legenda-donut span { display: flex; align-items: center; gap: 6px; }
.dot-legenda { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.page-hint { color: var(--text-muted); font-size: 13px; line-height: 1.5; margin: 0 0 14px; }

.list-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.search-box {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    font-size: 13px;
}
.search-box::placeholder { color: var(--text-muted); }
.search-box:focus { outline: none; border-color: var(--accent); }

.link-apri { color: var(--accent); font-weight: 600; white-space: nowrap; }

/* import */
.import-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.import-tab {
    background: var(--card-bg-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.import-tab.active { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }

.file-drop {
    display: flex; align-items: center; justify-content: center;
    text-align: center;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 28px 14px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    background: var(--card-bg-2);
    transition: border-color .15s, background .15s;
}
.file-drop:hover, .file-drop.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.file-drop.ha-file { border-style: solid; border-color: var(--accent); color: var(--text); }

.field-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.text-input {
    width: 100%;
    background: var(--card-bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
}
.text-input:focus { outline: none; border-color: var(--accent); }

.btn-primary {
    background: var(--accent);
    color: #0b0f17;
    border: none;
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.progress-track { height: 8px; background: var(--card-bg-2); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }

.azione-badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.azione-nuova { background: rgba(184,230,182,0.15); color: var(--green-pale); }
.azione-arricchita { background: rgba(199,211,247,0.15); color: var(--blue-pale); }
.azione-invariata { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.azione-saltata { background: rgba(226,104,95,0.15); color: var(--danger); }

/* ---------- desktop / tablet (min-width 900px): sidebar layout ---------- */
@media (min-width: 900px) {
    .app { flex-direction: row; }

    .sidebar {
        width: 230px;
        flex-shrink: 0;
        background: var(--sidebar-bg);
        border-right: 1px solid var(--border);
        padding: 20px 14px;
        display: flex;
        flex-direction: column;
        position: sticky;
        top: 0;
        height: 100vh;
    }
    .sidebar .brand { padding: 6px 8px 22px; }
    .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
    .sidebar nav a {
        display: flex; align-items: center; gap: 10px;
        padding: 10px 12px;
        border-radius: var(--radius-sm);
        color: var(--text-muted);
        font-size: 14px;
        font-weight: 500;
    }
    .sidebar nav a .ic { font-size: 16px; width: 18px; text-align: center; }
    .sidebar nav a.active { background: var(--accent-soft); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
    .sidebar nav a.active .ic { color: var(--accent); }
    .sidebar .nav-section-label { color: var(--text-muted); font-size: 11px; margin: 18px 0 6px 12px; text-transform: uppercase; letter-spacing: .05em; }

    .topbar { display: none; }
    .desktop-topbar {
        display: flex !important;
        align-items: center; justify-content: space-between;
        margin-bottom: 20px;
    }
    .bottom-nav { display: none; }
    #mobile-title { display: none; }

    main.content { padding: 24px 28px; padding-bottom: 28px; }

    .kpi-row { grid-template-columns: repeat(4, 1fr); }
    .layout-2col { grid-template-columns: 2fr 1fr; align-items: start; }
    .layout-2col-b { grid-template-columns: 1.3fr 1fr; align-items: start; }
}

.desktop-topbar { display: none; }
