/* ========================================
   MED-OS Compliance Layer
   Authentication Gate | Cookie Consent | Legal Footer
   Primary color: #167D87 (Verde Polimed)
   ======================================== */

/* ── AUTHENTICATION GATE ── */
#medos-auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 99998;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px) saturate(1.2);
    -webkit-backdrop-filter: blur(12px) saturate(1.2);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

#medos-auth-overlay.active {
    opacity: 1;
    pointer-events: all;
}

#medos-auth-overlay:not(.active),
#medos-auth-overlay.hidden {
    display: none !important;
    pointer-events: none !important;
    opacity: 0 !important;
    z-index: -9999 !important;
}

/* Force event pipeline restoration on root elements */
html, body {
    pointer-events: auto !important;
}

#medos-auth-overlay.locked .main-container,
#medos-auth-overlay.locked header,
#medos-auth-overlay.locked .left-sidebar {
    filter: blur(6px);
}

.medos-auth-card {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
    width: 420px;
    max-width: 92vw;
    padding: 42px 36px 36px;
    text-align: center;
    animation: authSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes authSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.medos-auth-card h2 {
    margin: 0 0 8px;
    font-size: 1.35em;
    font-weight: 800;
    color: #167D87;
    letter-spacing: -0.3px;
}

.medos-auth-card p {
    margin: 0 0 28px;
    font-size: 0.9em;
    color: #7f8c8d;
}

.medos-auth-card .form-group {
    text-align: left;
    margin-bottom: 18px;
}

.medos-auth-card label {
    display: block;
    font-size: 0.72em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #555;
    margin-bottom: 6px;
}

.medos-auth-card input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1.5px solid #e0e6ed;
    border-radius: 8px;
    font-size: 0.95em;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.medos-auth-card input:focus {
    border-color: #167D87;
    box-shadow: 0 0 0 3px rgba(22, 125, 135, 0.12);
}

.medos-auth-card .btn-accedi {
    width: 100%;
    height: 46px;
    background: #167D87;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    margin-top: 8px;
}

.medos-auth-card .btn-accedi:hover {
    background: #0f5a61;
    transform: translateY(-1px);
}

.medos-auth-card .btn-accedi:active {
    transform: translateY(0);
}

.medos-auth-card .auth-error {
    color: #e74c3c;
    font-size: 0.82em;
    margin-top: 12px;
    min-height: 1.2em;
}

/* ── COOKIE CONSENT BANNER ── */
#medos-cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 99997;
    background: #ffffff;
    border-top: 1px solid #e0e6ed;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
    padding: 10px 24px;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: nowrap;
}

#medos-cookie-banner.active {
    display: flex;
}

.medos-cookie-text {
    flex: 1 1 auto;
    font-size: 0.78em;
    color: #4a4a4a;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.medos-cookie-text strong {
    color: #167D87;
}

.medos-cookie-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.medos-cookie-btn {
    height: 32px;
    padding: 0 14px;
    border-radius: 6px;
    font-size: 0.78em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.medos-cookie-btn.accetta {
    background: #167D87;
    color: #fff;
}

.medos-cookie-btn.accetta:hover {
    background: #0f5a61;
}

.medos-cookie-btn.rifiuta {
    background: #f4f7f6;
    color: #555;
    border: 1px solid #d0d5dd;
}

.medos-cookie-btn.rifiuta:hover {
    background: #e8f0f1;
    color: #c0392b;
    border-color: #e8b4b0;
}

.medos-cookie-btn.personalizza {
    background: transparent;
    color: #167D87;
    border: 1px solid #167D87;
}

.medos-cookie-btn.personalizza:hover {
    background: rgba(22, 125, 135, 0.06);
}

/* Cookie preferences modal */
#medos-cookie-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
}

#medos-cookie-modal.active {
    display: flex;
}

.medos-cookie-modal-card {
    background: #fff;
    border-radius: 12px;
    width: 480px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    padding: 28px 32px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    animation: authSlideIn 0.3s ease both;
}

.medos-cookie-modal-card h3 {
    margin: 0 0 6px;
    font-size: 1.15em;
    color: #167D87;
}

.medos-cookie-modal-card p {
    font-size: 0.85em;
    color: #7f8c8d;
    margin: 0 0 20px;
}

.medos-cookie-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid #f0f0f0;
}

.medos-cookie-toggle:last-of-type {
    border-bottom: none;
    margin-bottom: 20px;
}

.medos-cookie-toggle label {
    font-size: 0.9em;
    font-weight: 600;
    color: #333;
}

.medos-cookie-toggle span {
    font-size: 0.78em;
    color: #95a5a6;
}

/* Toggle switch */
.medos-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.medos-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.medos-switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #d0d5dd;
    border-radius: 24px;
    transition: 0.25s;
}

.medos-switch .slider:before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.25s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.medos-switch input:checked + .slider {
    background: #167D87;
}

.medos-switch input:checked + .slider:before {
    transform: translateX(20px);
}

