/* =====================================================
   SUSTENTIA CRM — VISUAL REFRESH 3.1
   Unified shell, responsive behavior and UI polish.
   This file intentionally loads after legacy styles.
   ===================================================== */

:root {
    --crm-sidebar-width: 248px;
    --crm-sidebar-compact: 82px;
    --crm-mobile-topbar: 68px;
    --crm-mobile-dock: 72px;
    --crm-content-max: 1540px;
    --crm-surface: #ffffff;
    --crm-surface-soft: #f7f5f1;
    --crm-surface-muted: #f0ede7;
    --crm-border: rgba(47, 79, 79, 0.10);
    --crm-border-strong: rgba(47, 79, 79, 0.18);
    --crm-shadow-sm: 0 4px 16px rgba(30, 53, 53, 0.06);
    --crm-shadow-md: 0 12px 36px rgba(30, 53, 53, 0.10);
    --crm-shadow-lg: 0 24px 60px rgba(30, 53, 53, 0.16);
    --crm-ease: 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    color-scheme: light;
    background: var(--bg-light);
}

body {
    background:
        radial-gradient(circle at 92% 2%, rgba(140, 120, 83, 0.08), transparent 26rem),
        linear-gradient(180deg, #fbfaf8 0%, var(--bg-light) 32%, #f3f1ed 100%);
}

button,
a,
input,
select,
textarea {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid rgba(121, 154, 58, 0.42);
    outline-offset: 3px;
}

/* ── Application shell ─────────────────────────────── */
#app {
    min-height: 100dvh;
    background: transparent;
    overflow: visible;
}

#app > aside {
    width: var(--crm-sidebar-width);
    padding: 20px 14px 14px;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% -8%, rgba(168, 145, 104, 0.24), transparent 15rem),
        linear-gradient(180deg, #2f5150 0%, #263f3e 50%, #1e3433 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 12px 0 34px rgba(30, 53, 53, 0.13);
    transition: width var(--crm-ease), transform var(--crm-ease);
}

#app > aside .logo {
    width: auto;
    height: 78px;
    margin: 0 8px 14px;
    padding: 8px 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
    transition: margin var(--crm-ease), padding var(--crm-ease);
}

#app > aside .logo img {
    max-width: 152px;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.12));
    transition: max-width var(--crm-ease);
}

#crm-primary-nav {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

#crm-primary-nav::-webkit-scrollbar {
    width: 5px;
}

#crm-primary-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.20);
    border-radius: 8px;
}

#crm-primary-nav ul {
    padding: 4px 0 12px;
}

#crm-primary-nav ul li {
    margin: 3px 0;
}

#crm-primary-nav ul li a {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.80rem;
    letter-spacing: 0.015em;
    line-height: 1.25;
    text-transform: none;
    white-space: nowrap;
    transform: none;
}

#crm-primary-nav ul li a i {
    width: 26px;
    font-size: 0.92rem;
    color: rgba(255, 255, 255, 0.58);
    transition: color var(--crm-ease), transform var(--crm-ease);
}

#crm-primary-nav ul li a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.075);
    border-color: rgba(255, 255, 255, 0.08);
    transform: none;
}

#crm-primary-nav ul li a:hover i {
    color: #d8c7a5;
    transform: scale(1.08);
}

#crm-primary-nav ul li a.active {
    color: #fff;
    background: linear-gradient(135deg, rgba(168, 145, 104, 0.96), rgba(140, 120, 83, 0.92));
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow: 0 10px 24px rgba(12, 28, 27, 0.24);
    transform: none;
}

#crm-primary-nav ul li a.active i {
    color: #fff;
}

#sidebar-collapse-toggle {
    width: 100%;
    min-height: 42px;
    margin-top: 8px;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    color: rgba(255, 255, 255, 0.62);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    font-size: 0.72rem;
    text-transform: none;
    letter-spacing: 0.02em;
}

#sidebar-collapse-toggle:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.10);
}

.mobile-nav-account {
    display: none;
}

#app > main {
    margin-left: var(--crm-sidebar-width);
    max-width: none;
    min-width: 0;
    padding: 22px 30px 42px;
    overflow-x: clip;
    transition: margin-left var(--crm-ease);
}

#app > main > header {
    position: sticky;
    top: 14px;
    z-index: 85;
    min-height: 62px;
    margin: 0 auto 24px;
    padding: 11px 14px 11px 20px;
    border: 1px solid rgba(47, 79, 79, 0.09);
    border-radius: 17px;
    background: rgba(255, 255, 255, 0.90);
    box-shadow: var(--crm-shadow-sm);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
}

#view-title h1 {
    margin: 0;
    color: var(--primary);
    font-size: 0.92rem;
    font-weight: 800;
    letter-spacing: 0.10em;
}

.user-profile {
    gap: 10px;
}

