:root {
    --primary: #075e54;
    --primary-dark: #054c44;
    --accent: #25d366;
    --background: #efeae2;
    --panel: #ffffff;
    --header: #f0f2f5;
    --border: #e1e4e7;
    --text: #111b21;
    --muted: #667781;
    --danger: #b42318;
    --success: #067647;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        sans-serif;
    color: var(--text);
}

body {
    background: var(--background);
}

button,
input {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

/* LOGIN */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        linear-gradient(
            to bottom,
            var(--primary) 0,
            var(--primary) 220px,
            #e7e5df 220px,
            #e7e5df 100%
        );
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 14px 45px rgba(0, 0, 0, 0.16);
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 28px;
}

.auth-logo-icon,
.brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
    border-radius: 50%;
}

.auth-logo-icon {
    width: 58px;
    height: 58px;
    font-size: 20px;
}

.auth-logo h1 {
    margin: 0;
    font-size: 25px;
}

.auth-logo p {
    margin: 3px 0 0;
    color: var(--muted);
}

.auth-card label {
    display: block;
    margin: 17px 0 7px;
    font-size: 14px;
    font-weight: 600;
}

.auth-card input {
    width: 100%;
    height: 48px;
    padding: 0 13px;
    border: 1px solid #cfd4d8;
    border-radius: 8px;
    outline: none;
}

.auth-card input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(7, 94, 84, 0.12);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 20px;
    border: 0;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

.button.primary {
    background: var(--primary);
    color: #ffffff;
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.full {
    width: 100%;
    margin-top: 24px;
}

.alert {
    padding: 13px 15px;
    margin-bottom: 18px;
    border-radius: 8px;
    font-size: 14px;
}

.alert-error {
    background: #fef3f2;
    color: var(--danger);
    border: 1px solid #fecdca;
}

.alert-success {
    background: #ecfdf3;
    color: var(--success);
    border: 1px solid #abefc6;
}

/* APP */

.app-page {
    height: 100vh;
    overflow: hidden;
}

.app-shell {
    display: grid;
    grid-template-columns: 410px 1fr;
    width: 100%;
    height: 100vh;
    background: var(--panel);
}

.sidebar {
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: #ffffff;
}

.sidebar-header {
    height: 64px;
    flex: 0 0 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    background: var(--header);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    font-size: 15px;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.icon-button {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--muted);
    font-size: 23px;
}

.icon-button:hover {
    background: rgba(0, 0, 0, 0.07);
}

.search-area {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.search-area input {
    width: 100%;
    height: 38px;
    padding: 0 15px;
    border: 0;
    border-radius: 8px;
    background: var(--header);
    outline: none;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    min-height: 72px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 13px;
    border-bottom: 1px solid #f0f2f5;
}

.conversation-item:hover {
    background: #f5f6f6;
}

.avatar {
    width: 49px;
    height: 49px;
    flex: 0 0 49px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #dfe5e7;
    color: var(--primary);
    font-size: 19px;
    font-weight: 800;
}

.conversation-content {
    min-width: 0;
    flex: 1;
}

.conversation-top,
.conversation-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.conversation-top strong,
.conversation-bottom span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.conversation-top strong {
    font-size: 16px;
}

.conversation-top time,
.conversation-bottom span {
    color: var(--muted);
    font-size: 12px;
}

.conversation-bottom {
    margin-top: 5px;
}

.unread-badge {
    min-width: 21px;
    height: 21px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--accent);
    color: #ffffff;
    font-size: 11px;
}

.welcome-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
    background:
        radial-gradient(
            circle at center,
            rgba(255, 255, 255, 0.8),
            rgba(239, 234, 226, 0.92)
        );
}

.welcome-content {
    max-width: 520px;
}

.welcome-icon {
    font-size: 75px;
}

.welcome-content h1 {
    margin: 18px 0 10px;
    font-weight: 400;
}

.welcome-content p {
    color: var(--muted);
    line-height: 1.6;
}

