/* ============================================================
   SMMpro Responsive — Mobile-First Responsive Overhaul
   Unified responsive layer for all breakpoints (320px → 1440px+)
   ============================================================ */

/* ─── BASE MOBILE-FIRST RESETS ──────────────────────────────── */

/* Ensure all images and media are fluid */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* Prevent horizontal overflow globally */
html {
    overflow-x: hidden;
}
body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

/* Ensure touch targets are at least 44px — only for standalone interactive elements */
.btn-smm, .header-icon-btn, .pagination-btn,
.mobile-menu-toggle, .header-user-btn {
    min-height: 44px;
}

/* Smooth scrolling but respect user preferences */
@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

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


/* ================================================================
   SIDEBAR DRAWER — Mobile-Optimized Slide-In Navigation
   ================================================================ */

/* The sidebar is always rendered but off-screen on mobile/tablet */
@media (max-width: 1199px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        z-index: 1100;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
        display: flex !important; /* Override any display:none */
        visibility: visible !important;
    }
    .app-sidebar.open {
        transform: translateX(0);
        box-shadow: 16px 0 48px rgba(0, 0, 0, 0.15);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0);
        z-index: 1099;
        display: none;
        transition: background 0.3s ease;
    }
    .sidebar-overlay.active {
        display: block;
        background: rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(4px);
    }

    .app-main.sidebar-wrapper.content-area {
        margin-left: 0 !important;
    }

    /* Mobile close button inside sidebar */
    .sidebar-close-btn {
        display: flex !important;
    }
}

@media (min-width: 1200px) {
    .sidebar-close-btn {
        display: none !important;
    }
}


/* ================================================================
   EXTRA SMALL DEVICES — 320px to 480px (Mobile Phones)
   ================================================================ */