.user-profile > span:not(.user-avatar) {
    max-width: 240px;
    overflow: hidden;
    color: #626963;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-avatar {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(140, 120, 83, 0.20);
    border-radius: 12px;
    color: var(--bronze);
    background: linear-gradient(145deg, #f6f2eb, #ece4d7);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

#app .app-logout-btn {
    width: auto;
    min-height: 38px;
    margin: 0;
    padding: 8px 13px;
    border-radius: 10px;
    font-size: 0.73rem;
    letter-spacing: 0.025em;
    text-transform: none;
    box-shadow: none;
}

#view-content {
    width: 100%;
    max-width: var(--crm-content-max);
    margin: 0 auto;
}

/* ── Collapsed desktop shell ───────────────────────── */
#app.sidebar-collapsed > aside {
    width: var(--crm-sidebar-compact);
}

#app.sidebar-collapsed > main {
    margin-left: var(--crm-sidebar-compact);
}

#app.sidebar-collapsed > aside .logo {
    margin-inline: 0;
    padding-inline: 4px;
}

#app.sidebar-collapsed > aside .logo img {
    max-width: 54px;
}

#app.sidebar-collapsed #crm-primary-nav a {
    justify-content: center;
    gap: 0;
    padding-inline: 8px;
    font-size: 0;
}

#app.sidebar-collapsed #crm-primary-nav a i {
    width: auto;
    font-size: 1rem;
}

#app.sidebar-collapsed #sidebar-collapse-toggle {
    gap: 0;
}

#app.sidebar-collapsed #sidebar-collapse-toggle i {
    transform: rotate(180deg);
}

#app.sidebar-collapsed #sidebar-collapse-toggle span {
    display: none;
}

/* ── Content surfaces and controls ─────────────────── */
#app .card {
    padding: 24px;
    overflow: visible;
    border: 1px solid var(--crm-border);
    border-left: 1px solid var(--crm-border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--crm-shadow-sm);
}

#app .card:hover {
    box-shadow: var(--crm-shadow-md);
}

#app button {
    min-height: 40px;
    border-radius: 10px;
    letter-spacing: 0.02em;
    text-transform: none;
}

#app button.small,
#app .btn-primary.small,
#app .btn-secondary.small,
#app .btn-accent.small {
    min-height: 34px;
}

#app .btn-primary,
#app .btn-secondary,
#app .btn-accent {
    width: auto;
    margin-bottom: 0;
    padding: 10px 16px;
}

#app .form-group label,
#app label {
    letter-spacing: 0.045em;
}

#app .form-group input,
#app .form-group select,
#app .form-group textarea,
#app .form-input {
    min-height: 44px;
    border-color: rgba(47, 79, 79, 0.17);
    border-radius: 10px;
    background: #fff;
}

#app .form-group textarea {
    min-height: 96px;
}

#app .data-table,
#app table {
    border-collapse: separate;
    border-spacing: 0;
}

#app .data-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    color: #51605b;
    background: #f1eee8;
    border-bottom-color: rgba(47, 79, 79, 0.14);
}

#app .data-table td {
    background: rgba(255, 255, 255, 0.82);
}

#app .data-table tbody tr:hover td {
    background: #faf8f4;
}

#app .table-container,
#app .data-table-wrapper,
#app [style*="overflow-x:auto"],
#app [style*="overflow-x: auto"] {
    scrollbar-width: thin;
    scrollbar-color: rgba(47, 79, 79, 0.26) transparent;
}

/* ── Modals ────────────────────────────────────────── */
.modal-overlay {
    padding: 24px;
}

.modal-content {
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 20px;
    box-shadow: var(--crm-shadow-lg);
}

.modal-header {
    min-height: 66px;
    padding: 16px 22px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.modal-header h3 {
    font-size: 0.96rem;
    line-height: 1.35;
}

.close-btn {
    width: 42px;
    height: 42px;
    min-height: 42px;
}

/* ── Dashboard polish ──────────────────────────────── */
#app .dash-hero {
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 24px;
    box-shadow: 0 18px 42px rgba(30, 53, 53, 0.18);
}

#app .dash-kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

#app .kpi-card,
#app .dash-card {
    border-color: var(--crm-border);
    box-shadow: var(--crm-shadow-sm);
}

#app .kpi-card {
    min-height: 174px;
}

#app .quick-grid {
    grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
}

#app .quick-item {
    min-height: 88px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-color: rgba(47, 79, 79, 0.08);
}

/* ── Prospect navigation and Kanban ────────────────── */
#app .prospect-view-toggle {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--crm-border);
    border-radius: 12px;
    background: var(--crm-surface-muted);
}

#app .prospect-view-toggle button {
    min-height: 36px;
    border-radius: 9px;
}

#app .kanban-board {
    padding-bottom: 16px;
}

