/* ============================================================================
   ISIMaps - Design System
   ============================================================================ */

/* --- Reset & base --- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color .2s ease, color .2s ease;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* --- Tema chiaro (default) --- */
:root {
    --bg: #F8FAFC;
    --bg-elevated: #FFFFFF;
    --bg-subtle: #F1F5F9;
    --bg-hover: #F1F5F9;
    --border: #E2E8F0;
    --border-strong: #CBD5E1;
    --text: #0F172A;
    --text-muted: #64748B;
    --text-subtle: #94A3B8;
    --brand: #DC2626;
    --brand-hover: #B91C1C;
    --brand-subtle: #FEE2E2;
    --success: #16A34A;
    --success-subtle: #DCFCE7;
    --warning: #D97706;
    --warning-subtle: #FEF3C7;
    --danger: #DC2626;
    --danger-subtle: #FEE2E2;
    --info: #2563EB;
    --info-subtle: #DBEAFE;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
    --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
    --shadow-lg: 0 10px 25px rgba(15,23,42,.1), 0 4px 10px rgba(15,23,42,.04);
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
}

/* --- Tema scuro --- */
[data-theme="dark"] {
    --bg: #0F172A;
    --bg-elevated: #1E293B;
    --bg-subtle: #1E293B;
    --bg-hover: #334155;
    --border: #334155;
    --border-strong: #475569;
    --text: #F1F5F9;
    --text-muted: #94A3B8;
    --text-subtle: #64748B;
    --brand: #EF4444;
    --brand-hover: #DC2626;
    --brand-subtle: #450A0A;
    --success: #22C55E;
    --success-subtle: #14532D;
    --warning: #F59E0B;
    --warning-subtle: #451A03;
    --danger: #EF4444;
    --danger-subtle: #450A0A;
    --info: #3B82F6;
    --info-subtle: #1E3A8A;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.2);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.5), 0 4px 10px rgba(0,0,0,.2);
}

/* ============================================================================
   LAYOUT AUTH (login, reset, invite)
   ============================================================================ */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(180deg, var(--bg) 0%, var(--bg-subtle) 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -.02em;
    margin-bottom: 8px;
}
.auth-logo .isi { color: var(--brand); }
.auth-logo .maps { color: var(--text); }

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
}

.auth-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 8px;
    color: var(--text);
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================================================
   FORM
   ============================================================================ */

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-subtle);
}
.form-input::placeholder { color: var(--text-subtle); }
.form-input:disabled { background: var(--bg-subtle); cursor: not-allowed; }

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}
.form-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
    cursor: pointer;
}

.form-help {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.form-error {
    margin-top: 6px;
    font-size: 12px;
    color: var(--danger);
}

.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 16px 0;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
    text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: var(--brand);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: var(--brand-hover);
    text-decoration: none;
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    text-decoration: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
}

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ============================================================================
   FLASH MESSAGES
   ============================================================================ */

.flash-stack {
    margin-bottom: 16px;
}

.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 8px;
    border-left: 3px solid;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.flash-success { background: var(--success-subtle); border-color: var(--success); color: var(--text); }
.flash-error   { background: var(--danger-subtle);  border-color: var(--danger);  color: var(--text); }
.flash-warning { background: var(--warning-subtle); border-color: var(--warning); color: var(--text); }
.flash-info    { background: var(--info-subtle);    border-color: var(--info);    color: var(--text); }

.flash-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 1px;
}

/* ============================================================================
   TOPBAR (per pagine logged-in)
   ============================================================================ */

.topbar {
    height: 56px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -.02em;
}
.topbar-logo .isi { color: var(--brand); }
.topbar-logo .maps { color: var(--text); }

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    margin: 0 32px;
}
.topbar-nav a {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
    transition: all .15s;
}
.topbar-nav a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.topbar-nav a.active { background: var(--brand-subtle); color: var(--brand); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text); }

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
}
.user-menu .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
}

/* ============================================================================
   PAGE CONTENT
   ============================================================================ */

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: var(--text);
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* ============================================================================
   CARDS
   ============================================================================ */

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
}
.card-body { padding: 20px; }

/* ============================================================================
   UTILITIES
   ============================================================================ */

.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }
.hidden { display: none; }

