/**
 * Semplificazione UI 2026-11: area visita.
 * Caricato su tutte le pagine /app/ dopo medaid-ui.css (vedi medaid.php).
 */

/* =====================================================================
 * Compilazione della visita (templates/app/visite/nuova.php +
 * assets/js/visit-compose.js): moderna (schede + finestra) o a scorrimento.
 * ===================================================================== */

/* ---------- Barra delle sezioni e scelta del modo ---------- */

#visit-form .medaid-visit-compose-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 14px 20px 10px;
    border-top: 1px solid var(--medaid-border, #e9ecef);
}

.medaid-visit-compose-bar-title {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 10px;
    font-size: 0.9375rem;
}

.medaid-visit-compose-count {
    font-size: 0.8125rem;
    color: var(--medaid-text-muted, #6c757d);
}

.medaid-visit-compose-count.has-to-fill {
    color: #9a3412;
}

.medaid-visit-compose-switch {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: 999px;
    background: var(--medaid-gray-100, #f1f3f5);
}

.medaid-visit-compose-switch-btn {
    min-height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--medaid-text-secondary, #495057);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--medaid-motion-fast, 140ms) ease, color var(--medaid-motion-fast, 140ms) ease;
}

.medaid-visit-compose-switch-btn[aria-pressed="true"] {
    background: var(--medaid-bg-elevated, #fff);
    color: var(--medaid-primary, #3A6A6A);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.medaid-visit-compose-switch-btn:focus-visible {
    outline: 2px solid var(--medaid-primary, #3A6A6A);
    outline-offset: 2px;
}

/* ---------- Modo moderno: le sezioni vere stanno nascoste, si vedono le schede ---------- */

/* Solo con lo script avviato (medaid-compose-ready): senza, il form resta a scorrimento. */
#visit-form.medaid-fill-moderna.medaid-compose-ready > [data-visit-section]:not(.medaid-unit-inline),
#visit-form.medaid-fill-moderna.medaid-compose-ready > .medaid-module-section-wrapper:not(.medaid-unit-inline) {
    display: none !important;
}

#visit-form.medaid-fill-scorrimento .medaid-visit-cards,
#visit-form:not(.medaid-compose-ready) .medaid-visit-cards,
#visit-form:not(.medaid-compose-ready) .medaid-visit-compose-switch {
    display: none;
}

.medaid-visit-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    padding: 4px 20px 20px;
}

.medaid-visit-cards:empty {
    display: none;
}

.medaid-vcard {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    min-height: 88px;
    padding: 14px 40px 14px 16px;
    text-align: left;
    font: inherit;
    color: var(--medaid-text, #212529);
    background: var(--medaid-bg-elevated, #fff);
    border: 1px solid var(--medaid-border, #e9ecef);
    border-radius: var(--medaid-radius, 10px);
    cursor: pointer;
    transition: border-color var(--medaid-motion-fast, 140ms) ease, box-shadow var(--medaid-motion-fast, 140ms) ease, transform var(--medaid-motion-fast, 140ms) var(--medaid-ease-out, ease-out);
}

.medaid-vcard:hover {
    border-color: var(--medaid-primary, #3A6A6A);
    box-shadow: 0 4px 14px rgba(46, 35, 94, 0.08);
}

.medaid-vcard:active {
    transform: scale(0.99);
}

.medaid-vcard:focus-visible {
    outline: 2px solid var(--medaid-primary, #3A6A6A);
    outline-offset: 2px;
}

/* Indicazione leggera: la sezione vuota ha solo l'etichetta "Da compilare" (e un bordo
   appena più caldo); quella compilata il segno di spunta. Niente fondi colorati. */
.medaid-vcard.is-empty {
    border-color: rgba(232, 89, 12, 0.28);
}

.medaid-vcard.is-filled {
    border-color: var(--medaid-border, #e9ecef);
}

.medaid-vcard-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
}

.medaid-vcard-title {
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.3;
}

.medaid-vcard-done {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--medaid-primary, #3A6A6A);
}

.medaid-vcard-preview {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--medaid-text-secondary, #495057);
    min-width: 0;
}

.medaid-vcard-line {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.medaid-vcard-label {
    color: var(--medaid-text-muted, #6c757d);
}

.medaid-vcard-label::after {
    content: ':';
}

.medaid-vcard-hint {
    color: var(--medaid-text-muted, #6c757d);
}

.medaid-vcard-chevron {
    position: absolute;
    top: 50%;
    right: 12px;
    display: flex;
    color: var(--medaid-text-muted, #6c757d);
    transform: translateY(-50%);
}

/* ---------- Modo a scorrimento: indicazione leggera sulle sezioni vuote ---------- */

/* Basta l'etichetta "Da compilare" accanto al titolo: niente barre colorate. */
#visit-form .card-header.medaid-vsec-empty {
    box-shadow: none;
}

#visit-form .medaid-vsec-badge {
    margin-left: 10px;
    vertical-align: middle;
    font-size: 0.6875rem;
}

#visit-form.medaid-fill-scorrimento .medaid-section-collapsible {
    min-height: 44px;
}

/* ---------- Finestra della sezione ---------- */

.medaid-vsheet {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.medaid-vsheet[hidden] {
    display: none;
}

.medaid-vsheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(33, 37, 41, 0.42);
    opacity: 0;
    transition: opacity var(--medaid-motion-fast, 140ms) ease;
}

.medaid-vsheet-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 860px;
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    background: var(--medaid-bg-elevated, #fff);
    color: var(--medaid-text, #212529);
    border-radius: var(--medaid-radius-lg, 14px);
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.28);
    opacity: 0;
    transform: translateY(12px) scale(0.985);
    transition: opacity var(--medaid-motion-fast, 140ms) ease, transform var(--medaid-motion, 200ms) var(--medaid-ease-out, ease-out);
    outline: none;
}

.medaid-vsheet.is-open .medaid-vsheet-backdrop {
    opacity: 1;
}

.medaid-vsheet.is-open .medaid-vsheet-panel {
    opacity: 1;
    transform: none;
}

/* A transizione finita niente transform: i widget delle mappature usano position:fixed. */
.medaid-vsheet.is-settled .medaid-vsheet-panel {
    transition: none;
}

/* Mappature e widget grandi: finestra all'85% dello schermo (a tutto schermo solo su telefono). */
.medaid-vsheet.is-fullscreen {
    padding: 0;
}

.medaid-vsheet.is-fullscreen .medaid-vsheet-panel {
    width: 85vw;
    max-width: none;
    height: 85vh;
    height: 85dvh;
    max-height: none;
}

@media (max-width: 640px) {
    .medaid-vsheet.is-fullscreen .medaid-vsheet-panel {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }
}

.medaid-vsheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 12px 12px 20px;
    border-bottom: 1px solid var(--medaid-border, #e9ecef);
}

.medaid-vsheet-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    min-width: 0;
}

.medaid-vsheet-title {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.3;
}

.medaid-vsheet-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--medaid-text-muted, #6c757d);
    cursor: pointer;
}

.medaid-vsheet-close:hover {
    background: var(--medaid-gray-100, #f1f3f5);
    color: var(--medaid-text, #212529);
}

.medaid-vsheet-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* L'intestazione della sezione e' gia' nel titolo della finestra. */
.medaid-vsheet-body > .card-header[data-visit-section],
.medaid-vsheet-body > .medaid-module-section-wrapper > .card-header {
    display: none !important;
}

.medaid-vsheet-body > .medaid-module-section-wrapper {
    display: block !important;
}

.medaid-vsheet-body .medaid-section-content {
    max-height: none;
}

/* Contenuto allineato al titolo della finestra: con la densita' compatta il corpo
   della sezione ha 8px e a tutto schermo i campi toccavano il bordo. */
.medaid-vsheet-body > .medaid-visit-section-body,
.medaid-vsheet-body > .medaid-module-section-wrapper > .medaid-visit-section-body {
    padding: 14px 20px;
}

@media (max-width: 575px) {
    .medaid-vsheet-body > .medaid-visit-section-body,
    .medaid-vsheet-body > .medaid-module-section-wrapper > .medaid-visit-section-body {
        padding: 12px 14px;
    }
}

.medaid-vsheet-body.is-swapping {
    animation: medaidVsheetSwap var(--medaid-motion, 200ms) var(--medaid-ease-out, ease-out);
}

@keyframes medaidVsheetSwap {
    from { opacity: 0.2; }
    to { opacity: 1; }
}

.medaid-vsheet-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--medaid-border, #e9ecef);
}

.medaid-vsheet-footer .medaid-btn {
    min-height: 44px;
}

.medaid-vsheet-prev {
    margin-right: auto;
}

.medaid-vsheet-footer [hidden] {
    display: none !important;
}

/* Telefono: la finestra sale dal basso e occupa lo schermo. */
@media (max-width: 640px) {
    .medaid-vsheet {
        align-items: flex-end;
        padding: 0;
    }

    .medaid-vsheet-panel {
        max-height: 100vh;
        max-height: 100dvh;
        height: 100%;
        border-radius: 0;
        transform: translateY(24px);
    }

    .medaid-vsheet-footer {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .medaid-visit-cards {
        grid-template-columns: 1fr;
        padding-left: 16px;
        padding-right: 16px;
    }

    #visit-form .medaid-visit-compose-bar {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ---------- Pulsanti di fondo pagina ---------- */

#visit-form .medaid-visit-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px 10px;
}

#visit-form .medaid-visit-actions .medaid-btn {
    min-height: 44px;
}

.medaid-visit-actions-note {
    flex-basis: 100%;
    margin: 0;
    font-size: 0.8125rem;
    color: var(--medaid-text-secondary, #495057);
}

.medaid-visit-autosave-status {
    margin-right: auto;
    font-size: 0.8125rem;
    color: var(--medaid-text-muted, #6c757d);
}

.medaid-visit-cancel-link {
    min-height: 44px;
    padding: 0 8px;
    border: 0;
    background: none;
    color: var(--medaid-danger-strong, #b91c1c);
    font: inherit;
    font-size: 0.875rem;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

.medaid-visit-cancel-link:hover {
    color: #991b1b;
}

/* ---------- Bozza da riprendere ---------- */

.medaid-visit-draft-restore {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    margin-bottom: 16px;
    padding: 10px 14px;
    border-radius: var(--medaid-radius, 10px);
    background: var(--medaid-primary-light, rgba(58, 106, 106, 0.08));
    font-size: 0.875rem;
}

.medaid-visit-draft-restore[hidden] {
    display: none;
}

.medaid-visit-draft-restore-actions {
    display: inline-flex;
    gap: 8px;
}

.medaid-visit-draft-restore-actions .medaid-btn {
    min-height: 44px;
}

/* ---------- Altri dati registrati (modifica) ---------- */

.medaid-visit-other-data {
    margin: 0 20px 16px;
    border: 1px dashed var(--medaid-border, #dee2e6);
    border-radius: var(--medaid-radius, 10px);
    background: var(--medaid-gray-50, #f8f9fa);
}

.medaid-visit-other-data > summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
    min-height: 44px;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
}

.medaid-visit-other-data-hint {
    font-weight: 400;
    font-size: 0.8125rem;
    color: var(--medaid-text-muted, #6c757d);
}

.medaid-visit-other-data-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px 16px;
    margin: 0;
    padding: 0 16px 14px;
}

.medaid-visit-other-data-item dt {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--medaid-text-muted, #6c757d);
}

.medaid-visit-other-data-item dd {
    margin: 2px 0 0;
    font-size: 0.875rem;
    white-space: pre-line;
    word-break: break-word;
}

.medaid-visit-category-hint {
    margin: -6px 0 0;
    font-size: 0.8125rem;
    color: var(--medaid-text-muted, #6c757d);
}

/* ---------- Tema scuro ---------- */

[data-theme="dark"] .medaid-visit-compose-switch {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .medaid-visit-compose-count.has-to-fill {
    color: #fdba74;
}

[data-theme="dark"] .medaid-vcard.is-empty {
    border-color: rgba(253, 186, 116, 0.3);
}

[data-theme="dark"] .medaid-vsheet-backdrop {
    background: rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .medaid-vsheet-panel {
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .medaid-vsheet-close:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .medaid-visit-other-data {
    background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .medaid-visit-cancel-link {
    color: #fca5a5;
}

/* ---------- Movimento ridotto ---------- */

@media (prefers-reduced-motion: reduce) {
    .medaid-vsheet-backdrop,
    .medaid-vsheet-panel,
    .medaid-vcard,
    .medaid-visit-compose-switch-btn {
        transition: none !important;
    }

    .medaid-vsheet-panel {
        transform: none !important;
    }

    .medaid-vsheet-body.is-swapping {
        animation: none;
    }
}