#app .kanban-column {
    border-color: var(--crm-border);
    background: #f5f3ef;
}

#app .kanban-card {
    border-color: rgba(47, 79, 79, 0.08);
    box-shadow: 0 4px 14px rgba(30, 53, 53, 0.07);
}

/* ── Floating assistant ────────────────────────────── */
#ai-assistant-fab {
    transition: transform var(--crm-ease), box-shadow var(--crm-ease), right var(--crm-ease), bottom var(--crm-ease);
}

#ai-assistant-fab:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 14px 30px rgba(30, 53, 53, 0.30) !important;
}

#mobile-menu-toggle,
#mobile-bottom-nav,
#mobile-nav-backdrop {
    display: none;
}

/* =====================================================
   MOBILE + TABLET — ONE CONSISTENT BREAKPOINT
   ===================================================== */
@media (max-width: 900px) {
    :root {
        --crm-content-max: none;
    }

    body.crm-nav-open {
        overflow: hidden;
    }

    #app {
        min-height: 100dvh;
        flex-direction: column !important;
        padding-bottom: calc(var(--crm-mobile-dock) + env(safe-area-inset-bottom, 0px));
    }

    #app > aside,
    #app.sidebar-collapsed > aside {
        z-index: 1101;
        width: 100% !important;
        height: var(--crm-mobile-topbar) !important;
        min-height: var(--crm-mobile-topbar);
        padding: 0 14px !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        overflow: visible;
        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.10);
        box-shadow: 0 8px 28px rgba(30, 53, 53, 0.18);
    }

    #app > aside .logo,
    #app.sidebar-collapsed > aside .logo {
        width: 118px !important;
        height: 50px !important;
        margin: 0 !important;
        padding: 3px 0 !important;
        border: 0;
        justify-content: flex-start !important;
    }

    #app > aside .logo img,
    #app.sidebar-collapsed > aside .logo img {
        width: auto;
        max-width: 112px;
        height: 100%;
    }

    #mobile-menu-toggle {
        flex: 0 0 44px;
        width: 44px;
        min-width: 44px;
        height: 44px;
        min-height: 44px;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(255, 255, 255, 0.12) !important;
        border-radius: 12px !important;
        background: rgba(255, 255, 255, 0.06) !important;
    }

    #crm-primary-nav,
    #app.sidebar-collapsed #crm-primary-nav {
        position: fixed !important;
        top: var(--crm-mobile-topbar) !important;
        bottom: calc(var(--crm-mobile-dock) + env(safe-area-inset-bottom, 0px));
        left: 0 !important;
        z-index: 1105 !important;
        width: min(86vw, 340px) !important;
        height: auto !important;
        max-height: none !important;
        padding: 12px 12px 18px !important;
        display: flex !important;
        flex-direction: column;
        background:
            radial-gradient(circle at 20% 0%, rgba(168, 145, 104, 0.18), transparent 16rem),
            linear-gradient(180deg, #2c4b49, #1e3535) !important;
        box-shadow: 20px 0 48px rgba(12, 28, 27, 0.32);
        transform: translateX(-106%);
        visibility: hidden;
        transition: transform var(--crm-ease), visibility var(--crm-ease);
    }

    #crm-primary-nav.nav-open {
        transform: translateX(0);
        visibility: visible;
    }

    #crm-primary-nav ul {
        flex: 1;
        overflow-y: auto;
    }

    #crm-primary-nav ul li {
        width: 100%;
        border: 0;
    }

    #crm-primary-nav ul li a,
    #app.sidebar-collapsed #crm-primary-nav a {
        width: 100%;
        min-height: 48px;
        padding: 11px 13px !important;
        display: flex !important;
        justify-content: flex-start;
        gap: 10px;
        border-radius: 12px;
        font-size: 0.84rem;
    }

    #app.sidebar-collapsed #crm-primary-nav a i {
        width: 26px;
        font-size: 0.94rem;
    }

    .mobile-nav-account {
        padding: 13px 4px 0;
        display: grid;
        gap: 10px;
        border-top: 1px solid rgba(255, 255, 255, 0.10);
    }

    .mobile-nav-user {
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 10px;
        color: rgba(255, 255, 255, 0.82);
        font-family: var(--font-display);
        font-size: 0.76rem;
        font-weight: 700;
    }

    .mobile-nav-user #mobile-user-display-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-nav-account .user-avatar {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    #app .mobile-logout-btn {
        width: 100%;
        min-height: 44px;
        justify-content: center;
        color: #fff;
        background: rgba(179, 90, 61, 0.18);
        border: 1px solid rgba(230, 150, 123, 0.24);
    }

    #sidebar-collapse-toggle {
        display: none;
    }

    #mobile-nav-backdrop {
        position: fixed;
        top: var(--crm-mobile-topbar);
        right: 0;
        bottom: calc(var(--crm-mobile-dock) + env(safe-area-inset-bottom, 0px));
        left: 0;
        z-index: 1100;
        display: block;
        pointer-events: none;
        opacity: 0;
        background: rgba(17, 34, 33, 0.48);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        transition: opacity var(--crm-ease);
    }

    #mobile-nav-backdrop.is-open {
        pointer-events: auto;
        opacity: 1;
    }

    #app > main,
    #app.sidebar-collapsed > main {
        width: 100% !important;
        max-width: 100% !important;
        margin: var(--crm-mobile-topbar) 0 0 !important;
        padding: 12px 12px 30px !important;
        overflow-x: clip !important;
    }

    #app > main > header {
        position: static !important;
        width: 100% !important;
        height: auto !important;
        min-height: 50px;
        margin: 0 0 12px !important;
        padding: 11px 14px !important;
        display: flex !important;
        background: rgba(255, 255, 255, 0.90) !important;
        border-radius: 14px;
    }

    #app > main > header #view-title {
        display: block !important;
        min-width: 0;
    }

    #view-title h1 {
        overflow: hidden;
        font-size: 0.80rem;
        letter-spacing: 0.075em;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #app > main > header .user-profile {
        display: none !important;
    }

    #mobile-bottom-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1200;
        height: calc(var(--crm-mobile-dock) + env(safe-area-inset-bottom, 0px));
        padding: 6px 8px env(safe-area-inset-bottom, 0px);
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: center;
        border-top: 1px solid rgba(47, 79, 79, 0.11);
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 -12px 34px rgba(30, 53, 53, 0.12);
        backdrop-filter: blur(18px) saturate(1.2);
        -webkit-backdrop-filter: blur(18px) saturate(1.2);
    }

    #mobile-bottom-nav button {
        min-width: 0;
        min-height: 54px;
        padding: 5px 3px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        color: #7a817d;
        background: transparent;
        border: 0;
        border-radius: 12px;
        box-shadow: none;
        font-size: 0.66rem;
        font-weight: 700;
        letter-spacing: 0;
    }

    #mobile-bottom-nav button i {
        font-size: 1.02rem;
    }

    #mobile-bottom-nav button.active {
        color: var(--primary);
        background: rgba(47, 79, 79, 0.08);
    }

    #mobile-bottom-nav button.active i {
        color: var(--bronze);
    }

    /* Mobile content density */
    #app .card {
        padding: 16px !important;
        border-radius: 15px !important;
    }

    #app button,
    #app .btn-primary,
    #app .btn-secondary,
    #app .btn-accent {
        width: auto !important;
        min-height: 44px;
        margin-bottom: 0;
        padding: 10px 13px;
    }

    #app .form-actions {
        position: sticky;
        bottom: 0;
        z-index: 5;
        margin-inline: -12px;
        padding: 12px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 -8px 24px rgba(30, 53, 53, 0.08);
    }

    #app .dash-hero {
        padding: 24px 20px;
        margin-bottom: 18px;
        border-radius: 18px;
    }

    #app .dash-title {
        max-width: 100%;
        font-size: clamp(1.35rem, 6vw, 1.7rem);
    }

    #app .dash-subtitle {
        max-width: 32rem;
        padding-right: 0;
        font-size: 0.84rem;
    }

    #app .dash-date-badge {
        position: static;
        width: fit-content;
        max-width: 100%;
        margin-top: 16px;
        display: inline-flex;
        white-space: normal;
    }

    #app .dash-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-bottom: 18px;
    }

    #app .kpi-card {
        min-height: 154px;
        padding: 18px 16px;
        border-radius: 15px;
    }

    #app .kpi-num {
        font-size: 1.72rem;
    }

    #app .kpi-label {
        font-size: 0.69rem;
        line-height: 1.35;
    }

    #app .dash-lower {
        gap: 14px;
        margin-bottom: 16px;
    }

    #app .dash-card-header,
    #app .dash-card-body {
        padding-inline: 16px;
    }

    #app .quick-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Scrollable tabs remain legible instead of being ellipsized */
    #app .scroll-tabs,
    #app div[style*="border-bottom:2px"],
    #app div[style*="border-bottom: 2px"] {
        max-width: 100%;
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        scrollbar-width: none;
    }

    #app div[style*="border-bottom:2px"] > button,
    #app div[style*="border-bottom: 2px"] > button {
        min-width: max-content !important;
        flex: 0 0 auto !important;
        overflow: visible !important;
        text-overflow: clip !important;
    }

    /* Data-heavy views: one intentional horizontal scroller */
    #app .card:has(> table),
    #app .card > div:has(> table),
    #app .table-container,
    #app .data-table-wrapper,
    #app div[id$="-container"]:has(table) {
        overflow-x: auto !important;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }

    #app .data-table,
    #app .card table {
        width: 100% !important;
        min-width: 700px;
        display: table !important;
        overflow: visible !important;
        white-space: nowrap;
    }

    #app .data-table th,
    #app .data-table td {
        min-height: 44px;
        padding: 11px 10px !important;
        font-size: 0.80rem !important;
    }

    #app .kanban-column {
        min-width: min(82vw, 300px);
        max-width: min(86vw, 320px);
        flex-basis: min(82vw, 300px);
    }

    #app .kanban-card-actions button,
    #app .gcal-icon-btn,
    #app .gcal-icon-btn.sm {
        width: 44px;
        height: 44px;
        min-height: 44px;
    }

    /* Calendar switches to a readable day layout through calendar.js */
    #app .gcal-container {
        height: calc(100dvh - var(--crm-mobile-topbar) - var(--crm-mobile-dock) - 86px);
        min-height: 520px;
        border: 1px solid var(--crm-border);
        border-radius: 14px;
        box-shadow: var(--crm-shadow-sm);
    }

    #app .gcal-header {
        padding: 9px;
        gap: 8px;
    }

    #app .gcal-header-left,
    #app .gcal-header-right {
        width: 100%;
        gap: 6px;
    }

    #app .gcal-title {
        min-width: 0;
        font-size: 1rem;
    }

    #app .gcal-header-right {
        overflow-x: auto;
        justify-content: flex-start;
        scrollbar-width: none;
    }

    #app .gcal-view-switcher {
        flex: 0 0 auto;
    }

    #app .gcal-view-btn {
        min-height: 38px;
        padding-inline: 12px;
        font-size: 0.76rem;
    }

    #app .gcal-time-label,
    #app .gcal-day-name {
        font-size: 0.72rem !important;
    }

    #app .gcal-event-block {
        min-height: 26px;
        padding: 4px 6px;
        font-size: 0.76rem;
    }

    #app .gcal-event-time,
    #app .gcal-month-event,
    #app .gcal-month-more {
        font-size: 0.70rem;
    }

    #app .gcal-mobile-fab {
        right: 16px !important;
        bottom: 16px !important;
        width: 52px;
        height: 52px;
        min-height: 52px;
        box-shadow: 0 12px 26px rgba(47, 79, 79, 0.28);
    }

    body[data-crm-view="calendar"] #ai-assistant-fab {
        display: none !important;
    }

    #ai-assistant-fab {
        right: 16px !important;
        bottom: calc(var(--crm-mobile-dock) + 16px + env(safe-area-inset-bottom, 0px)) !important;
        width: 54px !important;
        height: 54px !important;
        min-height: 54px;
    }

    #ai-assistant-modal {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Mobile modals become stable, single-scroll surfaces */
    .modal-overlay {
        padding: 10px !important;
        align-items: flex-start !important;
    }

    .modal-content {
        width: min(100%, 720px) !important;
        max-width: 100% !important;
        max-height: calc(100dvh - 20px) !important;
        margin: 0 auto !important;
        padding: 0 !important;
        border-radius: 16px !important;
    }

    .modal-header {
        padding: 12px 14px;
    }

    .prospect-grid {
        padding: 14px !important;
    }
}

