/* Mobile-First Responsive Design for DRC Assist */

/* Global viewport and overflow control */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
}

/* Remove blank space at top of dashboard */
.content-wrapper {
    padding-top: 0 !important;
    margin-top: 0 !important;
}

/* Comprehensive responsive main content spacing fixes */
main.col-md-9, main[class*="col-"], .main-content {
    padding-top: 0 !important;
    margin-top: 0 !important;
}

/* Mobile devices (up to 768px) */
@media (max-width: 768px) {
    main.col-md-9, main[class*="col-"], .main-content {
        padding-top: 0 !important;
        margin-top: 0 !important;
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .container-fluid .row {
        margin-top: 0 !important;
    }
    
    .navbar + .container-fluid {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
}

/* Tablet devices (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    main.col-md-9, main[class*="col-"], .main-content {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }
}

/* Desktop devices (1025px and up) */
@media (min-width: 1025px) {
    main.col-md-9, main[class*="col-"], .main-content {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }
}

/* Large desktop devices (1201px and up) */
@media (min-width: 1201px) {
    main.col-md-9, main[class*="col-"], .main-content {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }
}

/* Dashboard specific spacing fixes */
.row:first-child {
    margin-top: 0 !important;
}

/* Navbar and sidebar responsive spacing */
@media (max-width: 768px) {
    .navbar {
        margin-bottom: 0 !important;
    }
    
    .container-fluid {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
}

/* Universal content wrapper fixes for all screen sizes */
.content-wrapper {
    padding-top: 0 !important;
    margin-top: 0 !important;
}

/* Mobile first approach - fix for various screen sizes */
@media (max-width: 576px) {
    .content-wrapper {
        padding: 0 0.5rem 1rem 0.5rem !important;
        margin-top: 0 !important;
    }
    
    /* Ensure first elements have no top margin */
    .content-wrapper > *:first-child {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
}

@media (min-width: 577px) and (max-width: 992px) {
    .content-wrapper {
        padding: 0 1rem 1rem 1rem !important;
        margin-top: 0 !important;
    }
    
    .content-wrapper > *:first-child {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
}

@media (min-width: 993px) {
    .content-wrapper {
        padding: 0 1.5rem 1rem 1.5rem !important;
        margin-top: 0 !important;
    }
    
    .content-wrapper > *:first-child {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
}

/* Additional universal fixes for common elements */
.row:first-child, .container:first-child, .card:first-child {
    margin-top: 0 !important;
}

/* Bootstrap override for authenticated layout */
.container-fluid > .row {
    margin-top: 0 !important;
}

/* Sidebar and main content coordination */
@media (min-width: 768px) {
    .row {
        margin-top: 0 !important;
    }
    
    .col-md-9.ms-sm-auto {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
}

/* Global responsive text utilities */
.text-responsive {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    hyphens: auto !important;
}

/* Universal text wrapping for all screens */
* {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    box-sizing: border-box !important;
}

/* Ensure all containers fit within viewport */
.container, .container-fluid, .row, .col {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

/* Email and long text handling globally */
a[href^="mailto:"],
.text-break-all {
    word-break: break-all !important;
    overflow-wrap: break-word !important;
    hyphens: auto !important;
}

/* Mobile typography helpers */
.h5-mobile {
    font-size: 1.125rem !important;
}

.fs-sm-5 {
    font-size: 0.875rem !important;
}

/* Base Mobile Styles (320px and up) */
@media (max-width: 576px) {
    /* Typography scaling for mobile */
    .display-1 { font-size: 2.5rem !important; }
    .display-2 { font-size: 2rem !important; }
    .display-3 { font-size: 1.75rem !important; }
    .h1, h1 { font-size: 1.5rem !important; }
    .h2, h2 { font-size: 1.35rem !important; }
    .h3, h3 { font-size: 1.25rem !important; }
    .h4, h4 { font-size: 1.125rem !important; }
    
    /* Responsive text handling */
    .text-responsive,
    p, .card-text, .card-body p {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        hyphens: auto !important;
        line-height: 1.4 !important;
    }
    
    /* Help section mobile optimization */
    .bg-primary p {
        font-size: 0.875rem !important;
        line-height: 1.4 !important;
        padding: 0 0.5rem !important;
        margin-bottom: 0 !important;
    }
    
    .bg-primary .text-nowrap {
        white-space: normal !important;
        word-break: break-word !important;
    }
    
    /* Ensure contact section stays within viewport */
    .bg-primary {
        margin-bottom: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    /* Text overflow prevention */
    body {
        overflow-x: hidden !important;
    }
    
    .container, .container-fluid {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    /* Email link responsiveness */
    a[href^="mailto:"] {
        word-break: break-all !important;
        overflow-wrap: break-word !important;
    }
    
    /* Mobile container adjustments */
    .container-fluid {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
    
    /* Hero section mobile optimization */
    .hero-section {
        min-height: 60vh !important;
        padding: 2rem 0 !important;
    }
    
    .hero-section .container {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .hero-section .btn {
        width: 100% !important;
        margin-bottom: 0.75rem !important;
    }
    
    .hero-section .d-flex.gap-3 {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    /* Card optimizations for mobile */
    .card {
        margin-bottom: 1.5rem !important;
        border-radius: 12px !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    .card-title {
        font-size: 1.125rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    /* Form controls mobile styling */
    .form-control, .form-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 0.75rem !important;
        border-radius: 8px !important;
    }
    
    .btn {
        padding: 0.75rem 1.5rem !important;
        font-size: 1rem !important;
        border-radius: 8px !important;
        min-height: 44px !important; /* Touch target minimum */
    }
    
    /* Navigation mobile improvements */
    .navbar-brand {
        font-size: 1.25rem !important;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem !important;
        font-size: 1rem !important;
    }
    
    /* Sidebar mobile behavior */
    .sidebar {
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease-in-out !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        z-index: 1050 !important;
        width: 280px !important;
        background-color: var(--bs-dark) !important;
    }
    
    .sidebar.show {
        transform: translateX(0) !important;
    }
    
    .sidebar-backdrop {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        background-color: rgba(0, 0, 0, 0.5) !important;
        z-index: 1040 !important;
        opacity: 0 !important;
        transition: opacity 0.3s ease-in-out !important;
    }
    
    .sidebar-backdrop.show {
        opacity: 1 !important;
    }
    
    /* Main content adjustment when sidebar is hidden */
    main.col-md-9 {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Table responsive improvements */
    .table-responsive {
        border-radius: 8px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .table th, .table td {
        white-space: nowrap !important;
        padding: 0.5rem !important;
        font-size: 0.875rem !important;
    }
    
    /* Charts mobile optimization */
    .chart-container {
        position: relative !important;
        height: 250px !important;
        width: 100% !important;
    }
    
    /* Footer and bottom content spacing */
    footer {
        margin-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
    
    /* Prevent horizontal scroll on all elements */
    * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Long text content handling */
    .text-break {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-word !important;
        hyphens: auto !important;
    }
}
    
    /* Modal improvements for mobile */
    .modal-dialog {
        margin: 1rem !important;
        max-width: calc(100% - 2rem) !important;
    }
    
    .modal-body {
        padding: 1rem !important;
    }
    
    /* Analytics dashboard mobile */
    .analytics-card {
        margin-bottom: 1rem !important;
    }
    
    .analytics-card .card-body {
        padding: 1rem !important;
        text-align: center !important;
    }
    
    .analytics-card .h5 {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Pricing table mobile */
    .pricing-card {
        margin-bottom: 2rem !important;
        max-width: 100% !important;
    }
    
    .pricing-card .card-header {
        padding: 1.5rem 1rem !important;
    }
    
    .pricing-card .price {
        font-size: 2rem !important;
    }
    
    /* Form wizard mobile */
    .wizard-steps {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .wizard-step {
        width: 100% !important;
        padding: 0.75rem !important;
        text-align: center !important;
    }
    
    /* Footer mobile */
    .footer {
        padding: 2rem 0 !important;
    }
    
    .footer .row > div {
        margin-bottom: 2rem !important;
        text-align: center !important;
    }
    
    /* Hide desktop-only elements */
    .d-none-mobile {
        display: none !important;
    }
    
    /* Touch-friendly elements */
    .btn, .nav-link, .card, input, select, textarea {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1) !important;
        -webkit-touch-callout: none !important;
    }
}

/* Tablet Portrait (577px to 768px) */
@media (min-width: 577px) and (max-width: 768px) {
    .hero-section {
        min-height: 65vh !important;
    }
    
    .display-2 { font-size: 2.5rem !important; }
    
    .card-columns {
        column-count: 2 !important;
    }
    
    .sidebar {
        width: 240px !important;
    }
    
    main.col-md-9 {
        margin-left: 0 !important;
        padding-left: 1rem !important;
    }
    
    .table th, .table td {
        padding: 0.75rem !important;
        font-size: 0.9rem !important;
    }
}

/* Tablet Landscape (769px to 992px) */
@media (min-width: 769px) and (max-width: 992px) {
    .hero-section {
        min-height: 70vh !important;
    }
    
    .card-columns {
        column-count: 3 !important;
    }
    
    .sidebar {
        position: relative !important;
        transform: none !important;
        width: 220px !important;
    }
    
    main.col-md-9 {
        margin-left: 220px !important;
        width: calc(100% - 220px) !important;
    }
}

/* Desktop (993px and up) */
@media (min-width: 993px) {
    .hero-section {
        min-height: 75vh !important;
    }
    
    .sidebar {
        position: fixed !important;
        width: 250px !important;
    }
    
    main.col-md-9 {
        margin-left: 250px !important;
        width: calc(100% - 250px) !important;
    }
    
    /* Show desktop-only elements */
    .d-desktop-only {
        display: block !important;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card, .btn, .form-control {
        -webkit-font-smoothing: antialiased !important;
        -moz-osx-font-smoothing: grayscale !important;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .hero-section {
        min-height: 50vh !important;
        padding: 1rem 0 !important;
    }
    
    .hero-section .container {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }
    
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
}

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

/* Dark mode improvements for mobile */
@media (prefers-color-scheme: dark) {
    .form-control {
        background-color: var(--bs-dark) !important;
        border-color: var(--bs-secondary) !important;
        color: var(--bs-light) !important;
    }
    
    .card {
        background-color: var(--bs-dark) !important;
        border-color: var(--bs-secondary) !important;
    }
}

/* Improved touch targets */
.touch-target {
    min-height: 44px !important;
    min-width: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Mobile navigation improvements */
.mobile-nav-toggle {
    display: none !important;
    position: fixed !important;
    top: 1rem !important;
    left: 1rem !important;
    z-index: 1060 !important;
    background-color: var(--bs-primary) !important;
    border: none !important;
    border-radius: 8px !important;
    padding: 0.75rem !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
}

@media (max-width: 768px) {
    .mobile-nav-toggle {
        display: block !important;
    }
}

/* Scrollbar improvements for mobile */
::-webkit-scrollbar {
    width: 6px !important;
    height: 6px !important;
}

::-webkit-scrollbar-track {
    background: transparent !important;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3) !important;
    border-radius: 3px !important;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5) !important;
}