:root {
    --med-primary: #0d9488;
    --med-dark: #0f766e;
    --med-bg: #e6f4f1;
    --med-card-bg: #f0fdfa;
    --med-border: #99f6e4;
    --med-text: #064e3b;
    --med-header-bg: #ccfbf1;
    --readonly-bg: #e2e8f0;
}

/* Corpo bloccato a schermo intero solo su desktop */
html, body {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 6px;
    background-color: var(--med-bg);
    color: var(--med-text);
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: 100vh;
    overflow: hidden;
}

/* Sezione superiore (Anagrafica): altezza bilanciata e bloccata su desktop */
.scrollable-section-top {
    height: 65vh;
    max-height: 65vh;
    overflow-y: auto;   
    padding-right: 4px;
    border-bottom: 2px dashed var(--med-border);
    padding-bottom: 4px;
    box-sizing: border-box;
}

/* Sezione inferiore (Visite): espansa per contemplare tutti i campi comodamente */
.scrollable-section-bottom {
    height: 44vh;
    max-height: 44vh;
    overflow-y: auto;
    padding-right: 4px;
    box-sizing: border-box;
}

.card {
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    background-color: var(--med-card-bg);
    border: 1.5px solid var(--med-border);
    margin-bottom: 6px;
    box-sizing: border-box;
}

.search-card-compact {
    width: 536px;
    box-sizing: border-box;
}

.equal-height-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    margin-bottom: 0;
}

.equal-height-card .table-container {
    flex: 1;
    overflow-y: auto;
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1.5px solid var(--med-border);
    padding-bottom: 3px;
    margin-bottom: 6px;
}

h2 { 
    margin: 0; 
    font-size: 0.88rem; 
}

.grid-2col {
    display: grid;
    grid-template-columns: 240px 288px;
    gap: 8px;
    margin-bottom: 6px;
    align-items: stretch;
}

.search-row-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.form-group {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 2px;
}

label {
    flex: 0 0 60px;
    font-size: 0.62rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

input, select, textarea {
    flex: 1;
    max-width: 140px;
    min-width: 0;
    padding: 2px 3px;
    border: 1px solid #cbd5e1;
    border-radius: 3px;
    box-sizing: border-box;
    font-size: 0.68rem;
    background-color: #ffffff;
}

textarea {
    resize: vertical;
    max-width: 100%;
}

input[readonly], textarea[readonly], select[disabled] {
    background-color: var(--readonly-bg) !important;
    color: #475569 !important;
    font-weight: bold;
    cursor: not-allowed;
}

.btn-container {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    margin-bottom: 0;
}

button.submit-btn {
    flex: 1;
    padding: 5px 3px;
    border: none;
    border-radius: 3px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.72rem;
}

.btn-med { 
    background-color: var(--med-primary); 
}

.btn-secondary {
    background-color: #64748b;
    color: white;
    border: none;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 0.68rem;
    cursor: pointer;
}

.btn-secondary:hover { 
    background-color: #475569; 
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4px;
    background: #ffffff;
    border-radius: 4px;
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: 4px 5px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.72rem;
    vertical-align: top;
}

tbody tr {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

tbody tr:hover {
    background-color: #f1f5f9 !important;
}

th { 
    background-color: var(--med-header-bg); 
    color: var(--med-text); 
    position: sticky;
    top: 0;
    z-index: 1;
}

.photo-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-top: 2px;
    flex: 1;
}

.photo-card {
    width: 28px;
    height: 28px;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    position: relative;
}

.photo-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tag { 
    padding: 1px 4px; 
    border-radius: 6px; 
    font-size: 0.62rem; 
    font-weight: bold; 
    display: inline-block; 
}

.tag-med { 
    background: #ccfbf1; 
    color: #0f766e; 
}

.badge-view {
    background-color: #fef08a;
    color: #854d0e;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.62rem;
    font-weight: bold;
}

.hidden { 
    display: none; 
}

/* =========================================================
   STILI DEDICATI AI DISPOSITIVI MOBILI (Smartphone e Tablet)
   ========================================================= */
@media screen and (max-width: 768px) {

    /* Sblocca l'altezza fissa del body su mobile per consentire lo scorrimento naturale */
    html, body {
        height: auto !important;
        overflow: auto !important;
        padding: 4px !important;
    }

    /* Rilascia le altezze fisse delle sezioni superiore e inferiore */
    .scrollable-section-top,
    .scrollable-section-bottom {
        height: auto !important;
        max-height: none !important;
        overflow-y: visible !important;
        border-bottom: 2px solid var(--med-border);
        padding-bottom: 12px;
        margin-bottom: 12px;
    }

    /* Annulla la griglia a 2 colonne fisse e adatta tutto in colonna singola */
    .grid-2col {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
    }

    /* Adatta la scheda di ricerca e le card a tutta larghezza */
    .search-card-compact,
    .card,
    .equal-height-card {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        height: auto !important;
    }

    /* Dis dispone i form group in colonna o blocco fluido per facilitare la scrittura */
    .form-group {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 4px !important;
        margin-bottom: 8px !important;
    }

    label {
        flex: unset !important;
        font-size: 0.75rem !important;
        width: 100% !important;
    }

    /* Input, select e textarea a larghezza piena e dimensione touch (16px evita lo zoom su iOS) */
    input[type="text"],
    input[type="date"],
    input[type="number"],
    select,
    textarea {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 16px !important; 
        padding: 10px !important;
        box-sizing: border-box !important;
    }

    /* Pulsanti grandi e comodi per il tocco con il pollice */
    button, .btn, button.submit-btn, .btn-secondary {
        width: 100% !important;
        min-height: 48px !important;
        font-size: 16px !important;
        padding: 10px !important;
        margin: 6px 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
    }

    .btn-container {
        flex-direction: column !important;
        gap: 6px !important;
    }

    /* Tabelle ottimizzate per lo scorrimento orizzontale su mobile */
    .table-responsive, .table-container {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    table {
        width: 100% !important;
        font-size: 13px !important;
    }

    th, td {
        padding: 8px 6px !important;
    }

    /* Miniature delle foto più grandi e comode da gestire su smartphone */
    .photo-card {
        width: 60px !important;
        height: 60px !important;
    }

    .photo-preview-container {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
}
