/* ================================================
   MOBILE & TABLET OVERRIDES
   CampaignBrain App - Responsive Styles

   Import AFTER styles.css and Tailwind
   Last updated: 2025-12-15
   ================================================ */

/* -----------------------------------------
   CSS VARIABLES FOR RESPONSIVE
   ----------------------------------------- */
:root {
    --sidebar-width: 256px;
    --sidebar-collapsed-width: 0px;
    --header-height: 64px;
    --footer-height: 48px;
    --mobile-nav-height: 56px;
    --touch-target-min: 44px;
}

/* -----------------------------------------
   GLOBAL RESPONSIVE UTILITIES
   ----------------------------------------- */

/* Hide on mobile */
@media (max-width: 767px) {
    .hide-mobile,
    .hide-on-mobile {
        display: none !important;
    }
}

/* Hide on tablet */
@media (min-width: 768px) and (max-width: 1023px) {
    .hide-tablet {
        display: none !important;
    }
}

/* Show only on mobile */
@media (min-width: 768px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* Show only on tablet and below */
@media (min-width: 1024px) {
    .show-tablet-down {
        display: none !important;
    }
}

/* -----------------------------------------
   SIDEBAR & NAVIGATION - TABLET
   ----------------------------------------- */

/* Tablet: Narrow sidebar */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar {
        width: 200px !important;
    }

    .sidebar .nav-text {
        font-size: 0.875rem;
    }

    .main-content {
        margin-left: 200px !important;
    }
}

/* Mobile: Sidebar becomes slide-in drawer */
@media (max-width: 767px) {
    .sidebar {
        position: fixed !important;
        left: -100% !important;
        top: 0;
        bottom: 0;
        width: 280px !important;
        z-index: 1000;
        transition: left 0.3s ease-in-out;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

    .sidebar.open,
    .sidebar.mobile-open {
        left: 0 !important;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease-in-out;
    }

    .sidebar-overlay.visible {
        opacity: 1;
        visibility: visible;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* Mobile hamburger button */
.mobile-menu-btn {
    display: none;
    padding: 0.5rem;
    border-radius: 0.375rem;
    background: transparent;
    border: none;
    cursor: pointer;
}

@media (max-width: 767px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* -----------------------------------------
   HEADER RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    header, .header {
        padding: 0.75rem 1rem !important;
    }

    header h1, .header h1 {
        font-size: 1.25rem !important;
    }

    /* Header actions stack or hide */
    .header-actions {
        gap: 0.5rem;
    }

    .header-actions .btn-text {
        display: none;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    header, .header {
        padding: 0.75rem 1.5rem !important;
    }
}

/* -----------------------------------------
   CONTENT AREA RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    .content-wrapper, .p-6 {
        padding: 1rem !important;
    }

    .content-wrapper .bg-white.rounded-lg.shadow-lg {
        margin: 0 -0.5rem;
        border-radius: 0.5rem;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .content-wrapper {
        padding: 1.5rem !important;
    }
}

/* -----------------------------------------
   DASHBOARD SPECIFIC
   ----------------------------------------- */

/* Stats cards - better tablet breakpoint */
@media (min-width: 640px) and (max-width: 1023px) {
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Quick actions - stack on small tablets */
@media (min-width: 768px) and (max-width: 900px) {
    .dashboard-actions {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 639px) {
    .dashboard-actions {
        grid-template-columns: 1fr !important;
    }

    .dashboard-actions a {
        flex-direction: row !important;
        justify-content: flex-start !important;
        padding: 1rem !important;
    }

    .dashboard-actions a .rounded-full {
        margin-bottom: 0 !important;
        margin-right: 1rem !important;
    }
}

/* Recent Audience & Events - stack on tablet */
@media (max-width: 1023px) {
    .dashboard-bottom-grid {
        grid-template-columns: 1fr !important;
    }
}

/* -----------------------------------------
   TABLES RESPONSIVE
   ----------------------------------------- */

/* Wrap all tables for horizontal scroll */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* On mobile, make tables more compact */
@media (max-width: 767px) {
    .table-responsive table {
        font-size: 0.875rem;
    }

    .table-responsive th,
    .table-responsive td {
        padding: 0.5rem 0.75rem !important;
        white-space: nowrap;
    }

    /* Hide less important columns on mobile */
    .table-responsive .hide-on-mobile {
        display: none !important;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .table-responsive .hide-on-tablet {
        display: none !important;
    }
}

/* Card-style tables for mobile (alternative) */
@media (max-width: 639px) {
    .table-as-cards thead {
        display: none;
    }

    .table-as-cards tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: 1rem;
        background: white;
    }

    .table-as-cards tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0 !important;
        border-bottom: 1px solid #f3f4f6;
    }

    .table-as-cards tbody td:last-child {
        border-bottom: none;
    }

    .table-as-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: 0.75rem;
        text-transform: uppercase;
    }
}

/* -----------------------------------------
   I360 SEARCH PAGE SPECIFIC
   ----------------------------------------- */

/* Filter sidebar - collapsible on tablet */
@media (min-width: 768px) and (max-width: 1023px) {
    #filterSidebar {
        width: 260px !important;
    }

    #filterSidebar.collapsed {
        width: 48px !important;
    }

    #filterSidebar.collapsed .filter-content-area,
    #filterSidebar.collapsed .filter-actions,
    #filterSidebar.collapsed .bg-gradient-to-r > div:not(button) {
        display: none;
    }
}

/* Mobile: Filter becomes modal/drawer */
@media (max-width: 767px) {
    .i360-layout {
        flex-direction: column !important;
        height: auto !important;
    }

    #filterSidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100% !important;
        max-width: 320px;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        height: 100vh !important;
        max-height: 100vh !important;
    }

    #filterSidebar.open {
        transform: translateX(0);
    }

    .i360-main-content {
        height: auto !important;
        max-height: none !important;
        min-height: calc(100vh - var(--header-height) - var(--footer-height));
    }

    /* Mobile filter toggle button */
    .mobile-filter-toggle {
        display: flex !important;
        position: sticky;
        top: 0;
        z-index: 50;
        background: white;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid #e5e7eb;
        margin-bottom: 0;
    }

    /* Selection bar - stack buttons */
    #selectionBar {
        flex-direction: column !important;
        gap: 0.75rem;
        padding: 0.75rem !important;
    }

    #selectionBar > div {
        width: 100%;
        justify-content: center;
    }

    #selectionBar .flex.items-center.space-x-2 {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Results table - fewer columns */
    .i360-results-table .col-political,
    .i360-results-table .col-voting {
        display: none;
    }
}

