/* ═══════════════════════════════════════════════════════
   PulsifyAI Master CRM — Layout (Shell, Sidebar, Content)
   Mobile-first responsive design
   ═══════════════════════════════════════════════════════ */

/* ── App Shell ────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    /* Dynamic viewport for mobile browsers */
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    transition: transform var(--transition-med), width var(--transition-med);
    will-change: transform;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(160, 174, 192, 0.45);
    backdrop-filter: blur(3px);
    z-index: 190;
    opacity: 0;
    transition: opacity var(--transition-med);
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* ── Mobile Hamburger Toggle ──────────────────────────── */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-base);
    box-shadow: var(--shadow-raised-sm);
    z-index: 150;
    padding: 0 16px;
    align-items: center;
    gap: 12px;
}

.mobile-header-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.mobile-header-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

.btn-hamburger {
    width: 40px;
    height: 40px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-raised-sm);
    background: var(--bg-base);
    padding: 10px;
    flex-shrink: 0;
}

.btn-hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: all var(--transition-fast);
}

/* ── Sidebar Header ────────────────────────────────────── */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    margin-bottom: 32px;
}

.sidebar-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
}

.sidebar-brand-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* Close button inside sidebar for mobile */
.sidebar-close {
    display: none;
    margin-left: auto;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-round);
    box-shadow: var(--shadow-raised-sm);
    background: var(--bg-base);
    font-size: 1.1rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* ── Sidebar Navigation ──────────────────────────────── */
.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition-med);
    cursor: pointer;
    position: relative;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.3);
    box-shadow: var(--shadow-raised-sm);
}

.nav-item.active {
    color: var(--accent);
    font-weight: 600;
    background: var(--bg-base);
    box-shadow: var(--shadow-raised-sm);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
}

.nav-icon {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    flex-shrink: 0;
}

.nav-item.active .nav-icon {
    opacity: 1;
}

/* ── Sidebar Separator ────────────────────────────────── */
.sidebar-separator {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--shadow-dark), transparent);
    margin: 16px 12px;
}

/* ── Sidebar Footer (User) ────────────────────────────── */
.sidebar-footer {
    padding: 16px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: auto;
}

.sidebar-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-round);
    background: linear-gradient(135deg, var(--accent), #6BB5E8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 0.85rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-raised-sm);
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar-logout {
    margin-left: auto;
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.sidebar-logout:hover {
    color: var(--danger);
    box-shadow: var(--shadow-raised-sm);
}

/* ── Main Content ─────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px 40px;
    min-height: 100vh;
    min-height: 100dvh;
    transition: margin-left var(--transition-med);
}

/* ── Page Header ──────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 32px;
    gap: 20px;
    flex-wrap: wrap;
}

.page-header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-title-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-raised-sm);
    background: var(--bg-base);
}

.page-subtitle {
    font-size: 0.88rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.page-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ── Search Bar ───────────────────────────────────────── */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    box-shadow: var(--shadow-pressed);
    border-radius: var(--radius-lg);
    background: var(--bg-base);
    min-width: 260px;
    transition: all var(--transition-med);
}

.search-bar:focus-within {
    box-shadow: var(--shadow-pressed), 0 0 0 2px var(--accent-light);
}

.search-bar input {
    flex: 1;
    background: transparent;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.search-bar input::placeholder {
    color: var(--text-tertiary);
}

.search-bar svg {
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

/* ── Login Layout ─────────────────────────────────────── */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg-base);
    position: relative;
    overflow: hidden;
    padding: 20px;
}

.login-wrapper::before,
.login-wrapper::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: var(--bg-base);
}

.login-wrapper::before {
    width: 300px;
    height: 300px;
    top: -80px;
    left: -80px;
    box-shadow: var(--shadow-raised);
    opacity: 0.5;
}

.login-wrapper::after {
    width: 200px;
    height: 200px;
    bottom: -60px;
    right: -60px;
    box-shadow: var(--shadow-raised);
    opacity: 0.5;
}

.login-card {
    width: 420px;
    max-width: 100%;
    padding: 48px 40px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-raised);
    background: var(--bg-base);
    text-align: center;
    position: relative;
    z-index: 1;
}

/* ── Bottom Mobile Nav ────────────────────────────────── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-base);
    box-shadow: 0 -4px 16px rgba(163, 177, 198, 0.5),
        0 -1px 4px rgba(255, 255, 255, 0.7);
    z-index: 150;
    align-items: stretch;
    /* Safe area padding for iPhone home indicator */
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    border-radius: 0;
    transition: color var(--transition-fast);
    text-decoration: none;
}

.mobile-nav-item svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.75;
}

.mobile-nav-item.active {
    color: var(--accent);
}

.mobile-nav-item.active svg {
    filter: drop-shadow(0 0 4px rgba(77, 139, 202, 0.35));
}

/* ── Tablet: Collapsed sidebar ────────────────────────── */
@media (max-width: 1024px) {
    .sidebar {
        width: var(--sidebar-collapsed);
        padding: 16px 8px;
    }

    .sidebar-brand,
    .nav-item span:not(.nav-icon),
    .sidebar-user-info,
    .sidebar-logout {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .sidebar-header {
        justify-content: center;
    }

    .sidebar-footer {
        justify-content: center;
    }

    .main-content {
        margin-left: var(--sidebar-collapsed);
        padding: 24px 20px;
    }

    .page-title {
        font-size: 1.3rem;
    }

    .search-bar {
        min-width: 200px;
    }
}

/* ── Mobile: Full drawer sidebar + bottom nav bar ──────── */
@media (max-width: 640px) {

    /* Show mobile header */
    .mobile-header {
        display: flex;
    }

    /* Show bottom nav bar */
    .mobile-bottom-nav {
        display: flex;
    }

    /* Show sidebar close button */
    .sidebar-close {
        display: flex;
    }

    /* Sidebar becomes off-canvas drawer */
    .sidebar {
        width: 280px;
        transform: translateX(-100%);
        padding: 24px 16px;
        box-shadow: none;
    }

    /* Show all sidebar items when open */
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(163, 177, 198, 0.5);
    }

    .sidebar.open~* .sidebar-overlay {
        display: block;
        opacity: 1;
    }

    /* Reset collapsed overrides */
    .sidebar .sidebar-brand,
    .sidebar .nav-item span:not(.nav-icon),
    .sidebar .sidebar-user-info,
    .sidebar .sidebar-logout {
        display: flex !important;
    }

    .sidebar .sidebar-brand {
        flex-direction: column;
    }

    .sidebar .nav-item {
        justify-content: flex-start;
        padding: 12px 16px;
    }

    /* Main content: no sidebar margin, top + bottom padding for fixed bars */
    .main-content {
        margin-left: 0;
        padding: 80px 16px 80px;
        /* top=mobile header, bottom=nav bar */
        /* Add safe area inset support */
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    /* Page header stacks vertically */
    .page-header {
        margin-bottom: 20px;
        gap: 12px;
        flex-direction: column;
    }

    .page-title {
        font-size: 1.15rem;
    }

    .page-subtitle {
        font-size: 0.8rem;
    }

    .page-header-right {
        width: 100%;
        flex-direction: column;
        gap: 10px;
    }

    .search-bar {
        width: 100%;
        min-width: unset;
    }

    /* Login card mobile */
    .login-card {
        padding: 36px 24px;
    }
}