.medos-switch input:disabled + .slider {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── BANNER ACTIVE: padding dinamico per non coprire il contenuto ── */
body.medos-cookie-banner-active .main-container {
    padding-bottom: 56px !important;
}

/* ── LEGAL FOOTER ── */
#medos-legal-footer {
    position: relative;
    background: #f8fafa;
    border-top: 1px solid #e0e6ed;
    padding: 8px 24px 2px;
    margin-bottom: 0;
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 0.78em;
    color: #7f8c8d;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    width: 100%;
    box-sizing: border-box;
}

#medos-legal-footer a {
    color: #167D87;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
    cursor: pointer;
}

#medos-legal-footer a:hover {
    color: #0f5a61;
    text-decoration: underline;
}

/* ── LEGAL MODALS ── */
.medos-legal-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
}

.medos-legal-modal.active {
    display: flex;
}

.medos-legal-card {
    background: #fff;
    border-radius: 12px;
    width: 640px;
    max-width: 92vw;
    max-height: 80vh;
    overflow-y: auto;
    padding: 32px 36px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    animation: authSlideIn 0.3s ease both;
}

.medos-legal-card h3 {
    margin: 0 0 12px;
    font-size: 1.2em;
    color: #167D87;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.medos-legal-card .close-btn {
    font-size: 1.4em;
    color: #95a5a6;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.medos-legal-card .close-btn:hover {
    color: #e74c3c;
}

.medos-legal-card p,
.medos-legal-card li {
    font-size: 0.88em;
    color: #444;
    line-height: 1.7;
}

.medos-legal-card ul {
    padding-left: 20px;
    margin: 10px 0;
}

/* Footer injected inside .main-container to avoid breaking body flex layout */
.main-container #medos-legal-footer {
    position: relative;
    flex-shrink: 0;
}

/* ============================================================
   GDPR ACTIVE OPT-IN — Unchecked checkbox guidance
   ============================================================ */
input[type="checkbox"].gdpr-unchecked:focus,
input[type="checkbox"]#p-consenso-privacy:focus,
input[type="checkbox"]#p-consenso-marketing:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(22, 125, 135, 0.25);
    border-color: #167D87 !important;
}

.privacy-row input[type="checkbox"]:not(:checked) + .slider {
    border: 2px solid #167D87;
    box-shadow: 0 0 0 2px rgba(22, 125, 135, 0.15);
}

/* ============================================================
   DOSEREC MODAL — D.M. 3 Novembre 2023
   ============================================================ */
#medos-doserec-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

#medos-doserec-modal.active {
    display: flex;
}

.medos-doserec-card {
    background: #fff;
    border-radius: 14px;
    width: 520px;
    max-width: 94vw;
    padding: 32px 36px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.2);
    animation: authSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
    border-top: 5px solid #167D87;
}

.medos-doserec-card h3 {
    margin: 0 0 8px;
    font-size: 1.15em;
    font-weight: 800;
    color: #167D87;
    display: flex;
    align-items: center;
    gap: 10px;
}

.medos-doserec-card p {
    font-size: 0.88em;
    color: #555;
    line-height: 1.65;
    margin: 0 0 20px;
}

.medos-doserec-card .doserec-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border: 1.5px solid #e0e6ed;
    border-radius: 8px;
    margin-bottom: 20px;
    background: #fafcfc;
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.medos-doserec-card .doserec-row:hover {
    border-color: #167D87;
    box-shadow: 0 0 0 3px rgba(22, 125, 135, 0.08);
}

.medos-doserec-card .doserec-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #167D87;
    margin-top: 2px;
    flex-shrink: 0;
    cursor: pointer;
}

.medos-doserec-card .doserec-row label {
    font-size: 0.85em;
    font-weight: 600;
    color: #333;
    line-height: 1.5;
    cursor: pointer;
}

.medos-doserec-card .doserec-row small {
    display: block;
    font-size: 0.78em;
    color: #7f8c8d;
    margin-top: 4px;
    font-weight: 400;
}

.medos-doserec-card .doserec-error {
    color: #e74c3c;
    font-size: 0.82em;
    min-height: 1.3em;
    margin-bottom: 12px;
}

.medos-doserec-card .doserec-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.medos-doserec-card .doserec-actions button {
    height: 40px;
    padding: 0 18px;
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.medos-doserec-card .doserec-actions .btn-confirm {
    background: #167D87;
    color: #fff;
}

.medos-doserec-card .doserec-actions .btn-confirm:hover {
    background: #0f5a61;
}

.medos-doserec-card .doserec-actions .btn-cancel {
    background: #f4f7f6;
    color: #555;
    border: 1px solid #d0d5dd;
}

.medos-doserec-card .doserec-actions .btn-cancel:hover {
    background: #e8f0f1;
    color: #c0392b;
    border-color: #e8b4b0;
}

/* ============================================================
   Cross-view footer anchoring (sidebar offset)
   ============================================================ */
body.has-sidebar #medos-legal-footer {
    left: 240px; /* standard sidebar width */
}

@media (max-width: 768px) {
    body.has-sidebar #medos-legal-footer {
        left: 0;
    }
}