/* Map container - smaller on mobile */
@media (max-width: 767px) {
    #map {
        height: 150px !important;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    #map {
        height: 180px !important;
    }
}

/* -----------------------------------------
   MODALS RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    .modal, [class*="modal"] > div {
        margin: 1rem;
        max-width: calc(100% - 2rem) !important;
        max-height: calc(100vh - 2rem) !important;
    }

    .modal-body {
        padding: 1rem !important;
    }

    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

/* -----------------------------------------
   FORMS RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    /* Stack form groups */
    .form-row, .grid.grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    /* Larger touch targets */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        min-height: var(--touch-target-min);
        font-size: 16px !important; /* Prevents iOS zoom */
    }

    /* Larger checkboxes and radios */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
    }

    /* Range sliders - larger thumb */
    input[type="range"] {
        height: 8px;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
}

/* -----------------------------------------
   BUTTONS RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    /* Ensure touch-friendly button sizes */
    .btn {
        min-height: var(--touch-target-min);
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .btn-sm {
        min-height: 36px;
    }

    .btn-xs {
        min-height: 32px;
    }

    /* Full-width buttons on mobile when in flex containers */
    .btn-group-mobile .btn {
        flex: 1;
    }
}

/* -----------------------------------------
   CARDS RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    .card {
        border-radius: 0.5rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    .card-header, .card-body {
        padding: 1rem !important;
    }
}

/* -----------------------------------------
   PAGINATION RESPONSIVE
   ----------------------------------------- */

@media (max-width: 639px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }

    .pagination .page-numbers {
        display: none;
    }

    .pagination .prev-next {
        flex: 1;
        justify-content: center;
    }
}

/* -----------------------------------------
   WORK QUEUE RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    .work-queue-header {
        flex-direction: column;
        gap: 1rem;
    }

    .work-queue-stats {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .work-queue-stats > div {
        flex: 1 1 45%;
    }

    .action-type-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

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

/* -----------------------------------------
   SEGMENTS PAGE RESPONSIVE
   ----------------------------------------- */

@media (max-width: 767px) {
    .segment-card {
        padding: 1rem !important;
    }

    .segment-card .segment-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .segment-card .segment-actions .btn {
        width: 100%;
    }
}

/* -----------------------------------------
   PRINT STYLES (for documentation)
   ----------------------------------------- */

@media print {
    .sidebar, .mobile-menu-btn, .no-print {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #e5e7eb;
    }
}

/* -----------------------------------------
   TOUCH DEVICE ENHANCEMENTS
   ----------------------------------------- */

@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .btn:hover {
        opacity: 1;
    }

    /* Add active states instead */
    .btn:active {
        opacity: 0.8;
        transform: scale(0.98);
    }

    /* Larger tap targets for rows */
    .table tbody tr {
        min-height: var(--touch-target-min);
    }

    /* Disable hover table highlights on touch */
    .table tbody tr:hover {
        background-color: inherit;
    }

    .table tbody tr:active {
        background-color: #f3f4f6;
    }
}

/* -----------------------------------------
   LANDSCAPE MOBILE (special case)
   ----------------------------------------- */

@media (max-width: 767px) and (orientation: landscape) {
    .sidebar {
        max-width: 250px;
    }

    /* Reduce vertical padding in landscape */
    .content-wrapper {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
}