/* ============================================================================
   ANIMATIONS (sobrie)
   ============================================================================ */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn .25s ease-out; }

/* ============================================================================
   Giorno 4 — UI Tenant
   ============================================================================ */

/* Page header */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-title { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.page-subtitle { font-size: 14px; color: var(--text-muted); margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Breadcrumb */
/* Empty state */
.empty-card {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-elevated);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
}
.empty-card svg {
    width: 48px; height: 48px;
    color: var(--text-subtle);
    margin-bottom: 12px;
}

/* ============================================================================
   Hierarchy Card (sede/edificio/mappa) — markup identico per tutti i livelli
   ============================================================================ */

.hcard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}
@media (max-width: 1300px) { .hcard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px)  { .hcard-grid { grid-template-columns: 1fr; } }

.hcard {
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform .2s ease, border-color .15s, box-shadow .2s;
}
.hcard:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

/* Cover 4:3 — immagine contain con sfondo gradient sottile.
   Ospita il badge "kind" flottante in alto a sx e i pulsanti azione a dx. */
.hcard-cover {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: linear-gradient(135deg, #f8fafc 0%, #eef2f7 100%);
    overflow: hidden;
}
[data-theme="dark"] .hcard-cover {
    background: linear-gradient(135deg, #1f2937 0%, #0f1722 100%);
}
.hcard-cover-link {
    display: block;
    width: 100%;
    height: 100%;
    transition: transform .35s ease;
}
.hcard:hover .hcard-cover-link { transform: scale(1.03); }
.hcard-cover img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.hcard-cover-empty {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-subtle);
    opacity: 0.5;
}
.hcard-cover-empty svg { width: 56px; height: 56px; }

/* Badge "kind" flottante in alto-sinistra della cover: pill bianca con
   piccola ombra e testo brand color. Si distingue chiaramente sopra a
   qualsiasi immagine di sfondo. */
.hcard-kind-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    display: inline-block;
    font-size: 20px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--brand);
    background: rgba(255, 255, 255, 0.95);
    padding: 7px 16px;
    border-radius: 999px;
    line-height: 1.15;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2;
    pointer-events: none;
}
[data-theme="dark"] .hcard-kind-badge {
    background: rgba(30, 41, 59, 0.92);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* Variante "filigrana": testo grande semi-trasparente centrato sull'immagine.
   Sostituisce il pill in alto-sinistra quando il tenant sceglie lo stile
   "watermark" in Impostazioni → Aspetto.
   Bilanciamento: deve essere CHIARAMENTE leggibile (è un'etichetta, non un
   timbro decorativo) ma comunque trasparente per non coprire l'immagine.
   Uso ombra + stroke per rendere il testo netto su sfondi sia chiari sia scuri. */
.hcard-kind-watermark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(32px, 8vw, 64px);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.85);
    text-shadow:
        0 2px 6px rgba(0, 0, 0, 0.65),
        0 0 2px rgba(0, 0, 0, 0.9);
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.55);
    pointer-events: none;
    user-select: none;
    z-index: 2;
    /* Gradient overlay più marcato per garantire leggibilità anche su
       immagini molto chiare. */
    background: linear-gradient(180deg, rgba(0,0,0,0.08) 0%, rgba(0,0,0,0.4) 100%);
}
[data-theme="dark"] .hcard-kind-watermark {
    color: rgba(241, 245, 249, 0.88);
    text-shadow:
        0 2px 6px rgba(0, 0, 0, 0.8),
        0 0 2px rgba(0, 0, 0, 1);
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.7);
    background: linear-gradient(180deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.45) 100%);
}

