/**
 * StratBear Global Responsive Fixes
 * Addresses iPad and mobile display issues across the platform
 */

/* ============================================
   CRITICAL VIEWPORT & BOX MODEL FIXES
   ============================================ */

* {
    box-sizing: border-box;
}

/* Prevent iOS text size adjustment */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Prevent horizontal overflow */
html, body {
    overflow-x: hidden;
    width: 100%;
}

/* ============================================
   iPAD SPECIFIC FIXES (768px - 1366px)
   ============================================ */

/* iPad Portrait (768px x 1024px) */
@media only screen
  and (min-device-width: 768px)
  and (max-device-width: 1024px)
  and (orientation: portrait) {

    /* Container width adjustments */
    .container {
        max-width: 720px;
        padding-left: 20px;
        padding-right: 20px;
    }

    /* Font size adjustments for better readability */
    body {
        font-size: 16px;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.75rem;
    }

    h3 {
        font-size: 1.5rem;
    }

    /* Card and panel adjustments */
    .card, .panel, .demo-option-card {
        margin-left: 10px;
        margin-right: 10px;
    }

    /* Grid adjustments */
    .row {
        margin-left: -10px;
        margin-right: -10px;
    }

    [class*="col-"] {
        padding-left: 10px;
        padding-right: 10px;
    }

    /* Button sizing for touch */
    .btn {
        min-height: 44px;
        padding: 12px 24px;
        font-size: 16px;
    }

    /* Navigation adjustments */
    .navbar {
        padding: 1rem;
    }

    .navbar-brand {
        font-size: 1.25rem;
    }

    /* Modal adjustments */
    .modal-dialog {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }
}

/* iPad Landscape (1024px x 768px) */
@media only screen
  and (min-device-width: 768px)
  and (max-device-width: 1024px)
  and (orientation: landscape) {

    .container {
        max-width: 960px;
    }

    /* Two-column layout for cards */
    .col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Adjust spacing */
    .demo-option-card {
        margin-bottom: 1.5rem;
    }
}

/* iPad Pro (1024px - 1366px) */
@media only screen
  and (min-device-width: 1024px)
  and (max-device-width: 1366px) {

    .container {
        max-width: 1140px;
        padding-left: 30px;
        padding-right: 30px;
    }

    /* Maintain three-column layouts */
    .col-lg-4 {
        flex: 0 0 33.333333%;
        max-width: 33.333333%;
    }

    /* Larger touch targets */
    .btn {
        min-height: 48px;
        padding: 14px 28px;
    }
}

/* ============================================
   MOBILE FIXES (< 768px)
   ============================================ */

@media (max-width: 767px) {

    /* Stack columns on mobile */
    [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
        padding-left: 15px;
        padding-right: 15px;
    }

    /* Full-width containers with padding */
    .container, .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }

    /* Typography scaling */
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    p, .text-body {
        font-size: 1rem;
    }

    /* Card and panel spacing */
    .card, .panel {
        margin-bottom: 1rem;
        border-radius: 8px;
    }

    /* Button adjustments */
    .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        min-height: 44px;
    }

    .btn-group {
        display: flex;
        flex-direction: column;
    }

    /* Table responsiveness */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Navigation mobile menu */
    .navbar-collapse {
        padding: 1rem 0;
    }

    .navbar-nav .nav-link {
        padding: 0.75rem 0;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }

    /* Modal full screen on mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-content {
        height: 100%;
        border-radius: 0;
    }
}

/* Small mobile devices (< 480px) */
@media (max-width: 479px) {

    /* Even smaller padding */
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }

    /* Smaller fonts for tiny screens */
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    /* Remove margins on cards */
    .card, .panel {
        margin-left: 0;
        margin-right: 0;
        border-radius: 0;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    a, button, input, select, textarea {
        min-height: 44px;
    }

    /* Disable hover effects on touch */
    .card:hover,
    .btn:hover,
    .demo-option-card:hover {
        transform: none !important;
    }

    /* Increase spacing between clickable elements */
    .btn + .btn {
        margin-left: 0.5rem;
    }

    /* Make dropdowns more touch-friendly */
    .dropdown-menu {
        padding: 0.5rem 0;
    }

    .dropdown-item {
        padding: 0.75rem 1.5rem;
    }
}

/* ============================================
   HIGH DPI / RETINA DISPLAY FIXES
   ============================================ */

@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {

    /* Sharper text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Thinner borders for high DPI */
    .border {
        border-width: 0.5px;
    }

    /* Better icon rendering */
    .fas, .far, .fab {
        -webkit-font-smoothing: antialiased;
    }
}

/* ============================================
   ORIENTATION CHANGE FIXES
   ============================================ */

@media (orientation: landscape) and (max-height: 500px) {

    /* Reduce vertical spacing in landscape */
    .navbar {
        padding: 0.5rem 1rem;
    }

    .section {
        padding: 2rem 0;
    }

    h1 {
        margin-bottom: 1rem;
    }
}

/* ============================================
   SPECIFIC COMPONENT FIXES
   ============================================ */

/* Fix demo setup cards */
.demo-option-card {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Fix PDF viewer on mobile */
.pdf-viewer-container {
    max-width: 100%;
    overflow-x: hidden;
}

.pdf-viewer-frame {
    max-width: 100%;
    width: 100%;
}

/* Fix strategic command center cards */
.strategic-card {
    min-height: auto;
    margin-bottom: 1rem;
}

/* Fix dashboard metrics on iPad */
@media (min-width: 768px) and (max-width: 1024px) {
    .metric-card {
        padding: 1.5rem;
    }

    .metric-value {
        font-size: 2rem;
    }

    .metric-label {
        font-size: 0.9rem;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Responsive text alignment */
@media (max-width: 767px) {
    .text-md-center {
        text-align: center !important;
    }

    .text-md-left {
        text-align: left !important;
    }

    .text-md-right {
        text-align: right !important;
    }
}

/* Responsive spacing */
@media (max-width: 767px) {
    .p-md-0 { padding: 0 !important; }
    .p-md-1 { padding: 0.25rem !important; }
    .p-md-2 { padding: 0.5rem !important; }
    .p-md-3 { padding: 1rem !important; }
    .p-md-4 { padding: 1.5rem !important; }
    .p-md-5 { padding: 3rem !important; }

    .m-md-0 { margin: 0 !important; }
    .m-md-1 { margin: 0.25rem !important; }
    .m-md-2 { margin: 0.5rem !important; }
    .m-md-3 { margin: 1rem !important; }
    .m-md-4 { margin: 1.5rem !important; }
    .m-md-5 { margin: 3rem !important; }
}

/* Responsive display */
@media (max-width: 767px) {
    .d-md-none { display: none !important; }
    .d-md-block { display: block !important; }
    .d-md-flex { display: flex !important; }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Focus styles for keyboard navigation */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #3b82f6;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-content:focus {
    top: 0;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    /* Hide unnecessary elements */
    .navbar,
    .sidebar,
    .footer,
    .btn,
    .no-print {
        display: none !important;
    }

    /* Ensure content fills page */
    .container {
        max-width: 100%;
        padding: 0;
    }

    /* Reset colors for printing */
    * {
        color: #000 !important;
        background: transparent !important;
    }
}