.app-toolbar {
    position: fixed;
    z-index: 75;
    top: max(12px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.app-toolbar .theme-preference,
.app-toolbar .system-notification-center {
    position: static;
}

.app-toolbar .notification-panel {
    position: absolute;
    inset: calc(100% + 8px) 0 auto auto;
    width: min(390px, calc(100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right))));
    max-height: 75vh;
    max-height: 75dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.app-toolbar .notification-list { max-height: none; overflow: visible; }
.app-toolbar .notification-bell { flex: 0 0 auto; }

body.messages-mode .main-container {
    display: flex;
    flex-direction: column;
}

body.messages-mode .app-toolbar {
    position: relative;
    inset: auto;
    padding: 4px 10px 8px;
}

body.messages-mode .app-toolbar .notification-panel { top: 100%; right: 10px; }
body.messages-mode .messages-card { flex: 1 1 auto; min-height: 0; height: auto; }

.client-search-tools {
    display: grid;
    gap: 8px;
    margin-bottom: 12px;
}

.client-search-tools > label { font-size: .9rem; font-weight: 650; }
.client-search-tools > input { width: 100%; margin: 0; }

.client-form-section,
.client-extra-filters,
.client-overview {
    border: 1px solid var(--glass-border, #3a3a3a);
    border-radius: 11px;
}

.client-form-section { margin-top: 8px; }
.client-form-section > summary,
.client-extra-filters > summary,
.client-overview > summary,
.client-card-details > summary {
    padding: 12px;
    font-size: .88rem;
    font-weight: 650;
    line-height: 1.25;
    cursor: pointer;
}

.client-form-section .manual-client-grid,
.client-extra-filters .client-filters { padding: 0 12px 12px; }
.client-extra-filters #btn-clear-client-filters { align-self: end; }
.client-overview { margin-bottom: 12px; }
.client-overview .client-summary { padding: 0 12px 12px; margin: 0; }
.client-card-primary-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.client-card-primary-actions .client-edit-btn { width: auto; margin: 0; }
.client-card-details > summary { padding-inline: 0; }
.client-card-details:not([open]) { color: var(--text-muted); }
.client-card-details textarea { width: 100%; }
.client-card-details .client-observation-label { display: block; }
.client-form-section:not(:has(.input-group:not(.hidden))) { display: none; }

@media (max-width: 760px) {
    body:not(.messages-mode) {
        align-items: flex-start;
        padding-block: env(safe-area-inset-top) calc(64px + env(safe-area-inset-bottom));
    }

    body:not(.messages-mode) .main-container {
        padding: 8px max(10px, env(safe-area-inset-right)) 16px max(10px, env(safe-area-inset-left));
    }

    .app-masthead {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        min-width: 0;
        margin-bottom: 10px;
    }

    .app-brand {
        display: flex;
        order: -1;
        align-items: center;
        gap: 7px;
        min-width: 0;
        margin: 0;
        text-align: left;
    }

    .app-brand .logo-container { display: block; flex: 0 0 auto; margin: 0; }
    .app-brand .logo-img { display: block; width: 42px; height: 42px; margin: 0; object-fit: contain; }
    .app-brand .badge { display: none; }
    .app-brand #status-text { margin: 0; font-size: .69rem; line-height: 1.2; overflow-wrap: anywhere; }
    .app-toolbar { position: relative; inset: auto; flex: 0 0 auto; gap: 8px; }
    .app-toolbar .theme-preference { padding: 3px; gap: 2px; }
    .app-toolbar .theme-option { min-width: 0; min-height: 40px; padding: 5px 7px; font-size: .72rem; }
    .app-toolbar .notification-bell { width: 44px; height: 44px; }
    .app-toolbar .notification-panel { max-height: min(75dvh, 640px); }

    body.messages-mode .main-container { height: 100dvh; padding-top: env(safe-area-inset-top); }
    body.messages-mode .app-masthead {
        position: absolute;
        z-index: 75;
        top: calc(11px + env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
        margin: 0;
    }
    body.messages-mode .app-toolbar { padding: 0; }
    body.messages-mode .app-toolbar .notification-panel { top: calc(100% + 8px); right: 0; }
    body.messages-mode:has(.system-notification-center:not(.hidden)) .messages-topbar { padding-right: max(62px, calc(54px + env(safe-area-inset-right))); }
    body.messages-mode .messages-topbar { gap: 8px; }
    body.messages-mode .messages-account-picker,
    body.messages-mode #messages-client-select { min-width: min(108px, 32vw); max-width: 38vw; }
    body.messages-mode.messages-conversation-open .app-masthead { display: none; }
    body.messages-mode .message-composer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }

    .header-row { gap: 8px; margin-bottom: 8px; }
    .header-row h2 { font-size: clamp(1.12rem, 5vw, 1.4rem); overflow-wrap: anywhere; }
    .btn-back, .header-row .btn-icon-small { min-width: 44px; min-height: 44px; flex: 0 0 auto; }
    .input-group input:not([type="checkbox"]):not([type="radio"]),
    .input-group select,
    .input-group textarea,
    .client-search-tools > input,
    body.messages-mode .message-composer textarea { font-size: 16px; }
    .input-group input:not([type="checkbox"]):not([type="radio"]),
    .input-group select,
    .client-search-tools > input { min-height: 44px; }

    .agenda-summary,
    .client-overview .client-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        margin-bottom: 12px;
    }

    .agenda-summary .summary-card,
    .client-overview .summary-card { min-width: 0; min-height: 0; padding: 8px; }
    .agenda-summary .summary-value,
    .client-overview .summary-value { font-size: 1.2rem; }
    .agenda-summary .summary-label,
    .client-overview .summary-label { font-size: .65rem; line-height: 1.15; overflow-wrap: anywhere; }

    #numbers-step .dashboard-panel { padding: 0; border: 0; background: none; box-shadow: none; }
    #numbers-step .section-heading { margin-bottom: 10px; }
    #numbers-step .section-heading-row { width: 100%; align-items: stretch; gap: 8px; }
    #numbers-step .client-registry-header-actions { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
    #numbers-step .client-registry-header-actions button { min-height: 44px; min-width: 0; margin: 0; }
    #numbers-step .client-registry-list { max-height: none; overflow: visible; padding-right: 0; }
    #numbers-step .client-card { padding: 12px; }
    #numbers-step .client-card-header { gap: 7px; }
    #numbers-step .client-card-title { min-width: 0; overflow-wrap: anywhere; }
    #numbers-step .client-badges .client-badge:not(:first-child) { display: none; }
    #numbers-step .client-card-actions { gap: 8px; }
    #numbers-step .client-card-actions button,
    #numbers-step .client-card-primary-actions button { min-height: 44px; }

    .manual-client-modal { padding: 0; align-items: stretch; }
    .manual-client-modal .manual-client-modal-card { height: 100%; max-height: 100%; border: 0; border-radius: 0; overflow: hidden; }
    .manual-client-modal .manual-client-form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; padding: 0; }
    .manual-client-form-header {
        padding: calc(12px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
        margin: 0;
        border-bottom: 1px solid var(--glass-border, #334155);
    }
    .manual-client-form-header .btn-icon-small { width: 44px; height: 44px; font-size: 1.25rem; flex: 0 0 auto; }
    .manual-client-form-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 12px max(14px, env(safe-area-inset-right)) 16px max(14px, env(safe-area-inset-left)); }
    .manual-client-form-body .manual-client-grid { gap: 10px; }
    .manual-client-modal .manual-client-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 6px;
        margin: 0;
        padding: 10px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
        border-top: 1px solid var(--glass-border, #334155);
    }
    .manual-client-modal .manual-client-actions button { margin: 0; min-height: 46px; }
    .manual-client-modal .manual-client-actions #btn-cancel-client-edit { min-height: 44px; }

    .support-floating-button {
        right: max(10px, env(safe-area-inset-right));
        bottom: max(10px, env(safe-area-inset-bottom));
        width: 46px;
        min-height: 46px;
        justify-content: center;
        padding: 0;
    }
    .support-floating-button span:last-child { display: none; }
    body.messages-mode.messages-conversation-open .support-floating-button,
    body:has(.psychology-evolution-modal:not(.hidden), .client-picker:not(.hidden), dialog[open], .support-modal:not(.hidden)) .support-floating-button { display: none; }
    html:has(.manual-client-modal:not(.hidden)), body:has(.manual-client-modal:not(.hidden)) { overflow: hidden; }
}