@media (max-width: 520px) {
    #app > main,
    #app.sidebar-collapsed > main {
        padding-inline: 10px !important;
    }

    #app .dash-hero {
        padding: 22px 17px;
    }

    #app .dash-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #app .kpi-card {
        min-height: 146px;
        padding: 16px 14px;
    }

    #app .kpi-icon {
        width: 42px;
        height: 42px;
        margin-bottom: 12px;
    }

    #mobile-bottom-nav button span {
        font-size: 0.62rem;
    }

    #app .gcal-coaching-link-btn span {
        display: none;
    }

    #app .gcal-coaching-link-btn {
        width: 44px;
        min-width: 44px;
        padding: 0 !important;
        justify-content: center;
        border-radius: 12px !important;
    }

    .modal-overlay {
        padding: 0 !important;
    }

    .modal-content {
        width: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border: 0 !important;
        border-radius: 0 !important;
    }
}

@media (max-width: 370px) {
    #app .dash-kpis {
        grid-template-columns: 1fr;
    }
}

/* =====================================================
   REAL MODULE INTEGRATION — APPROVED VISUAL LANGUAGE
   Presentation-only overrides for existing module markup.
   ===================================================== */
.crm-module-intro {
    position: relative;
    min-height: 154px;
    margin-bottom: 20px;
    padding: 28px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    overflow: hidden;
    color: #fff;
    background:
        radial-gradient(circle at 92% 10%, rgba(255, 255, 255, 0.10), transparent 13rem),
        linear-gradient(135deg, #2f4f4f 0%, #3d6565 64%, #8c7853 100%);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 18px;
    box-shadow: var(--crm-shadow-md);
}

.crm-module-intro::after {
    content: "";
    position: absolute;
    right: -74px;
    bottom: -128px;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.055);
}