.security-note {
    margin-top: 35px;
    color: var(--muted);
    font-size: 12px;
}

.empty-list {
    padding: 60px 25px;
    text-align: center;
    color: var(--muted);
}

.empty-list-icon {
    margin-bottom: 12px;
    font-size: 40px;
}

.empty-list p {
    margin: 8px 0 0;
    line-height: 1.5;
}

/* TELEFONO */

@media (max-width: 760px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        width: 100%;
        height: 100vh;
        border-right: 0;
    }

    .welcome-panel {
        display: none;
    }

    .auth-page {
        padding: 15px;
    }

    .auth-card {
        padding: 25px 20px;
    }
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 3px;
}

/* RUBRICA */

.contacts-page {
    min-height: 100vh;
    background: #f3f5f6;
}

.contacts-shell {
    min-height: 100vh;
}

.contacts-header {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 24px;
    background: var(--primary);
    color: #ffffff;
}

.contacts-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.contacts-brand .brand-icon {
    background: #ffffff;
    color: var(--primary);
}

.contacts-brand strong,
.contacts-brand small {
    display: block;
}

.contacts-brand small {
    margin-top: 2px;
    color: rgba(255, 255, 255, 0.75);
}

.top-navigation {
    display: flex;
    align-items: center;
    gap: 5px;
}

.top-navigation a {
    padding: 10px 14px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.82);
    font-weight: 600;
    font-size: 14px;
}

.top-navigation a:hover,
.top-navigation a.active {
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}

.contacts-main {
    display: grid;
    grid-template-columns: minmax(340px, 42%) 1fr;
    min-height: calc(100vh - 68px);
}

.contacts-list-panel {
    padding: 22px;
    border-right: 1px solid var(--border);
    background: #ffffff;
}

.contacts-list-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 18px;
}

.contacts-list-title h1,
.contact-form-heading h2 {
    margin: 0;
}

.contacts-list-title p,
.contact-form-heading p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.contacts-search {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
}

.contacts-search input {
    min-width: 0;
    flex: 1;
    height: 43px;
    padding: 0 13px;
    border: 1px solid #d0d5d8;
    border-radius: 8px;
    outline: none;
}

.contacts-search input:focus {
    border-color: var(--primary);
}

.contacts-search button {
    padding: 0 17px;
    border: 0;
    border-radius: 8px;
    background: #e9edef;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
}

.contacts-list {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.contact-row {
    min-height: 78px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid #eef0f2;
    background: #ffffff;
}

.contact-row:last-child {
    border-bottom: 0;
}

.contact-row:hover,
.contact-row.selected {
    background: #f1f7f6;
}

.contact-row-content {
    min-width: 0;
    flex: 1;
}

.contact-row-top,
.contact-row-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.contact-row-top strong,
.contact-row-bottom span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.contact-row-bottom {
    margin-top: 7px;
    color: var(--muted);
    font-size: 12px;
}

.contact-status {
    flex: 0 0 auto;
    padding: 4px 7px;
    border-radius: 999px;
    background: #e5f6ef;
    color: #087558;
    font-size: 10px;
    font-weight: 700;
}

.contact-form-panel {
    padding: 30px;
    background: #f7f8f9;
}

.contact-form-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    max-width: 800px;
    margin: 0 auto 22px;
}

.contact-form {
    max-width: 800px;
    margin: 0 auto;
    padding: 25px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 4px 18px rgba(17, 27, 33, 0.05);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.form-field {
    min-width: 0;
}

.form-field.full-width {
    grid-column: 1 / -1;
}

.form-field label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cfd5d8;
    border-radius: 8px;
    background: #ffffff;
    outline: none;
    font: inherit;
}

.form-field input,
.form-field select {
    height: 45px;
}

.form-field textarea {
    resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(7, 94, 84, 0.1);
}

.contact-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.button.secondary {
    background: #e9edef;
    color: var(--text);
}

.button.danger {
    margin-right: auto;
    background: #fff1f0;
    color: #b42318;
}