@media (max-width: 480px) {

    /* ─── Typography ─────────────────────────────────── */
    body { font-size: 14px; }
    .page-title { font-size: 20px !important; letter-spacing: -0.01em; }
    .page-subtitle { font-size: 13px; }
    .page-eyebrow { font-size: 10px; }
    .h1 { font-size: 22px; }
    .h2 { font-size: 18px; }
    .h3 { font-size: 16px; }
    .h4 { font-size: 15px; }
    .h5, h5 { font-size: 14px; }

    /* ─── Layout ──────────────────────────────────────── */
    .app-content.container-fluid {
        padding-left: 12px !important;
        padding-right: 12px !important;
        padding-top: 16px !important;
    }

    /* ─── Header ──────────────────────────────────────── */
    .app-header {
        height: 56px;
        padding: 0 12px !important;
        gap: 8px;
    }
    .workspace-switcher { display: none !important; }
    .header-search-bar { display: none !important; }
    .header-user-info { display: none !important; }
    .header-icon-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 16px;
    }
    .avatar-header-md {
        width: 34px;
        height: 34px;
        min-width: 34px;
        border-radius: 10px;
        font-size: 13px;
    }
    .mobile-menu-toggle {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    /* ─── Cards ───────────────────────────────────────── */
    .card-smm {
        padding: 16px !important;
        border-radius: 16px;
    }

    /* ─── KPI Grid ────────────────────────────────────── */
    .kpi-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    .kpi-card-new { padding: 14px 16px; border-radius: 14px; }
    .kpi-num { font-size: 20px !important; }
    .kpi-icon-wrap { width: 36px; height: 36px; font-size: 16px; border-radius: 10px; }
    .kpi-desc { font-size: 11px; }
    .kpi-badge-trend { font-size: 9px; padding: 2px 6px; }

    /* ─── Buttons ─────────────────────────────────────── */
    .btn-smm { padding: 10px 16px; font-size: 13px; border-radius: 10px; }
    .btn-smm-lg { padding: 12px 20px; font-size: 14px; }
    .btn-smm-xl { padding: 14px 24px; font-size: 15px; }
    .btn-smm-sm { padding: 8px 14px; font-size: 11px; }
    .btn-icon-sm { width: 36px; height: 36px; }
    .page-actions { width: 100%; flex-wrap: wrap; }
    .page-actions .btn-smm { flex: 1; min-width: 0; justify-content: center; }

    /* ─── Tables ──────────────────────────────────────── */
    .table-responsive { margin: 0 -12px; border-radius: 0; }
    .data-table th, .data-table td { padding: 10px 8px !important; font-size: 12px; }
    .data-table th:first-child, .data-table td:first-child { padding-left: 12px !important; }
    .data-table th:last-child, .data-table td:last-child { padding-right: 12px !important; }

    /* ─── Charts ──────────────────────────────────────── */
    .chart-area, .chart-canvas-wrap { height: 220px !important; }
    .chart-350 { height: 250px !important; }
    .chart-200 { height: 160px !important; }

    /* ─── Forms ───────────────────────────────────────── */
    .form-control-smm, .form-input-smm, .input-smm {
        padding: 12px 14px;
        font-size: 16px; /* Prevents iOS zoom */
        border-radius: 10px;
    }
    .form-select-smm { font-size: 16px; padding: 12px 14px; }
    .form-section { padding: 16px; border-radius: 14px; }
    .form-floating-smm label { font-size: 13px; }

    /* ─── Badges ──────────────────────────────────────── */
    .badge-smm { font-size: 9px; padding: 3px 8px; }

    /* ─── Footer ──────────────────────────────────────── */
    .app-footer {
        padding: 32px 16px 20px !important;
    }
    .app-footer .row { gap: 24px !important; }
    .app-footer .col-lg-2,
    .app-footer .col-lg-4,
    .app-footer .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }
    .footer-heading { margin-bottom: 10px; }

    /* ─── Modals ──────────────────────────────────────── */
    .modal-dialog { margin: 8px !important; }
    .modal-content { border-radius: 16px !important; }
    .modal-header, .modal-body, .modal-footer { padding: 16px !important; }

    /* ─── Alerts ──────────────────────────────────────── */
    .alert-smm { font-size: 13px; padding: 12px 14px; border-radius: 12px; }
    .panel-alert { padding: 12px 14px; font-size: 13px; border-radius: 10px; }

    /* ─── Panel Cards ─────────────────────────────────── */
    .panel-card-header { padding: 12px 14px; }
    .panel-card-body { padding: 14px; }
    .panel-card-title { font-size: 14px; }

    /* ─── Pagination ──────────────────────────────────── */
    .pagination-bar { gap: 4px; }
    .pagination-btn { height: 34px; min-width: 34px; padding: 0 8px; font-size: 12px; }

    /* ─── Bulk Toolbar ────────────────────────────────── */
    .bulk-toolbar {
        left: 8px !important;
        right: 8px !important;
        bottom: 16px !important;
        padding: 12px 16px;
        border-radius: 14px;
        gap: 12px;
        font-size: 13px;
    }

    /* ─── Empty States ────────────────────────────────── */
    .empty-panel { padding: 40px 16px; }
    .empty-panel-icon { width: 60px; height: 60px; font-size: 24px; }
    .state-empty { padding: 40px 16px; min-height: 280px; }

    /* ─── Misc ────────────────────────────────────────── */
    .page-intro { margin-bottom: 20px !important; }
    .mb-5 { margin-bottom: 24px !important; }
    .mb-4 { margin-bottom: 16px !important; }
    .py-4 { padding-top: 16px !important; padding-bottom: 16px !important; }
    .px-lg-5 { padding-left: 12px !important; padding-right: 12px !important; }
    .g-4, .g-xl-5 { --bs-gutter-x: 12px; --bs-gutter-y: 12px; }

    /* Hide less important elements */
    .hide-mobile-xs { display: none !important; }

    /* Command Palette */
    .command-palette-overlay { padding-top: 10vh; }
    .command-palette-card { border-radius: 16px; }
    .command-palette-header { padding: 16px; }
    .command-palette-footer { padding: 10px 16px; }
    .command-palette-hints { display: none; }
}


/* ================================================================
   SMALL DEVICES — 481px to 767px (Large Phones / Small Tablets)
   ================================================================ */

@media (min-width: 481px) and (max-width: 767px) {

    .app-content.container-fluid {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    .app-header { padding: 0 14px !important; height: 60px; }
    .workspace-switcher { display: none !important; }
    .header-search-bar { display: none !important; }

    .page-title { font-size: 24px !important; }
    .page-subtitle { font-size: 14px; }

    .card-smm { padding: 20px !important; border-radius: 18px; }

    .kpi-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 14px !important;
    }
    .kpi-num { font-size: 24px !important; }

    .chart-area, .chart-canvas-wrap { height: 260px !important; }

    .app-footer { padding: 36px 20px 24px !important; }

    .page-actions { width: 100%; }
    .page-actions .btn-smm { flex: 1; justify-content: center; }
}


/* ================================================================
   TABLET — 768px to 1023px
   ================================================================ */

@media (min-width: 768px) and (max-width: 1023px) {

    .app-content.container-fluid {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }

    .app-header {
        height: 62px;
        padding: 0 16px !important;
    }
    .header-search-bar { display: none !important; }

    .page-title { font-size: 26px !important; }

    .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 16px !important; }
    .kpi-num { font-size: 26px !important; }

    .card-smm { padding: 24px !important; }

    .chart-area, .chart-canvas-wrap { height: 280px !important; }

    .app-footer { padding: 40px 24px 24px !important; }

    /* Tables: allow horizontal scroll */
    .table-responsive-wrapper,
    .table-responsive { -webkit-overflow-scrolling: touch; }
}