.crm-module-intro-copy {
    position: relative;
    z-index: 1;
    max-width: 720px;
}

.crm-module-eyebrow {
    display: block;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.66);
    font-family: var(--font-display);
    font-size: 0.70rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.crm-module-intro h2 {
    margin: 0 0 7px;
    color: #fff;
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 2vw, 1.62rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.18;
    text-transform: none;
}

.crm-module-intro p {
    max-width: 620px;
    margin: 0;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.86rem;
    line-height: 1.55;
}

.crm-module-intro-icon {
    position: relative;
    z-index: 1;
    width: 66px;
    height: 66px;
    flex: 0 0 66px;
    display: grid;
    place-items: center;
    color: #fff;
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 19px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.10);
    font-size: 1.45rem;
}

.crm-module-shell {
    min-width: 0;
}

.crm-module-shell > .card,
.crm-module-shell .card {
    border-color: var(--crm-border);
    border-radius: 16px;
    box-shadow: var(--crm-shadow-sm);
}

.crm-module-shell h2,
.crm-module-shell h3 {
    letter-spacing: -0.01em;
}

.crm-module-shell .form-input,
.crm-module-shell input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.crm-module-shell select,
.crm-module-shell textarea {
    min-height: 44px;
    border-color: var(--crm-border-strong) !important;
    border-radius: 11px !important;
    background-color: #fff;
}

