:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e4e7ec;
    --text: #1a1d29;
    --text-soft: #667085;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --warn: #d97706;
    --ok: #059669;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
    --shadow-lg: 0 12px 32px rgba(16,24,40,.16);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ---------- LOGIN ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.login-card {
    background: var(--surface);
    padding: 36px 32px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 320px;
    text-align: center;
}
.login-logo {
    width: 56px; height: 56px;
    margin: 0 auto 16px;
    border-radius: 16px;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 20px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--text-soft); margin: 0 0 24px; font-size: 14px; }
.login-card input {
    width: 100%; padding: 12px 14px; margin-bottom: 14px;
    border: 1px solid var(--border); border-radius: 10px; font-size: 15px;
}
.login-card button {
    width: 100%; padding: 12px; border: none; border-radius: 10px;
    background: var(--primary); color: #fff; font-size: 15px; font-weight: 600;
    cursor: pointer;
}
.login-card button:hover { background: var(--primary-dark); }
.login-error {
    background: #fef2f2; color: var(--danger);
    padding: 10px; border-radius: 8px; font-size: 14px; margin-bottom: 12px;
}

/* ---------- APP LAYOUT ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: 340px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.sidebar-head {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
}
.brand-logo {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--text-soft); }
.logout-link { margin-left: auto; color: var(--text-soft); text-decoration: none; font-size: 13px; }
.logout-link:hover { color: var(--danger); }

.sidebar-actions { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.btn-primary {
    padding: 11px; border: none; border-radius: 10px;
    background: var(--primary); color: #fff; font-weight: 600; font-size: 14px;
    cursor: pointer; width: 100%;
}
.btn-primary:hover { background: var(--primary-dark); }
.search-box {
    padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
    font-size: 14px; width: 100%;
}
.filtri { display: flex; gap: 6px; }
.filtri button {
    flex: 1; padding: 7px; border: 1px solid var(--border); background: var(--surface);
    border-radius: 8px; font-size: 12px; color: var(--text-soft); cursor: pointer;
}
.filtri button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.lista-clienti { flex: 1; overflow-y: auto; padding: 6px 12px 18px; }
.cliente-item {
    padding: 13px 14px; border-radius: 12px; cursor: pointer;
    margin-bottom: 6px; transition: background .12s;
    border: 1px solid transparent;
}
.cliente-item:hover { background: var(--bg); }
.cliente-item.selected { background: #eff6ff; border-color: #bfdbfe; }
.cliente-item .nome { font-weight: 600; font-size: 14.5px; }
.cliente-item .dominio { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }
.badge-arch {
    font-size: 10px; background: #f3f4f6; color: var(--warn);
    padding: 2px 7px; border-radius: 20px; margin-left: 6px;
}

/* ---------- CONTENT ---------- */
.content { flex: 1; overflow-y: auto; padding: 32px 40px; }
.empty-state {
    height: 100%; display: flex; flex-direction: column;
    align-items: center; justify-content: center; color: var(--text-soft);
    text-align: center;
}
.empty-state .ico { font-size: 48px; margin-bottom: 12px; opacity: .4; }

.scheda-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.scheda-avatar {
    width: 56px; height: 56px; border-radius: 14px;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700; flex-shrink: 0;
}
.scheda-head h1 { margin: 0; font-size: 24px; }
.scheda-head a { color: var(--primary); text-decoration: none; font-size: 14px; }
.scheda-meta { margin-left: auto; display: flex; gap: 8px; }
.btn-ghost {
    padding: 9px 14px; border: 1px solid var(--border); background: var(--surface);
    border-radius: 9px; font-size: 13px; cursor: pointer; color: var(--text);
}
.btn-ghost:hover { background: var(--bg); }
.btn-ghost.danger { color: var(--danger); border-color: #fecaca; }

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.card h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); }
.note-text { white-space: pre-wrap; line-height: 1.6; font-size: 15px; }
.note-empty { color: var(--text-soft); font-style: italic; }
.scheda-footer { font-size: 12px; color: var(--text-soft); margin-top: 8px; }

/* ---------- MODALE ---------- */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(16,24,40,.45); z-index: 50;
    align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface); border-radius: 18px; padding: 26px;
    width: 460px; max-width: 100%; box-shadow: var(--shadow-lg);
}
.modal h2 { margin: 0 0 18px; font-size: 19px; }
.modal label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-soft); }
.modal input, .modal textarea {
    width: 100%; padding: 11px 13px; border: 1px solid var(--border);
    border-radius: 10px; font-size: 14.5px; margin-bottom: 16px; font-family: inherit;
}
.modal textarea { min-height: 130px; resize: vertical; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- RESPONSIVE ---------- */
.menu-toggle { display: none; }
@media (max-width: 820px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 40;
        transform: translateX(-100%); transition: transform .25s;
        box-shadow: var(--shadow-lg);
    }
    .app.menu-open .sidebar { transform: translateX(0); }
    .content { padding: 70px 20px 30px; width: 100%; }
    .menu-toggle {
        display: flex; position: fixed; top: 14px; left: 14px; z-index: 30;
        width: 42px; height: 42px; border-radius: 10px; border: none;
        background: var(--surface); box-shadow: var(--shadow);
        align-items: center; justify-content: center; font-size: 20px; cursor: pointer;
    }
    .scheda-meta { flex-direction: column; }
}