/* ================================================================
   LAPTOP — 1024px to 1199px
   ================================================================ */

@media (min-width: 1024px) and (max-width: 1199px) {
    .app-content.container-fluid {
        padding-left: 28px !important;
        padding-right: 28px !important;
    }

    .kpi-grid { grid-template-columns: repeat(4, 1fr) !important; }
}


/* ================================================================
   DESKTOP+ — 1200px and above
   ================================================================ */

@media (min-width: 1200px) {
    /* Sidebar margin for content */
    .app-main.sidebar-wrapper.content-area {
        margin-left: var(--sidebar-width);
    }
}


/* ================================================================
   RESPONSIVE TABLE — Card Transformation for Mobile (up to 767px)
   Add class 'table-mobile-cards' to any table for mobile cards
   ================================================================ */

@media (max-width: 767px) {
    /* Mobile card-based table */
    .table-mobile-cards thead { display: none; }
    .table-mobile-cards tbody tr {
        display: block;
        background: var(--smm-white);
        border: 1px solid var(--smm-grey-light);
        border-radius: 16px;
        margin-bottom: 12px;
        padding: 16px;
        box-shadow: 0 2px 12px rgba(0,0,0,0.04);
    }
    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0 !important;
        border: 0 !important;
        border-bottom: 1px solid rgba(0,0,0,0.05) !important;
        font-size: 13px;
    }
    .table-mobile-cards tbody td:first-child {
        padding-top: 0 !important;
    }
    .table-mobile-cards tbody td:last-child {
        border-bottom: 0 !important;
        padding-bottom: 0 !important;
    }
    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-size: 10px;
        font-weight: 800;
        text-transform: uppercase;
        color: var(--text-muted);
        letter-spacing: 0.06em;
        flex-shrink: 0;
        margin-right: 12px;
    }
    /* Hide data-label pseudo for empty labels */
    .table-mobile-cards tbody td[data-label=""]::before {
        display: none;
    }

    /* Base table-smm mobile improvements */
    .table-smm {
        font-size: 13px;
    }
    .table-smm th, .table-smm td {
        padding: 10px 8px !important;
    }
    .table-smm th:first-child, .table-smm td:first-child {
        padding-left: 14px !important;
    }
}

@media (min-width: 768px) {
    .table-mobile-cards thead { display: table-header-group; }
    .table-mobile-cards tbody tr { display: table-row; }
    .table-mobile-cards tbody td { display: table-cell; }
    .table-mobile-cards tbody td::before { display: none; }
}


/* ================================================================
   RESPONSIVE CHARTS
   ================================================================ */

/* Ensure canvas charts resize properly */
canvas {
    max-width: 100% !important;
}


/* ================================================================
   RESPONSIVE DONUT / CIRCLE CHARTS
   ================================================================ */

@media (max-width: 480px) {
    .donut-ring, .donut-ring-multi {
        width: 140px !important;
        height: 140px !important;
        border-width: 12px !important;
    }
    .donut-value { font-size: 20px !important; }
    .donut-label { font-size: 8px !important; }
}

@media (min-width: 481px) and (max-width: 767px) {
    .donut-ring, .donut-ring-multi {
        width: 160px !important;
        height: 160px !important;
    }
}


/* ================================================================
   DASHBOARD — Mobile-Specific Optimizations
   ================================================================ */