@media (max-width: 900px) {
    .contacts-main {
        grid-template-columns: 1fr;
    }

    .contacts-list-panel {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 600px) {
    .contacts-header {
        padding: 10px 13px;
    }

    .top-navigation a {
        padding: 8px 9px;
        font-size: 12px;
    }

    .contacts-list-panel,
    .contact-form-panel {
        padding: 14px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-field.full-width {
        grid-column: auto;
    }

    .contact-form {
        padding: 18px;
    }

    .contacts-list-title {
        align-items: flex-start;
    }
}

/* CHAT */
.chat-shell{display:grid;grid-template-columns:390px minmax(0,1fr);width:100%;height:100vh;background:#fff}
.chat-sidebar{height:100vh}
.conversation-item.active{background:#e9edef}
.chat-panel{min-width:0;height:100vh;display:flex;flex-direction:column;background:var(--background)}
.chat-header{min-height:64px;flex:0 0 64px;display:flex;align-items:center;gap:11px;padding:0 17px;border-bottom:1px solid var(--border);background:var(--header)}
.chat-avatar{width:42px;height:42px;flex:0 0 42px;font-size:15px}
.chat-contact-title{min-width:0;flex:1}
.chat-contact-title strong,.chat-contact-title span{display:block;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.chat-contact-title strong{font-size:15px}
.chat-contact-title span{margin-top:3px;color:var(--muted);font-size:12px}
.contact-info-button{padding:9px 12px;border-radius:8px;background:#fff;color:var(--primary);font-size:12px;font-weight:700}
.mobile-back{display:none;font-size:25px}
.messages-container{flex:1;overflow-y:auto;padding:25px 7%;background-color:#efeae2;background-image:radial-gradient(rgba(17,27,33,.035) 1px,transparent 1px);background-size:18px 18px}
.chat-start-message{width:fit-content;max-width:90%;margin:10px auto 25px;padding:9px 14px;border-radius:8px;background:#fff5c4;color:#54656f;text-align:center;font-size:12px;box-shadow:0 1px 1px rgba(17,27,33,.08)}
.chat-start-message strong,.chat-start-message span{display:block}
.chat-start-message span{margin-top:4px}
.message-row{display:flex;margin-bottom:4px}
.message-row.incoming{justify-content:flex-start}
.message-row.outgoing{justify-content:flex-end}
.message-bubble{position:relative;max-width:min(680px,78%);padding:7px 9px 5px;border-radius:8px;box-shadow:0 1px 1px rgba(17,27,33,.12)}
.message-row.incoming .message-bubble{background:#fff;border-top-left-radius:2px}
.message-row.outgoing .message-bubble{background:#d9fdd3;border-top-right-radius:2px}
.message-text{padding-right:8px;overflow-wrap:anywhere;white-space:normal;font-size:14px;line-height:1.42}
.message-text a{color:#027eb5;text-decoration:underline}
.message-meta{min-width:52px;display:flex;align-items:center;justify-content:flex-end;gap:4px;margin-top:2px;color:#667781;font-size:10px}
.message-status{letter-spacing:-2px;font-size:12px}
.message-composer{min-height:62px;display:flex;align-items:flex-end;gap:5px;padding:9px 11px;background:var(--header)}
.composer-icon{width:40px;height:43px;flex:0 0 40px;border:0;border-radius:50%;background:transparent;color:var(--muted);cursor:pointer;font-size:21px}
.composer-icon:hover{background:rgba(0,0,0,.06)}
.message-form{min-width:0;flex:1;display:flex;align-items:flex-end;gap:7px}
.message-form textarea{width:100%;min-height:43px;max-height:120px;padding:11px 14px;border:0;border-radius:9px;background:#fff;outline:none;resize:none;overflow-y:auto;font:inherit;line-height:21px}
.send-button{width:43px;height:43px;flex:0 0 43px;display:flex;align-items:center;justify-content:center;border:0;border-radius:50%;background:var(--primary);color:#fff;cursor:pointer;font-size:19px}
.send-button:hover{background:var(--primary-dark)}
@media (max-width:760px){
  .chat-shell{display:block}
  .chat-sidebar{display:none}
  .chat-panel{width:100%}
  .mobile-back{display:block}
  .chat-header{padding:0 9px}
  .contact-info-button{padding:8px;font-size:11px}
  .messages-container{padding:18px 10px}
  .message-bubble{max-width:86%}
  .message-composer{gap:2px;padding:7px 5px}
  .composer-icon{width:35px;flex-basis:35px}
  .message-form textarea{padding-left:11px;padding-right:11px}
}
.message-status.read {
    color: #53bdeb;
}
.message-form {
    position: relative;
}

.attachment-preview {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    border: 1px solid #d8dedc;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.12);
    font-size: 13px;
    z-index: 20;
}

.attachment-preview[hidden] {
    display: none;
}

#attachment-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#attachment-remove {
    flex: 0 0 auto;
    width: 25px;
    height: 25px;
    border: 0;
    border-radius: 50%;
    background: #e9eeee;
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
}

#attachment-remove:hover {
    background: #dce5e2;
}
.install-app-button {
    border: 0;
    cursor: pointer;
}

.install-app-button[hidden] {
    display: none !important;
}

.install-app-button:disabled {
    opacity: 0.55;
    cursor: wait;
}
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.delete-chat-form {
    margin: 0;
}

.delete-chat-button {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
}

.delete-chat-button:hover {
    background: rgba(220, 53, 69, 0.12);
}

/* Correzione definitiva chat su smartphone */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

@media (max-width: 768px) {
    html,
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        overflow: hidden;
    }

    body.app-page {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
        overscroll-behavior: none;
    }

    .chat-shell {
        position: absolute;
        inset: 0;
        display: block;
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
    }

    .chat-sidebar {
        display: none;
    }

    .chat-panel {
        position: absolute;
        inset: 0;
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
    }

    .chat-header {
        min-height: 58px;
        height: 58px;
        flex: 0 0 58px;
        padding: 0 8px;
        gap: 8px;
        overflow: hidden;
    }

    .mobile-back {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 40px;
        flex: 0 0 34px;
        font-size: 23px;
    }

    .chat-avatar {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
    }

    .chat-contact-title {
        min-width: 0;
        flex: 1 1 auto;
    }

    .chat-contact-title strong {
        font-size: 15px;
    }

    .chat-contact-title span {
        font-size: 12px;
    }

    .chat-header-actions {
        flex: 0 0 auto;
        gap: 2px;
    }

    .contact-info-button {
        max-width: 126px;
        padding: 8px 10px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 11px;
    }

    .delete-chat-button {
        width: 36px;
        height: 36px;
        padding: 0;
        font-size: 17px;
    }

    .messages-container {
        flex: 1 1 0;
        min-height: 0;
        width: 100%;
        overflow-x: hidden;
        overflow-y: auto;
        padding: 14px 8px 12px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    .message-bubble {
        max-width: 88%;
    }

    .message-composer {
        position: relative;
        flex: 0 0 auto;
        width: 100%;
        min-height: 58px;
        margin: 0;
        padding:
            6px
            4px
            max(6px, env(safe-area-inset-bottom));
        display: flex;
        align-items: flex-end;
        gap: 2px;
        background: var(--header);
        border-top: 1px solid var(--border);
        z-index: 50;
    }

    .composer-icon {
        width: 34px;
        height: 42px;
        flex: 0 0 34px;
        padding: 0;
        font-size: 20px;
    }

    .message-form {
        position: relative;
        min-width: 0;
        flex: 1 1 auto;
        display: flex;
        align-items: flex-end;
        gap: 4px;
    }

    .message-form textarea,
    #message-input {
        display: block;
        width: 100%;
        min-width: 0;
        min-height: 42px;
        max-height: 100px;
        padding: 10px 10px;
        font-size: 16px;
        line-height: 22px;
    }

    .send-button {
        width: 42px;
        height: 42px;
        flex: 0 0 42px;
        padding: 0;
    }

    .emoji-picker {
        left: 6px !important;
        right: 6px !important;
        bottom: calc(100% + 6px) !important;
        width: auto !important;
        max-width: none !important;
        max-height: min(360px, 55vh) !important;
    }

    .attachment-preview {
        left: 0;
        right: 0;
        bottom: calc(100% + 6px);
    }
}

/* Supporto per browser mobili meno recenti */
@supports not (height: 100dvh) {
    @media (max-width: 768px) {
        body.app-page,
        .chat-shell,
        .chat-panel {
            height: 100%;
        }
    }
}
/* Altezza reale e larghezza corretta su Chrome Android */
@media (max-width: 768px) {

    html,
    body,
    body.app-page {
        width: 100vw !important;
        max-width: 100vw !important;
        height: var(--inbox-app-height, 100dvh) !important;
        min-height: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
    }

    .chat-shell,
    .chat-panel {
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: var(--inbox-app-height, 100dvh) !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    .chat-panel {
        display: flex !important;
        flex-direction: column !important;
    }

    .chat-header {
        width: 100% !important;
        max-width: 100vw !important;
        flex: 0 0 58px !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    .chat-contact-title {
        min-width: 0 !important;
        flex: 1 1 0 !important;
    }

    .chat-header-actions {
        min-width: 0 !important;
        flex: 0 0 auto !important;
    }

    .messages-container {
        width: 100% !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        min-height: 0 !important;
        flex: 1 1 0 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    .message-row {
        width: 100% !important;
        max-width: 100% !important;
    }

    .message-bubble {
        max-width: 86% !important;
    }

    .message-image,
    .message-video {
        display: block !important;
        max-width: 100% !important;
        height: auto !important;
    }

    .message-composer {
        position: relative !important;
        width: 100% !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        flex: 0 0 auto !important;
        margin: 0 !important;
        overflow: visible !important;
    }

    .message-form {
        min-width: 0 !important;
        max-width: 100% !important;
        flex: 1 1 0 !important;
    }

    #message-input {
        min-width: 0 !important;
        width: 100% !important;
        font-size: 16px !important;
    }

  .emoji-picker {
    max-width: calc(100vw - 12px) !important;

}
} /* CHIUDE @media (max-width: 768px) */

#contact-form {
    scroll-margin-top: 15px;
}
#contact-form {
    scroll-margin-top: 15px;
}

@media (max-width: 900px) {
    .contacts-page {
        overflow-y: auto;
    }

    .contacts-shell {
        min-height: 100%;
    }

    .contact-form-panel {
        scroll-margin-top: 12px;
    }
}
/* Correzione scorrimento Rubrica su smartphone */
@media (max-width: 768px) {
    html:has(body.contacts-page),
    body.contacts-page {
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 100% !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior: auto !important;
    }

    body.contacts-page .contacts-shell {
        position: static !important;
        width: 100% !important;
        height: auto !important;
        min-height: 100vh !important;
        overflow: visible !important;
    }

    body.contacts-page .contacts-main {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    body.contacts-page .contacts-list-panel,
    body.contacts-page .contact-form-panel {
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    body.contacts-page .contact-form {
        margin-bottom: 40px;
    }

    body.contacts-page .contact-form-actions {
        flex-wrap: wrap;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

.contacts-list-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

@media (max-width: 600px) {
    .contacts-list-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .contacts-list-actions .button {
        width: 100%;
        min-height: 42px;
    }

    .contacts-list-title {
        flex-direction: column;
        align-items: stretch;
    }
}
/* Conversazioni con nuovi messaggi */
.conversation-item.has-unread {
    background: #e7f8ef;
    border-left: 5px solid var(--accent);
}

.conversation-item.has-unread:hover {
    background: #dcf4e7;
}

.conversation-item.has-unread .conversation-top strong {
    font-weight: 800;
    color: #075e54;
}

.conversation-item.has-unread .conversation-bottom span {
    color: #344b45;
    font-weight: 600;
}

.conversation-item.has-unread time {
    color: #087558;
    font-weight: 800;
}

.conversation-item.has-unread .unread-badge {
    min-width: 24px;
    height: 24px;
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.18);
    font-size: 12px;
    font-weight: 800;
}

/* INVIO TEMPLATE MULTIPLO DALLA RUBRICA */
.bulk-template-bar {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8faf9;
}

.bulk-selection-tools,
.bulk-send-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.bulk-selection-tools strong {
    margin-left: auto;
    color: var(--muted);
    font-size: 13px;
}

.button.compact {
    min-height: 38px;
    padding: 0 13px;
    font-size: 13px;
}

.bulk-send-tools select {
    min-width: 0;
    flex: 1;
    height: 40px;
    padding: 0 10px;
    border: 1px solid #cfd5d8;
    border-radius: 8px;
    background: #fff;
}

.bulk-send-tools button:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.bulk-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 12px;
}

.bulk-progress-track {
    height: 7px;
    flex: 1;
    overflow: hidden;
    border-radius: 999px;
    background: #dfe6e3;
}

.bulk-progress-track span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width .2s ease;
}

.contact-selectable {
    padding-left: 9px;
}

.contact-selectable.bulk-selected {
    background: #e7f8ef;
}

.contact-check-wrap {
    flex: 0 0 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.contact-check-wrap input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.contact-check-wrap span {
    width: 19px;
    height: 19px;
    border: 2px solid #aeb9b5;
    border-radius: 5px;
    background: #fff;
}

.contact-check-wrap input:checked + span {
    border-color: var(--primary);
    background: var(--primary);
    box-shadow: inset 0 0 0 3px #fff;
}

.contact-row-main {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.template-dot {
    width: 13px;
    height: 13px;
    flex: 0 0 13px;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, .05);
}

.template-dot.never { background: #aeb7bc; }
.template-dot.sent { background: #25d366; }
.template-dot.failed { background: #d92d20; }

@media (max-width: 600px) {
    .bulk-selection-tools strong {
        width: 100%;
        margin-left: 0;
    }

    .bulk-send-tools {
        align-items: stretch;
        flex-direction: column;
    }

    .bulk-send-tools select,
    .bulk-send-tools .button {
        width: 100%;
    }
}

/* ELENCO CONVERSAZIONI: SCROLL DESKTOP E APP PC */
@media screen and (min-width: 769px) {
    html,
    body,
    body.app-page {
        width: 100%;
        height: 100vh;
        min-height: 0;
        overflow: hidden;
    }

    .app-shell {
        width: 100%;
        height: 100vh;
        min-height: 0;
        overflow: hidden;
    }

    .sidebar {
        height: 100vh;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .sidebar-header,
    .search-area {
        flex: 0 0 auto;
    }

    .conversation-list {
        flex: 1 1 0;
        min-height: 0;
        height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior-y: contain;
        scrollbar-gutter: stable;
    }

    .conversation-list::-webkit-scrollbar {
        width: 10px;
    }

    .conversation-list::-webkit-scrollbar-thumb {
        background: #aeb7bb;
        border: 2px solid transparent;
        border-radius: 10px;
        background-clip: padding-box;
    }

    .conversation-list::-webkit-scrollbar-track {
        background: transparent;
    }
}
/* FIX DEFINITIVO SCROLL RUBRICA */
html:has(body.contacts-page) {
    height: auto !important;
    min-height: 100% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

body.contacts-page {
    position: static !important;
    height: auto !important;
    min-height: 100vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

body.contacts-page .contacts-shell,
body.contacts-page .contacts-main,
body.contacts-page .contacts-list-panel,
body.contacts-page .contact-form-panel {
    height: auto !important;
    overflow: visible !important;
}