.crm-module-shell textarea {
    min-height: 96px;
}

.crm-module-shell .btn-primary,
.crm-module-shell .btn-secondary,
.crm-module-shell .btn-accent,
.crm-module-shell .btn-outline {
    min-height: 42px;
    border-radius: 11px !important;
}

/* Finance / cartera */
.crm-finance-shell > .card {
    padding: 22px;
    overflow: hidden;
}

.crm-finance-shell > .card > div:first-child {
    margin: -22px -22px 22px !important;
    padding: 20px 22px !important;
    display: flex !important;
    align-items: center !important;
    gap: 16px !important;
    flex-wrap: wrap;
    background: linear-gradient(135deg, #fbfaf8, #f1eee8);
    border-bottom: 1px solid var(--crm-border) !important;
}

.crm-finance-shell > .card > div:first-child > div:first-child {
    min-width: min(100%, 280px);
    flex: 1;
}

.crm-finance-shell > .card > div:first-child > div:last-child {
    display: flex !important;
    flex: 1 1 460px;
    justify-content: flex-end;
    gap: 9px !important;
    flex-wrap: wrap;
}

.crm-finance-shell #project-filter,
.crm-finance-shell #land-status-filter,
.crm-finance-shell #advisor-filter,
.crm-finance-shell #finance-search {
    width: auto !important;
    min-width: 180px;
    flex: 1 1 180px;
}

.crm-finance-shell .grid-split-2 {
    gap: 22px;
}

.crm-finance-shell #clients-list-content,
.crm-finance-shell #clients-collection-list {
    padding-right: 4px;
    scrollbar-color: rgba(47, 79, 79, 0.24) transparent;
}

.crm-finance-shell .data-table {
    overflow: hidden;
    border: 1px solid var(--crm-border);
    border-radius: 13px;
}

.crm-finance-shell .data-table th {
    background: #f3f1ec;
}

.finance-land-status-summary {
    margin: 0 0 22px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.finance-status-card {
    min-height: 82px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    color: #4e5752;
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 14px;
    box-shadow: var(--crm-shadow-sm);
    cursor: pointer;
    transition: transform var(--crm-ease), border-color var(--crm-ease), box-shadow var(--crm-ease);
}

.finance-status-card:hover,
.finance-status-card.is-active {
    transform: translateY(-2px);
    border-color: var(--crm-border-strong);
    box-shadow: var(--crm-shadow-md);
}

.finance-status-card.is-active {
    outline: 3px solid rgba(47, 79, 79, 0.10);
}

.finance-status-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #f1eee8;
    font-size: 1rem;
}

.finance-status-card strong,
.finance-status-card small {
    display: block;
}

.finance-status-card strong {
    color: var(--primary);
    font-size: 1.3rem;
    line-height: 1;
}

.finance-status-card small {
    margin-top: 6px;
    color: #6b736f;
    font-size: 0.76rem;
    font-weight: 700;
}

.finance-status-card.is-pending .finance-status-icon {
    color: #9a6509;
    background: #fff4d9;
}

.finance-status-card.is-paid .finance-status-icon {
    color: #24794b;
    background: #e7f6ed;
}

.finance-status-card.is-deeded .finance-status-icon {
    color: #6a4d8f;
    background: #f1eafa;
}

.land-status-badge {
    max-width: 190px;
    padding: 5px 9px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 1.25;
}