/* Pulsanti azione (matita + cestino) sulla cover */
.hcard-actions {
    position: absolute; top: 8px; right: 8px;
    display: flex; gap: 4px;
    z-index: 2;
}
.hcard-action-btn {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,.15);
    background: rgba(255,255,255,.95);
    color: #4b5563;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,.1);
    transition: all .12s;
}
.hcard-action-btn:hover {
    background: #fff;
    color: #111827;
    border-color: rgba(0,0,0,.25);
}
.hcard-action-btn-danger:hover {
    background: var(--danger-subtle, #fef2f2);
    color: var(--danger, #dc2626);
    border-color: var(--danger, #dc2626);
}
.hcard-action-btn svg { width: 15px; height: 15px; }

/* Body cliccabile: titolo + meta (numero figli). Subito sotto alla cover,
   senza header separato. Hover cambia leggermente il colore del titolo. */
.hcard-body {
    display: block;
    padding: 14px 16px 12px;
    text-decoration: none;
    color: var(--text);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    transition: background .12s;
}
.hcard-body:hover {
    background: var(--bg-elevated);
    text-decoration: none;
}
.hcard-body:hover .hcard-title { color: var(--brand); }

.hcard-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    line-height: 1.25;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: -0.015em;
    transition: color .12s;
}
.hcard-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    line-height: 1.2;
}
.hcard-meta svg {
    flex-shrink: 0;
    color: var(--text-subtle);
}

/* Sottomenù figli */
.hcard-children {
    padding: 6px 8px;
    flex: 1;
    max-height: 180px;
    overflow-y: auto;
}
.hcard-children-empty {
    padding: 16px 8px;
    text-align: center;
}
.hcard-child-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    transition: background .12s;
}
.hcard-child-row:hover {
    background: var(--bg-hover);
    text-decoration: none;
}
.hcard-child-row-static { cursor: default; }
.hcard-child-row-static:hover { background: transparent; }
.hcard-child-name {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hcard-child-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-subtle);
    padding: 1px 8px;
    border-radius: 9px;
    flex-shrink: 0;
    min-width: 24px;
    text-align: center;
    font-weight: 500;
}

/* Pulsante "+ Aggiungi …" in fondo */
.hcard-add-btn {
    display: flex; align-items: center; justify-content: center;
    gap: 6px;
    padding: 9px 12px;
    background: none;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all .12s;
}
.hcard-add-btn:hover { background: var(--bg-hover); color: var(--brand); }

/* ============================================================================
   Modali (backdrop + card)
   ============================================================================ */

.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 1000;
    display: none;            /* JS lo cambia in 'flex' all'apertura */
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
    animation: modalFadeIn .18s ease-out;
}
.modal-backdrop[style*="flex"] { display: flex !important; }

@keyframes modalFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
    width: 100%;
    max-width: 540px;
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn .22s ease-out;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-card form {
    display: flex; flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 80px);
}

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 8px;
}
/* Pulsante "←" indietro nei modali annidati: sta a sinistra del title */
.modal-back-btn {
    flex-shrink: 0;
    margin-right: 4px;
    padding: 4px 6px;
    color: var(--text-muted);
}
.modal-back-btn:hover {
    background: var(--bg-hover, rgba(0,0,0,.05));
    color: var(--text);
}
/* Quando il back-btn è presente, il title prende lo spazio rimanente */
.modal-header .modal-back-btn + .modal-title {
    flex: 1;
    margin-left: 0;
}
.modal-title {
    font-size: 16px; font-weight: 600; margin: 0;
    line-height: 1.3;
    flex: 1;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.modal-footer {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-subtle);
    flex-shrink: 0;
}

/* Mobile: la card prende quasi tutto lo schermo */
@media (max-width: 640px) {
    .modal-backdrop { padding: 16px 10px; align-items: stretch; }
    .modal-card { max-width: 100%; max-height: 100%; }
}

/* Link sulla cover (cliccabile, ma sotto i pulsanti edit/delete) */
.hcard-cover-link {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: block;
}
.hcard-cover-link img {
    width: 100%; height: 100%;
    object-fit: contain;
    display: block;
}
.hcard-cover-link .hcard-cover-empty {
    width: 100%; height: 100%;
}
/* Pulsanti edit/delete sopra al link */
.hcard-actions { z-index: 3; }

/* Card senza sottomenù né pulsante: header più ampio */
.hcard:has(.hcard-cover):not(:has(.hcard-children)):not(:has(.hcard-add-btn)) .hcard-header {
    border-bottom: none;
    flex: 1;
    padding: 14px 16px;
}

/* X di chiusura modali — versione grande ed evidente */
.modal-header .btn-icon,
.modal-header button[onclick*="closeModal"],
.modal-header button[onclick*="hcardCloseModal"],
.modal-header button[onclick*="display='none'"] {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 24px;
    line-height: 1;
    font-weight: 400;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .12s;
    padding: 0;
    flex-shrink: 0;
}
.modal-header .btn-icon:hover,
.modal-header button[onclick*="closeModal"]:hover,
.modal-header button[onclick*="hcardCloseModal"]:hover,
.modal-header button[onclick*="display='none'"]:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border);
}