@media (max-width: 767px) {
    /* ─── Icon Circles ────────────────────────────────── */
    .icon-circle {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    .icon-circle i { font-size: 18px !important; }

    /* ─── Bento KPI Cards ─────────────────────────────── */
    .kpi-elite .body-small,
    .kpi-elite p { font-size: 10px; }
    .hover-reveal { opacity: 1; transform: none; } /* Always visible on touch */

    /* ─── Chart Container Heights ─────────────────────── */
    .bento-item .chart-canvas-wrap,
    .bento-item [style*="height: 380px"],
    .bento-item [style*="height: 180px"],
    .bento-item [style*="height: 140px"] {
        height: 200px !important;
    }
    .bento-item.p-0 .p-4.chart-canvas-wrap {
        padding: 12px !important;
    }

    /* ─── Recent Activity Section ─────────────────────── */
    .card-smm.shadow-premium .px-4.py-4 {
        padding: 14px 16px !important;
        flex-wrap: wrap;
        gap: 10px;
    }
    .card-smm.shadow-premium .px-4.py-4 h3,
    .card-smm.shadow-premium .px-4.py-4 .h4 {
        font-size: 16px !important;
    }
    .card-smm.shadow-premium .px-4.py-4 .btn-smm {
        font-size: 11px;
        padding: 6px 12px;
    }

    /* ─── Bento Chart Header ──────────────────────────── */
    .bento-item .p-4.border-bottom {
        padding: 12px 14px !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .bento-item .p-4.border-bottom h3 {
        font-size: 14px !important;
    }
    .bento-item .p-4.border-bottom p {
        font-size: 11px;
    }

    /* ─── Sender Score Box ────────────────────────────── */
    .border-gradient-elite .d-flex .size-md {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    /* ─── Space-y utility fix ─────────────────────────── */
    .space-y-3 > * + * { margin-top: 8px; }
}

/* Small phones — further compaction */
@media (max-width: 390px) {
    .kpi-elite .kpi-value { font-size: 18px !important; }
    .kpi-elite { padding: 12px !important; }

    .bento-item .chart-canvas-wrap,
    .bento-item [style*="height"] {
        height: 180px !important;
    }

    .icon-circle {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
    .icon-circle i { font-size: 16px !important; }
}


/* ================================================================
   RESPONSIVE FORMS — Settings Pages
   ================================================================ */

@media (max-width: 767px) {
    /* Account settings profile card */
    .profile-upload-wrapper {
        width: 120px !important;
        height: 120px !important;
    }

    /* Floating label adjustments */
    .form-floating-smm {
        margin-bottom: 12px;
    }
    .form-floating-smm .form-control-smm {
        font-size: 16px;
    }

    /* Settings sidebar nav becomes horizontal tabs */
    .settings-sidebar-nav {
        flex-direction: row;
        overflow-x: auto;
        gap: 4px;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
    }
    .settings-nav-link {
        white-space: nowrap;
        font-size: 12px;
        padding: 8px 12px;
    }

    /* List cards */
    .list-card-header { padding: 16px; }
    .list-card-stat { padding: 10px 12px; }
    .list-card-stat-value { font-size: 18px; }
}


/* ================================================================
   RESPONSIVE AI TOOLS PAGE
   ================================================================ */

@media (max-width: 767px) {
    .ai-feature-card { padding: 20px; border-radius: 14px; }
    .ai-feature-icon { width: 48px; height: 48px; border-radius: 14px; font-size: 22px; }
    .ai-feature-name { font-size: 14px; }
    .ai-feature-desc { font-size: 12px; }
}


/* ================================================================
   RESPONSIVE AUTH PAGES
   ================================================================ */

@media (max-width: 480px) {
    .social-btn { padding: 12px 16px; font-size: 13px; }
    .auth-divider { margin: 16px 0; }
}


/* ================================================================
   RESPONSIVE EMAIL BUILDER
   ================================================================ */

@media (max-width: 991px) {
    /* Builder panels stack vertically on tablet */
    .eb-sidebar,
    .eb-properties-panel {
        position: fixed;
        z-index: 1100;
        top: 0;
        bottom: 0;
        width: 300px;
        max-width: 85vw;
        transition: transform 0.3s ease;
    }
    .eb-sidebar { left: 0; transform: translateX(-100%); }
    .eb-sidebar.open { transform: translateX(0); }
    .eb-properties-panel { right: 0; transform: translateX(100%); }
    .eb-properties-panel.open { transform: translateX(0); }
}


/* ================================================================
   RESPONSIVE COMMAND PALETTE
   ================================================================ */

@media (max-width: 480px) {
    .command-palette-card {
        max-width: 100%;
        border-radius: 16px;
    }
    .command-palette-results { max-height: 40vh; }
    .command-palette-header input { font-size: 1rem; }
}


/* ================================================================
   LANDSCAPE PHONE OPTIMIZATIONS
   ================================================================ */

@media (max-height: 480px) and (orientation: landscape) {
    .app-header { height: 48px; }
    .app-content.container-fluid { padding-top: 8px !important; }
    .modal-dialog { margin: 4px !important; }
}


/* ================================================================
   PRINT RESPONSIVE
   ================================================================ */

@media print {
    .app-sidebar, .app-header, .sidebar-overlay,
    .mobile-menu-toggle, .bulk-toolbar { display: none !important; }
    .app-main.sidebar-wrapper.content-area { margin-left: 0 !important; }
    .app-content.container-fluid { padding: 0 !important; }
    .card-smm { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
}


/* ================================================================
   SAFE AREA INSETS (Notch support for modern phones)
   ================================================================ */

@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
    }
    .app-footer {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
    .bulk-toolbar {
        bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    }
    .app-sidebar {
        padding-top: env(safe-area-inset-top);
    }
}
