/**
 * Enhanced Mobile Responsive CSS for SendKimbla
 * Optimized for iOS and Android devices
 */

/* Base Mobile Styles (All Mobile Devices) */
@media only screen and (max-width: 767px) {

    /* Hide sidebar on mobile */
    body > div.container-fluid > div.row-fluid > div.span2 {
        display: none;
    }

    /* Full width main content */
    body > div.container-fluid > div.row-fluid > div.span10 {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Navbar improvements */
    .navbar-fixed-top {
        position: relative !important;
    }

    .navbar .brand {
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Tables - make scrollable horizontally */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }

    /* Hide less important table columns on mobile */
    #brands-table > thead > tr > th:nth-child(1),
    #brands-table > tbody > tr > td:nth-child(1),
    #brands-table > thead > tr > th:nth-child(3),
    #brands-table > tbody > tr > td:nth-child(3),
    #brands-table > thead > tr > th:nth-child(5),
    #brands-table > tbody > tr > td:nth-child(5),
    #brands-table > thead > tr > th:nth-child(6),
    #brands-table > tbody > tr > td:nth-child(6) {
        display: none;
    }

    /* Form improvements */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        box-sizing: border-box;
    }

    .input-xlarge,
    .input-large,
    .input-medium {
        width: 100% !important;
        box-sizing: border-box;
    }

    /* Buttons - make them touch-friendly */
    .btn {
        padding: 10px 15px !important;
        font-size: 14px !important;
        min-height: 44px; /* Apple's recommended touch target */
        margin: 5px 0;
    }

    .btn-group {
        display: block !important;
        width: 100% !important;
    }

    .btn-group > .btn {
        display: block !important;
        width: 100% !important;
        margin: 5px 0 !important;
    }

    /* Dropdown menus */
    .dropdown-menu {
        position: static !important;
        float: none !important;
        width: 100% !important;
        margin: 0 !important;
        max-height: 300px;
        overflow-y: auto;
    }

    /* Modal improvements */
    .modal {
        width: 95% !important;
        margin-left: 2.5% !important;
        left: 0 !important;
        top: 10px !important;
    }

    .modal-body {
        max-height: 400px;
        overflow-y: auto;
    }

    /* Alert messages */
    .alert {
        font-size: 14px;
        padding: 15px;
    }

    /* Card/Panel improvements */
    .well {
        padding: 15px;
        margin-bottom: 15px;
    }

    /* Typography */
    h1 { font-size: 24px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }

    p.lead {
        font-size: 16px !important;
        line-height: 1.4;
    }

    /* Campaign editor specific */
    #edit-form .control-group {
        margin-bottom: 15px;
    }

    #edit-form label {
        display: block;
        margin-bottom: 5px;
    }

    /* Media Library mobile optimization */
    .media-library-container {
        padding: 10px !important;
    }

    .media-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
        gap: 10px !important;
    }

    .media-thumbnail {
        height: 100px !important;
    }

    .upload-area {
        padding: 20px !important;
    }

    .toolbar {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .search-box {
        width: 100% !important;
        min-width: auto !important;
    }

    .filter-buttons {
        width: 100%;
        justify-content: space-between;
    }

    /* Actions bar for media library */
    .actions-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 10px !important;
    }

    /* CKEditor mobile optimization */
    .cke_chrome {
        border: 1px solid #ddd !important;
    }

    .cke_top {
        padding: 5px !important;
    }

    .cke_toolbar {
        margin: 2px !important;
    }

    .cke_button {
        padding: 5px !important;
    }

    /* Subscriber list improvements */
    .table-wrapper div.scrollable table {
        margin-left: 0px !important;
    }

    .pinned {
        display: none !important;
    }

    /* Navigation improvements */
    .nav-collapse {
        max-height: none !important;
    }

    .nav-collapse.collapse {
        height: auto !important;
        overflow: visible !important;
    }

    /* Pagination */
    .pagination {
        text-align: center;
    }

    .pagination ul > li {
        display: inline-block;
    }

    /* Settings page */
    #settings-form .control-group {
        margin-bottom: 20px;
    }

    /* Reports page */
    .chart-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Small Mobile Devices (phones < 480px) */
@media only screen and (max-width: 480px) {

    .container-fluid {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .navbar .brand {
        font-size: 16px;
        max-width: 150px;
    }

    .btn-group.pull-right {
        float: none !important;
        display: block !important;
        width: 100% !important;
        margin-bottom: 10px;
    }

    /* Stack buttons vertically */
    .form-actions .btn {
        display: block;
        width: 100% !important;
        margin: 5px 0 !important;
    }

    /* Media library grid - 2 columns on small phones */
    .media-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    h1 { font-size: 22px !important; }
    h2 { font-size: 18px !important; }
    h3 { font-size: 16px !important; }
}

/* Tablet Devices (768px - 991px) */
@media only screen and (min-width: 768px) and (max-width: 991px) {

    .span2 {
        width: 20%;
    }

    .span10 {
        width: 78%;
    }

    /* Media library - 3 columns on tablets */
    .media-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    }
}

/* Landscape orientation optimization */
@media only screen and (max-width: 767px) and (orientation: landscape) {

    .navbar-fixed-top {
        position: fixed !important;
    }

    .modal {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea {
        font-size: 16px !important; /* Prevents zoom */
    }

    select {
        font-size: 16px !important;
    }
}

/* Android specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Android Chrome */
    select {
        background-image: none;
        padding-right: 10px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    a, button, input[type="submit"], input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 15px;
    }

    /* Remove hover effects on touch devices */
    .btn:hover {
        background-color: inherit;
    }

    /* Improve link spacing */
    a {
        padding: 5px;
        margin: 2px 0;
        display: inline-block;
    }
}

/* High DPI screens (Retina displays) */
@media only screen and (-webkit-min-device-pixel-ratio: 2),
       only screen and (min--moz-device-pixel-ratio: 2),
       only screen and (min-resolution: 192dpi) {

    /* Ensure images don't look blurry */
    img {
        -ms-interpolation-mode: bicubic;
        image-rendering: -webkit-optimize-contrast;
    }
}

/* Print styles (bonus) */
@media print {
    .navbar,
    .sidebar,
    .btn,
    .form-actions {
        display: none !important;
    }

    .container-fluid {
        width: 100% !important;
    }
}