/* Breadcrumb bar con tasto indietro */
.breadcrumb-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 4px 8px;
    position: relative;
    min-height: 36px;
}
.breadcrumb-back {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-muted);
    text-decoration: none;
    transition: all .12s;
}
.breadcrumb-back svg { width: 16px; height: 16px; }
.breadcrumb-back:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border-strong);
    text-decoration: none;
}
.breadcrumb-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    /* niente più flex-wrap: il nav resta su una riga e il back è
       centrato verticalmente rispetto a quella riga (#1) */
    flex-wrap: nowrap;
    justify-content: center;
    line-height: 1.4;
}
.breadcrumb-nav a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 5px;
    transition: all .12s;
}
.breadcrumb-nav a:hover {
    background: var(--bg-hover);
    color: var(--brand);
    text-decoration: none;
}
.breadcrumb-nav .breadcrumb-sep {
    color: var(--text-subtle);
    font-weight: 300;
}
.breadcrumb-nav .breadcrumb-current {
    color: var(--text);
    font-weight: 600;
    padding: 2px 6px;
}

/* ============================================================
   Round 58: Parent context card (#3)
   "Edificio: <nome>" / "Sede: <nome>" sopra la lista subordinata
   ============================================================ */
.parent-context-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.parent-context-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--brand-subtle, rgba(220,38,38,0.08));
    color: var(--brand);
    display: flex;
    align-items: center;
    justify-content: center;
}
.parent-context-icon svg {
    width: 24px;
    height: 24px;
}
.parent-context-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.parent-context-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    font-weight: 700;
}
.parent-context-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================================
   IsiDialog — alert/confirm stilizzati che sostituiscono i modali nativi del
   browser. Stesso linguaggio dei modali principali (card centrata, backdrop
   semi-trasparente). Auto-adattivo al tema dark via CSS vars.
   ============================================================================ */
.isi-dialog-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .55);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
    padding: 24px;
    animation: isiDialogFadeIn .15s ease-out;
}
@keyframes isiDialogFadeIn { from { opacity: 0; } to { opacity: 1; } }

.isi-dialog-card {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    overflow: hidden;
    animation: isiDialogSlideIn .18s ease-out;
}
@keyframes isiDialogSlideIn {
    from { opacity: 0; transform: translateY(-10px) scale(.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.isi-dialog-body {
    display: flex;
    gap: 14px;
    padding: 22px 24px 18px;
    align-items: flex-start;
}
.isi-dialog-icon {
    flex-shrink: 0;
    width: 44px; height: 44px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.isi-dialog-icon svg { width: 24px; height: 24px; }
.isi-dialog-content { flex: 1; min-width: 0; }
.isi-dialog-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 6px;
    line-height: 1.3;
}
.isi-dialog-message {
    font-size: 14px;
    color: var(--text);
    line-height: 1.55;
    margin: 0;
    word-break: break-word;
}

/* Bottoni allineati a destra, separatore visivo dal body */
.isi-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 24px 20px;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border);
}

/* Kind: icona colorata e fondo sottilmente tinto. I --*-subtle adattano al tema. */
.isi-dialog-kind-info     .isi-dialog-icon { background: var(--info-subtle);    color: var(--info); }
.isi-dialog-kind-warning  .isi-dialog-icon { background: var(--warning-subtle); color: var(--warning); }
.isi-dialog-kind-danger   .isi-dialog-icon { background: var(--danger-subtle);  color: var(--danger); }
.isi-dialog-kind-success  .isi-dialog-icon { background: var(--success-subtle); color: var(--success); }
.isi-dialog-kind-question .isi-dialog-icon { background: var(--brand-subtle);   color: var(--brand); }

/* Responsive: su schermi stretti la card si stringe e i padding scalano */
@media (max-width: 520px) {
    .isi-dialog-backdrop { padding: 12px; }
    .isi-dialog-body { padding: 18px 18px 14px; }
    .isi-dialog-footer { padding: 12px 18px 16px; }
    .isi-dialog-title { font-size: 16px; }
}