/* ---------- NOTE STRUTTURATE / TIMELINE ---------- */
.note-toolbar {
    display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.note-toolbar h3 { margin: 0; flex: 1; }
.btn-add-nota {
    padding: 8px 14px; border: none; border-radius: 9px;
    background: var(--primary); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-add-nota:hover { background: var(--primary-dark); }

.note-filtro-cat {
    padding: 7px 11px; border: 1px solid var(--border); border-radius: 9px;
    font-size: 13px; background: var(--surface); color: var(--text);
}

.timeline { display: flex; flex-direction: column; gap: 10px; }

.nota-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid #94a3b8;
    border-radius: 0 12px 12px 0;
    padding: 13px 16px;
    box-shadow: var(--shadow);
    transition: box-shadow .12s;
}
.nota-card:hover { box-shadow: 0 4px 14px rgba(16,24,40,.10); }

.nota-top { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.nota-data {
    font-size: 13px; color: var(--text-soft);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.cat-badge {
    font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
    background: #eff6ff; color: var(--primary); white-space: nowrap;
}
.nota-actions { margin-left: auto; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.nota-card:hover .nota-actions { opacity: 1; }
.nota-actions button {
    border: none; background: none; cursor: pointer; font-size: 12px;
    color: var(--text-soft); padding: 3px 8px; border-radius: 6px;
}
.nota-actions button:hover { background: var(--bg); color: var(--text); }
.nota-actions button.del:hover { color: var(--danger); background: #fef2f2; }
.nota-body { white-space: pre-wrap; line-height: 1.55; font-size: 14.5px; }

/* Colori per categoria: striscia + badge.
   Si applicano via classe cat-XXX generata dal JS (slug della categoria). */
.cat-hosting    { border-left-color:#378ADD; } .cat-hosting    .cat-badge{ background:#E6F1FB; color:#0C447C; }
.cat-server     { border-left-color:#185FA5; } .cat-server     .cat-badge{ background:#E6F1FB; color:#042C53; }
.cat-dominio    { border-left-color:#1D9E75; } .cat-dominio    .cat-badge{ background:#E1F5EE; color:#085041; }
.cat-wordpress  { border-left-color:#534AB7; } .cat-wordpress  .cat-badge{ background:#EEEDFE; color:#3C3489; }
.cat-prestashop { border-left-color:#7F77DD; } .cat-prestashop .cat-badge{ background:#EEEDFE; color:#26215C; }
.cat-googleads  { border-left-color:#BA7517; } .cat-googleads  .cat-badge{ background:#FAEEDA; color:#633806; }
.cat-metaads    { border-left-color:#378ADD; } .cat-metaads    .cat-badge{ background:#E6F1FB; color:#0C447C; }
.cat-seo        { border-left-color:#639922; } .cat-seo        .cat-badge{ background:#EAF3DE; color:#27500A; }
.cat-tracking   { border-left-color:#0F6E56; } .cat-tracking   .cat-badge{ background:#E1F5EE; color:#04342C; }
.cat-email      { border-left-color:#D4537E; } .cat-email      .cat-badge{ background:#FBEAF0; color:#72243E; }
.cat-grafica    { border-left-color:#D85A30; } .cat-grafica    .cat-badge{ background:#FAECE7; color:#712B13; }
.cat-preventivo { border-left-color:#BA7517; } .cat-preventivo .cat-badge{ background:#FAEEDA; color:#633806; }
.cat-generale   { border-left-color:#888780; } .cat-generale   .cat-badge{ background:#F1EFE8; color:#444441; }
.cat-altro      { border-left-color:#888780; } .cat-altro      .cat-badge{ background:#F1EFE8; color:#444441; }

.note-vuote { color: var(--text-soft); font-style: italic; padding: 20px 0; }

/* Campi affiancati nella modale nota */
.row-2 { display: flex; gap: 12px; }
.row-2 > div { flex: 1; }
.modal select {
    width: 100%; padding: 11px 13px; border: 1px solid var(--border);
    border-radius: 10px; font-size: 14.5px; margin-bottom: 16px; font-family: inherit;
    background: var(--surface);
}

/* Card info statiche (ex note_interne) */
.info-statiche { white-space: pre-wrap; line-height: 1.55; font-size: 14px; }