.land-status-badge.is-pending {
    color: #8a5a00;
    background: #fff4d9;
}

.land-status-badge.is-paid {
    color: #1f7044;
    background: #e7f6ed;
}

.land-status-badge.is-deeded {
    color: #604184;
    background: #f1eafa;
}

.deed-number-display {
    max-width: 200px;
    margin-top: 6px;
    color: #565f5a;
    font-size: 0.7rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.deed-number-display span {
    color: #a05b45;
    font-style: italic;
}

.land-status-modal {
    z-index: 10006;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.land-status-modal-content {
    width: min(520px, 100%);
    overflow: hidden;
    border-radius: 16px;
}

.land-status-modal .modal-header {
    align-items: flex-start;
}

.land-status-modal .modal-header h3,
.land-status-modal .modal-header p {
    margin: 0;
}

.land-status-modal .modal-header p {
    margin-top: 5px;
    color: #7b837f;
    font-size: 0.78rem;
    font-weight: 500;
}

.land-status-modal-body {
    padding: 22px;
}

.land-status-modal-body small {
    display: block;
    margin-top: 6px;
    color: #707873;
}

.land-status-modal-actions {
    margin-top: 22px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Training / academy */
.crm-training-shell > div:first-child {
    margin-bottom: 20px !important;
    padding: 5px;
    display: flex !important;
    gap: 5px !important;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    background: #eceae5;
    border: 1px solid var(--crm-border);
    border-bottom: 1px solid var(--crm-border) !important;
    border-radius: 13px;
    scrollbar-width: none;
}

.crm-training-shell > div:first-child::-webkit-scrollbar {
    display: none;
}

.crm-training-shell > div:first-child > button {
    min-height: 43px;
    flex: 0 0 auto;
    padding: 10px 16px !important;
    border-radius: 9px !important;
    white-space: nowrap;
}

.crm-training-shell #tab-content-contenido > div:first-child {
    padding: 16px 18px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--crm-border);
    border-radius: 14px;
}

.crm-training-shell #video-grid,
.crm-training-shell #resource-list {
    align-items: stretch;
}

.crm-training-shell #video-grid > .card,
.crm-training-shell #resource-list > .card {
    border-left-width: 0 !important;
    box-shadow: 0 8px 22px rgba(30, 53, 53, 0.07);
}

/* Reports */
.crm-reports-shell > .card:first-child {
    overflow: hidden;
    border: 1px solid var(--crm-border);
}

.crm-reports-shell .scroll-tabs {
    gap: 5px;
    padding: 6px !important;
    background: #eceae5 !important;
    border-bottom-color: var(--crm-border) !important;
    scrollbar-width: none;
}

.crm-reports-shell .scroll-tabs::-webkit-scrollbar {
    display: none;
}

.crm-reports-shell .scroll-tabs > div {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-bottom-width: 0 !important;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.48);
}

.crm-reports-shell .period-selector {
    padding: 5px !important;
    border: 1px solid var(--crm-border);
    background: #eceae5 !important;
}

.crm-reports-shell .period-selector button {
    min-height: 38px;
    padding: 7px 12px !important;
    border-radius: 8px !important;
}

.crm-reports-shell #reports-content-area > .card,
.crm-reports-shell #reports-content-area [class*="stat-card"] {
    border-color: var(--crm-border) !important;
    border-radius: 15px !important;
    box-shadow: var(--crm-shadow-sm) !important;
}

/* Profile */
.crm-profile-shell > div:first-child {
    align-items: start;
}

.crm-profile-shell .id-card {
    overflow: hidden;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 18px 40px rgba(30, 53, 53, 0.18);
}

.crm-profile-shell .id-card-header {
    padding: 18px;
}

.crm-profile-shell .id-card-photo {
    box-shadow: 0 8px 22px rgba(30, 53, 53, 0.16);
}

.crm-profile-shell #profile-form > div[style*="grid-template-columns"],
.crm-profile-shell #doc-cards-grid {
    gap: 14px !important;
}

.crm-profile-shell #doc-cards-grid > div {
    border-color: var(--crm-border) !important;
    background: #faf9f7 !important;
    box-shadow: 0 5px 15px rgba(30, 53, 53, 0.045);
}

.crm-profile-shell #certifications-container,
.crm-profile-shell #expansion-network-container {
    min-width: 0;
}

