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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.5;
}

/* Navbar */
.navbar {
    background: #1a56db;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 48px;
    box-shadow: 0 2px 4px rgba(0,0,0,.15);
}
.nav-brand { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.nav-logo { height: 28px; width: auto; }
.nav-links { display: flex; align-items: center; gap: .35rem; }
.nav-links a {
    color: #fff; text-decoration: none; font-size: .82rem; font-weight: 500;
    padding: .35rem .7rem; border-radius: 6px; transition: background .15s, opacity .15s;
    opacity: .85;
    display: inline-flex; align-items: center; gap: .4rem;
}
.nav-links .nav-icon, .nav-dropdown-btn .nav-icon {
    width: 16px; height: 16px; flex-shrink: 0; opacity: .9;
}
.nav-dropdown-menu .nav-icon {
    width: 15px; height: 15px; flex-shrink: 0; opacity: .65; margin-right: .15rem;
}
.nav-links a:hover { background: rgba(255,255,255,.15); opacity: 1; text-decoration: none; }
.nav-links a.active { background: rgba(255,255,255,.22); opacity: 1; }
/* Nav dropdowns */
.nav-dropdown { position: relative; }
.nav-dropdown-btn {
    background: none; border: none; color: #fff; font: inherit; font-size: .82rem; font-weight: 500;
    opacity: .85; cursor: pointer; display: flex; align-items: center; gap: .3rem;
    padding: .35rem .7rem; border-radius: 6px; transition: background .15s, opacity .15s;
}
.nav-dropdown-btn:hover { background: rgba(255,255,255,.15); opacity: 1; }
.nav-dropdown-btn.active { background: rgba(255,255,255,.22); opacity: 1; }
.nav-dropdown-arrow { font-size: .6rem; transition: transform .2s; }
.nav-dropdown.open .nav-dropdown-arrow { transform: rotate(180deg); }
.nav-dropdown-menu {
    display: none; position: absolute; left: 0; top: calc(100% + 4px);
    background: #fff; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
    min-width: 160px; overflow: hidden; z-index: 100;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
    display: flex; align-items: center; gap: .5rem;
    padding: .55rem 1rem; color: #333 !important; font-size: .85rem;
    text-decoration: none !important; white-space: nowrap; opacity: 1 !important;
}
.nav-dropdown-menu a:hover { background: #f3f4f6; }
.nav-dropdown-menu a.active { background: #e8edfb; color: #1a56db !important; font-weight: 600; }

.nav-user-menu { position: relative; }
.nav-user-btn {
    background: none; border: none; color: #fff; font: inherit; font-size: .85rem;
    opacity: .85; cursor: pointer; display: flex; align-items: center; gap: .35rem; padding: .25rem .4rem; border-radius: 4px;
}
.nav-user-btn:hover { opacity: 1; background: rgba(255,255,255,.12); }
.nav-user-arrow { font-size: .65rem; transition: transform .2s; }
.nav-user-menu.open .nav-user-arrow { transform: rotate(180deg); }
.nav-user-dropdown {
    display: none; position: absolute; right: 0; top: calc(100% + 4px);
    background: #fff; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
    min-width: 120px; overflow: hidden; z-index: 100;
}
.nav-user-menu.open .nav-user-dropdown { display: block; }
.nav-user-dropdown a {
    display: flex; align-items: center; gap: .5rem;
    padding: .55rem 1rem; color: #333 !important; font-size: .88rem;
    text-decoration: none !important; white-space: nowrap;
}
.nav-user-dropdown .nav-icon { width: 15px; height: 15px; flex-shrink: 0; opacity: .65; }
.nav-user-dropdown a:hover { background: #f3f4f6; }
.nav-user-sep { border: none; border-top: 1px solid #e5e7eb; margin: .2rem 0; }

/* Container */
.container {
    max-width: 960px;
    margin: 1.25rem auto;
    padding: 0 1rem;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #e8f0fe;
}
.login-box {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    padding: 2rem 1.75rem;
    width: 100%;
    max-width: 360px;
    text-align: center;
}
.login-box h1 { color: #1a56db; margin-bottom: .25rem; }
.login-logo { max-width: 220px; margin-bottom: .75rem; }
.login-box .subtitle { color: #666; font-size: .9rem; margin-bottom: 1.5rem; }

/* Fields */
.field { margin-bottom: .75rem; text-align: left; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .2rem; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: .4rem .65rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: .9rem;
    transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: #1a56db;
    box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: .4rem 1rem;
    border-radius: 6px;
    font-size: .85rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary { background: #1a56db; color: #fff; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-full { width: 100%; text-align: center; padding: .55rem; }
.btn-sm { padding: .25rem .65rem; font-size: .78rem; }

/* Alerts */
.alert {
    padding: .5rem .85rem;
    border-radius: 6px;
    margin-bottom: .75rem;
    font-size: .85rem;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert ul { margin: 0; padding-left: 1.25rem; }

/* Session warning banner */
.session-warning {
    position: fixed;
    top: 48px; left: 0; right: 0;
    background: #f59e0b;
    color: #1a1a1a;
    text-align: center;
    padding: .5rem;
    font-size: .9rem;
    font-weight: 600;
    z-index: 1000;
}

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat-card { background: #fff; border-radius: 8px; padding: 1rem; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stat-number { font-size: 2rem; font-weight: 700; color: #1a56db; }
.stat-label { color: #6b7280; font-size: .82rem; margin-top: .15rem; }

/* Section header */
.page-header, .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .75rem;
}
.page-header h2, .section-header h3 { margin: 0; }

/* Table */
.table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.table th, .table td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid #f3f4f6; font-size: .88rem; }
.table th { background: #f9fafb; font-size: .8rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .05em; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f9fafb; }

/* Form card */
.form-card { background: #fff; border-radius: 8px; padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.form-card fieldset { border: 1px solid #e5e7eb; border-radius: 6px; padding: .85rem; margin-bottom: .75rem; }
.form-card legend { font-weight: 600; padding: 0 .5rem; color: #374151; font-size: .9rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-actions { display: flex; gap: .5rem; padding-top: .35rem; }

/* Detail card */
.detail-card { background: #fff; border-radius: 8px; padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.detail-section { margin-bottom: 1rem; }
.detail-section h3 { font-size: .95rem; color: #6b7280; margin-bottom: .4rem; border-bottom: 1px solid #f3f4f6; padding-bottom: .35rem; }
dl { display: grid; grid-template-columns: 150px 1fr; gap: .3rem .75rem; }
dt { font-weight: 600; color: #6b7280; font-size: .85rem; }
dd { color: #111; font-size: .9rem; }

.empty-state { color: #9ca3af; padding: 1.5rem; text-align: center; font-size: .9rem; }
h2 { margin-bottom: .75rem; }

/* Badge */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #f3f4f6; color: #6b7280; }

/* Badge ruoli */
.badge-ruolo-admin { background: #fef3c7; color: #92400e; }
.badge-ruolo-educatore1 { background: #dbeafe; color: #1e40af; }
.badge-ruolo-educatore2 { background: #f3e8ff; color: #6b21a8; }
.badge-ruolo-visualizzatore { background: #f3f4f6; color: #6b7280; }
.badge-ruolo-amministrazione { background: #fef9c3; color: #854d0e; }
.badge-ruolo-segreteria_sociale { background: #d1fae5; color: #065f46; }

/* Varie */
.text-muted { color: #9ca3af; }
.ospite-info { margin-bottom: 1rem; padding: .75rem 1rem; background: #f9fafb; border-radius: 6px; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: .45rem;
    cursor: pointer;
    font-weight: 500;
    font-size: .85rem;
    line-height: 1.2;
    color: #374151;
    padding: .35rem .6rem;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    background: #fff;
    transition: border-color .15s, background .15s;
    user-select: none;
}
.checkbox-label:hover { border-color: #93b4f5; background: #f8faff; }
.checkbox-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    transition: background .15s, border-color .15s;
    margin: 0;
    line-height: 1;
}
.checkbox-label input[type="checkbox"]:checked {
    background: #1a56db;
    border-color: #1a56db;
}
.checkbox-label input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.checkbox-label:has(input:checked) {
    border-color: #93b4f5;
    background: #eff6ff;
}
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .5rem; padding: .5rem 0; }
.btn-danger { background: #fee2e2; color: #991b1b; }

/* Foto ospite */
.guest-photo {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid #e5e7eb;
}
.guest-photo > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.guest-photo-placeholder {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #dbeafe;
    color: #1e40af;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    flex-shrink: 0;
    border: 2px solid #e5e7eb;
}
.guest-photo-lg {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid #e5e7eb;
}
.guest-photo-lg > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.guest-photo-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
}
.guest-photo-sm > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.guest-photo-sm.guest-photo-placeholder {
    width: 36px;
    height: 36px;
    font-size: .7rem;
    font-weight: 700;
    color: #6b7280;
    background: #f3f4f6;
}

/* Struttura — griglia ospiti presenti */
.ospiti-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: .75rem;
}
.ospite-card {
    background: #fff;
    border-radius: 8px;
    padding: .75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    display: flex;
    align-items: center;
    gap: .7rem;
    text-decoration: none;
    color: inherit;
    transition: box-shadow .15s, transform .15s;
}
.ospite-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12); transform: translateY(-1px); }
.ospite-card-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.ospite-card-info strong { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ospite-card-info span { font-size: .78rem; color: #6b7280; }

/* Documenti — tab */
.doc-tabs-wrapper { margin-top: 1.25rem; }
.doc-tabs-wrapper > h3 { margin-bottom: .5rem; }
.doc-tabs { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); overflow: hidden; }
.doc-tab-nav { display: flex; border-bottom: 2px solid #e5e7eb; }
.doc-tab-btn {
    padding: .5rem 1rem;
    font-size: .85rem;
    font-weight: 600;
    color: #6b7280;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.doc-tab-btn:hover { color: #1a56db; }
.doc-tab-btn.active { color: #1a56db; border-bottom-color: #1a56db; }
.doc-tab-panel { display: none; padding: 1rem; }
.doc-tab-panel.active { display: block; }
.upload-form { display: flex; align-items: center; gap: .75rem; margin-top: .75rem; }
.file-input { font-size: .875rem; }
.btn-star { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: #9ca3af; padding: 0; line-height: 1; }
.btn-star:hover, .btn-star.starred { color: #f59e0b; }
.star-active { color: #f59e0b; font-size: 1.1rem; }

/* Note ospiti — badge tipo */
.badge-nota { display: inline-block; font-size: .72rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; white-space: nowrap; }
.badge-nota-salute       { background: #fce4ec; color: #c62828; }
.badge-nota-psicologico  { background: #f3e5f5; color: #6a1b9a; }
.badge-nota-legale       { background: #e8eaf6; color: #283593; }
.badge-nota-documenti    { background: #fff3e0; color: #e65100; }
.badge-nota-integrazione { background: #e8f5e9; color: #2e7d32; }
.badge-nota-convivenza   { background: #fff8e1; color: #f9a825; }
.badge-nota-colloquio    { background: #e0f7fa; color: #00838f; }
.badge-nota-logistica    { background: #efebe9; color: #4e342e; }
.badge-nota-movimenti    { background: #e3f2fd; color: #1565c0; }
.badge-nota-generica     { background: #f5f5f5; color: #616161; }

/* Note — card */
.nota-card { background: #fff; border-radius: 8px; padding: 1rem; margin-bottom: .75rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); border-left: 4px solid #e5e7eb; position: relative; }
.nota-card-salute       { border-left-color: #ef5350; }
.nota-card-psicologico  { border-left-color: #ab47bc; }
.nota-card-legale       { border-left-color: #5c6bc0; }
.nota-card-documenti    { border-left-color: #ff9800; }
.nota-card-integrazione { border-left-color: #66bb6a; }
.nota-card-convivenza   { border-left-color: #fdd835; }
.nota-card-colloquio    { border-left-color: #26c6da; }
.nota-card-logistica    { border-left-color: #8d6e63; }
.nota-card-movimenti    { border-left-color: #42a5f5; }
.nota-card-generica     { border-left-color: #bdbdbd; }
.nota-header { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; font-size: .85rem; }
.nota-testo { font-size: .92rem; line-height: 1.5; white-space: pre-line; }
.nota-meta { font-size: .78rem; color: #9ca3af; margin-top: .5rem; }
.nota-ristretta { opacity: .85; }
.nota-ristretta::after { content: '🔒'; position: absolute; top: .75rem; right: .75rem; font-size: .85rem; }

/* Note — filtri */
.note-filtri { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1.25rem; padding: .75rem; background: #f9fafb; border-radius: 8px; }
.note-filtri .field { margin-bottom: 0; }
.note-filtri label { font-size: .78rem; font-weight: 500; }
.note-filtri select, .note-filtri input { font-size: .85rem; padding: .3rem .5rem; }

/* Scheda ospite — tab di pagina */
.page-tabs { margin-top: 1rem; }
.page-tab-nav {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 1rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.page-tab-nav::-webkit-scrollbar { display: none; }
.page-tab-btn {
    padding: .5rem 1.1rem;
    font-size: .85rem;
    font-weight: 500;
    color: #6b7280;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color .15s, border-color .15s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: .35rem;
}
.page-tab-btn:hover { color: #1a56db; }
.page-tab-btn.active { color: #1a56db; border-bottom-color: #1a56db; font-weight: 600; }
.page-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 .3rem;
    font-size: .72rem;
    font-weight: 700;
    background: #e5e7eb;
    color: #374151;
    border-radius: 999px;
    line-height: 1;
}
.page-tab-btn.active .page-tab-badge { background: #dbeafe; color: #1e40af; }
.page-tab-panel { display: none; }
.page-tab-panel.active { display: block; }

/* ── Hamburger ── */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: .2rem .4rem;
    line-height: 1;
}

/* ── Responsive (≤ 640 px) ── */
@media (max-width: 640px) {

    /* Navbar: hamburger */
    .navbar {
        flex-wrap: wrap;
        height: auto;
        padding: .75rem 1rem;
        gap: 0;
    }
    .nav-brand { flex: 1; }
    .nav-toggle { display: flex; align-items: center; }
    .nav-links {
        display: none;
        flex-direction: column;
        width: 100%;
        padding: .5rem 0 .5rem;
        gap: .1rem;
        border-top: 1px solid rgba(255,255,255,.2);
        margin-top: .6rem;
        text-align: center;
    }
    .nav-links.open { display: flex; }
    .nav-links a,
    .nav-links .btn { padding: .55rem .75rem; font-size: .95rem; background: none; color: #fff; border-radius: 6px; opacity: 1; width: 100%; }
    .nav-links a:hover,
    .nav-links a.active { background: rgba(255,255,255,.12); }
    .nav-dropdown { width: 100%; }
    .nav-dropdown-btn { padding: .55rem .75rem; font-size: .95rem; width: 100%; justify-content: center; opacity: 1; }
    .nav-dropdown-menu { position: static; box-shadow: none; background: rgba(255,255,255,.1); border-radius: 4px; min-width: 0; }
    .nav-dropdown-menu a { color: #fff !important; padding: .45rem .75rem; font-size: .9rem; opacity: 1 !important; }
    .nav-dropdown-menu a.active { background: rgba(255,255,255,.12); color: #fff !important; }
    .nav-user-menu { width: 100%; }
    .nav-user-btn { padding: .55rem .75rem; font-size: .95rem; width: 100%; justify-content: center; }
    .nav-user-dropdown { position: static; box-shadow: none; background: rgba(255,255,255,.1); border-radius: 4px; min-width: 0; }
    .nav-user-dropdown a { color: #fff !important; padding: .45rem .75rem; }

    /* Contenitore */
    .container { margin: 1rem auto; }

    /* Header pagina */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: .75rem;
    }
    .page-header > div:last-child { flex-wrap: wrap; }

    /* Tabelle: scorri orizzontalmente */
    .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Form in colonna singola */
    .form-row { grid-template-columns: 1fr; }
    .form-actions { flex-wrap: wrap; }
    .form-card { padding: 1rem; }

    /* Definition list: stack verticale */
    dl { grid-template-columns: 1fr; gap: .15rem; }
    dt { margin-top: .6rem; }
    dt:first-of-type { margin-top: 0; }

    /* Upload form */
    .upload-form { flex-wrap: wrap; }

    /* Griglia statistiche: 2 colonne fisse su mobile */
    .stats-grid { grid-template-columns: 1fr 1fr; }

    /* Detail card: meno padding */
    .detail-card { padding: 1rem; }
}

/* ── Autocomplete ── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
    display: none; position: absolute; z-index: 100; top: 100%; left: 0; right: 0;
    background: #fff; border: 1px solid #d1d5db; border-top: none; border-radius: 0 0 6px 6px;
    max-height: 220px; overflow-y: auto; margin: 0; padding: 0; list-style: none;
    box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
.autocomplete-list li {
    padding: .5rem .75rem; cursor: pointer; font-size: .9rem;
}
.autocomplete-list li:hover { background: #eff6ff; }
.autocomplete-clear {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    cursor: pointer; font-size: 1.2rem; color: #9ca3af; line-height: 1;
}
.autocomplete-clear:hover { color: #374151; }

/* ── Codice fiscale validation ── */
.input-valid  { border-color: #22c55e !important; }
.input-invalid { border-color: #ef4444 !important; }
.cf-feedback { display: block; margin-top: .25rem; font-size: .78rem; min-height: 1.1em; }
.cf-feedback-ok  { color: #16a34a; }
.cf-feedback-err { color: #dc2626; }

/* ── Sortable table headers ── */
th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-sort]:hover { color: #1a56db; }
th[data-sort]::after { content: '\2195'; margin-left: .35rem; opacity: .3; font-size: .7rem; }
th[data-sort].sort-asc::after  { content: '\25B2'; opacity: .8; color: #1a56db; }
th[data-sort].sort-desc::after { content: '\25BC'; opacity: .8; color: #1a56db; }