/* Social Hub */
.crm-social-shell .sh-header {
    background:
        radial-gradient(circle at 92% 0%, rgba(205, 164, 52, 0.17), transparent 18rem),
        linear-gradient(135deg, #2f4f4f, #1e3535) !important;
    border-color: rgba(255, 255, 255, 0.10) !important;
    border-radius: 18px !important;
    box-shadow: var(--crm-shadow-md) !important;
}

.crm-social-shell .sh-tabs {
    gap: 5px;
    padding: 5px;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    border: 1px solid var(--crm-border);
    background: #eceae5 !important;
    scrollbar-width: none;
}

.crm-social-shell .sh-tabs::-webkit-scrollbar {
    display: none;
}

.crm-social-shell .sh-tab {
    min-height: 42px;
    flex: 0 0 auto !important;
    padding-inline: 14px !important;
}

.crm-social-shell .sh-card {
    border-color: var(--crm-border) !important;
    border-radius: 15px !important;
    box-shadow: var(--crm-shadow-sm) !important;
}

.crm-social-shell .sh-input,
.crm-social-shell .sh-composer textarea {
    border-color: var(--crm-border-strong) !important;
    border-radius: 11px !important;
}

@media (max-width: 900px) {
    .crm-module-intro {
        min-height: 0;
        margin-bottom: 14px;
        padding: 22px 20px;
        border-radius: 16px;
    }

    .crm-module-intro-icon {
        width: 54px;
        height: 54px;
        flex-basis: 54px;
        border-radius: 15px;
        font-size: 1.2rem;
    }

    .crm-finance-shell > .card {
        padding: 16px;
    }

    .crm-finance-shell > .card > div:first-child {
        margin: -16px -16px 18px !important;
        padding: 17px 16px !important;
        align-items: stretch !important;
        flex-direction: column;
    }

    .crm-finance-shell > .card > div:first-child > div:last-child {
        flex-basis: auto;
        justify-content: stretch;
    }

    .crm-finance-shell > .card > div:first-child > div:last-child > div[style*="width:1px"] {
        display: none;
    }

    .crm-finance-shell #project-filter,
    .crm-finance-shell #land-status-filter,
    .crm-finance-shell #advisor-filter,
    .crm-finance-shell #finance-search {
        width: 100% !important;
        min-width: 0;
        flex-basis: 100%;
    }

    .finance-land-status-summary {
        grid-template-columns: 1fr;
        gap: 9px;
    }

    .finance-status-card {
        min-height: 68px;
        padding: 11px 13px;
    }

    .land-status-modal-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .land-status-modal-actions button {
        width: 100%;
    }

    .crm-finance-shell .grid-split-2 {
        grid-template-columns: 1fr !important;
    }

    .crm-finance-shell .grid-split-2 > div {
        padding-inline: 0 !important;
        border-right: 0 !important;
    }

    .crm-training-shell #tab-content-contenido > div:first-child {
        align-items: stretch !important;
        flex-direction: column;
    }

    .crm-training-shell #tab-content-contenido > div:first-child > div {
        align-items: stretch !important;
        flex-direction: column;
    }

    .crm-training-shell #training-dev-filter {
        width: 100%;
    }

    .crm-reports-shell > .card:first-child > div:nth-child(2) {
        align-items: stretch !important;
        flex-direction: column;
    }

    .crm-reports-shell .period-selector {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        scrollbar-width: none;
    }

    .crm-reports-shell .period-selector button {
        flex: 0 0 auto;
    }

    .crm-profile-shell > div:first-child {
        grid-template-columns: 1fr !important;
    }

    .crm-profile-shell > div:first-child > div:first-child {
        max-width: 520px;
        width: 100%;
        margin-inline: auto;
    }

    .crm-profile-shell #profile-form > div[style*="grid-template-columns"],
    .crm-profile-shell #doc-cards-grid {
        grid-template-columns: 1fr !important;
    }

    .crm-social-shell .sh-header {
        padding: 21px 19px !important;
        align-items: flex-start !important;
    }

    .crm-social-shell .sh-header > div:last-child {
        width: 100%;
        padding-bottom: 4px;
        overflow-x: auto;
        flex-wrap: nowrap !important;
        scrollbar-width: none;
    }

    .crm-social-shell .sh-header > div:last-child::-webkit-scrollbar {
        display: none;
    }

    .crm-social-shell .sh-platform-pill {
        flex: 0 0 auto;
    }
}

@media (max-width: 520px) {
    .crm-module-intro {
        padding: 19px 17px;
    }

    .crm-module-intro h2 {
        font-size: 1.15rem;
    }

    .crm-module-intro p {
        font-size: 0.79rem;
    }

    .crm-module-intro-icon {
        display: none;
    }

    .crm-training-shell #video-grid,
    .crm-training-shell #resource-list {
        grid-template-columns: 1fr !important;
    }

    .crm-reports-shell .scroll-tabs > div {
        padding: 10px 12px !important;
    }

    .crm-profile-shell .card {
        padding-inline: 14px;
    }

    .crm-social-shell .sh-header h2 {
        font-size: 1.3rem !important;
    }

    .crm-social-shell .sh-platform-pill {
        padding: 7px 12px !important;
        font-size: 0.72rem !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
