/**
 * Pars Medicine - Mobile Responsiveness CSS
 * Comprehensive mobile fixes for all Pars Medicine platforms
 * Version: 1.0.0
 * Date: 2026-01-23
 *
 * Covers:
 * - Main website (parsmedicine.com)
 * - EMR (emr.parsmedicine.com)
 * - Education portal (education.parsmedicine.com)
 * - Patient portal (emr.parsmedicine.com/portal)
 */

/* ============================================
   VIEWPORT & BASE MOBILE FIXES
   ============================================ */

/* Prevent horizontal scroll on all devices */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Ensure proper box sizing */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Ensure images never overflow */
img, video, iframe, embed, object {
    max-width: 100%;
    height: auto;
}

/* Prevent tables from causing horizontal scroll */
table {
    max-width: 100%;
    overflow-x: auto;
    display: block;
}

@media (min-width: 768px) {
    table {
        display: table;
    }
}

/* ============================================
   TOUCH TARGETS - MINIMUM 44x44px
   ============================================ */

/* Buttons */
button, .btn, [role="button"],
input[type="button"], input[type="submit"], input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
}

/* Links in navigation */
nav a, .nav a, .navbar a, .nav-link, .menu a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 10px 12px;
}

/* Form inputs */
input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="search"],
input[type="url"], input[type="date"], input[type="time"],
input[type="datetime-local"], textarea, select {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 16px; /* Prevents iOS zoom on focus */
}

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

/* ============================================
   READABLE TEXT SIZES
   ============================================ */

body {
    font-size: 16px;
    line-height: 1.6;
}

/* Minimum readable sizes */
p, li, td, th, label, span, a {
    font-size: inherit;
}

/* Small text adjustments */
small, .small, .text-small {
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Headings on mobile */
@media (max-width: 575.98px) {
    h1, .h1 { font-size: 1.75rem; }
    h2, .h2 { font-size: 1.5rem; }
    h3, .h3 { font-size: 1.25rem; }
    h4, .h4 { font-size: 1.125rem; }
    h5, .h5 { font-size: 1rem; }
    h6, .h6 { font-size: 0.9375rem; }
}

/* ============================================
   MOBILE NAVIGATION FIXES
   ============================================ */

/* Mobile navbar */
@media (max-width: 991.98px) {
    .navbar, .pars-navbar {
        padding: 8px 0;
    }

    .navbar-brand {
        max-width: 60%;
    }

    .navbar-brand img {
        max-height: 40px;
        width: auto;
    }

    /* Hamburger menu button */
    .navbar-toggler {
        min-width: 44px;
        min-height: 44px;
        padding: 8px 12px;
        border: 2px solid rgba(255,255,255,0.5);
    }

    /* Mobile menu */
    .navbar-collapse {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: inherit;
        z-index: 1000;
        padding: 15px;
        box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    }

    .navbar-nav {
        flex-direction: column;
    }

    .navbar-nav .nav-item {
        width: 100%;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }

    .navbar-nav .nav-link {
        padding: 12px 15px;
        display: block;
    }

    /* Dropdown on mobile */
    .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        margin: 0;
        padding: 0;
        border: none;
        box-shadow: none;
        background: rgba(0,0,0,0.1);
    }

    .dropdown-item {
        padding: 10px 25px;
    }

    /* Mega menu on mobile */
    .mega-menu {
        position: static !important;
        width: 100% !important;
        padding: 15px;
    }

    .mega-menu .row {
        flex-direction: column;
    }

    .mega-menu .col, .mega-menu [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 15px;
    }
}

/* ============================================
   BREAKPOINT FIXES - SMALL MOBILE (< 576px)
   ============================================ */

@media (max-width: 575.98px) {
    /* Container padding */
    .container, .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }

    /* Row negative margins */
    .row {
        margin-left: -10px;
        margin-right: -10px;
    }

    .row > * {
        padding-left: 10px;
        padding-right: 10px;
    }

    /* Cards stack full width */
    .card {
        margin-bottom: 15px;
    }

    /* Hide login form in navbar, show toggle */
    .pars-login-area {
        display: none !important;
    }

    /* Footer columns stack */
    .pars-footer .col-lg-2,
    .pars-footer .col-lg-3,
    .pars-footer .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
        text-align: center;
        margin-bottom: 20px;
    }

    .pars-footer .social-links {
        justify-content: center;
    }

    .pars-footer ul {
        text-align: center;
    }

    /* Topbar hidden on mobile */
    .pars-topbar {
        display: none;
    }

    /* Development banner compact - !important to override inline styles */
    #pars-dev-banner {
        font-size: 12px !important;
        padding: 6px 10px !important;
        line-height: 1.3;
    }
}

/* ============================================
   BREAKPOINT FIXES - MOBILE (576px - 767px)
   ============================================ */

@media (min-width: 576px) and (max-width: 767.98px) {
    .container {
        max-width: 100%;
    }

    /* Two column grid on small tablets */
    .row .col-sm-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ============================================
   BREAKPOINT FIXES - TABLET (768px - 991px)
   ============================================ */

@media (min-width: 768px) and (max-width: 991.98px) {
    /* Login area compact */
    .pars-login-area {
        min-width: 250px;
    }

    .pars-login-area input {
        width: 100px !important;
    }

    /* Sidebar adjustments */
    aside.col-lg-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .main-content .col-lg-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ============================================
   HOMEPAGE MOBILE FIXES
   ============================================ */

@media (max-width: 767.98px) {
    /* Banner section */
    .banner, .pars-hero-section {
        padding: 30px 15px !important;
    }

    .banner h1, .pars-hero-section h1 {
        font-size: 1.75rem !important;
    }

    .banner p, .pars-hero-section p {
        font-size: 1rem !important;
    }

    /* Three column boxes stack */
    .com-content-article__body > div[style*="grid-template-columns"] {
        display: block !important;
    }

    .com-content-article__body > div[style*="grid-template-columns"] > div {
        margin-bottom: 20px !important;
    }

    /* Quick access grid */
    .pars-quick-access {
        grid-template-columns: 1fr !important;
    }

    /* Welcome banner */
    .com-content-article__body > div > div[style*="linear-gradient(135deg, #1e3a8a"] {
        padding: 30px 15px !important;
    }

    .com-content-article__body > div > div[style*="linear-gradient(135deg, #1e3a8a"] > h1 {
        font-size: 1.75rem !important;
    }

    .com-content-article__body > div > div[style*="linear-gradient(135deg, #1e3a8a"] > div {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .com-content-article__body > div > div[style*="linear-gradient(135deg, #1e3a8a"] > div > a {
        width: 100% !important;
        text-align: center !important;
    }

    /* Quick Access boxes */
    .com-content-article__body > div > div[style*="background: #f8fafc"] > div[style*="grid-template-columns"] {
        display: block !important;
    }

    .com-content-article__body > div > div[style*="background: #f8fafc"] > div > div {
        margin-bottom: 15px !important;
    }

    /* Bottom A container */
    .bottom-a-container .moduletable {
        flex: 1 1 100% !important;
        max-width: 100% !important;
    }
}

/* ============================================
   SIDEBAR MOBILE FIXES
   ============================================ */

@media (max-width: 991.98px) {
    /* Sidebars stack below content */
    .sidebar-left, .sidebar-right {
        order: 2;
    }

    .main-content > .row {
        display: flex;
        flex-direction: column;
    }

    .main-content > .row > .col-lg-6 {
        order: 1;
        flex: 0 0 100%;
        max-width: 100%;
    }

    .main-content aside {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Sidebar card improvements */
    aside .card {
        margin-bottom: 15px;
    }

    aside .card-body {
        padding: 15px;
    }
}

/* ============================================
   FORM MOBILE FIXES
   ============================================ */

@media (max-width: 767.98px) {
    /* Form layouts stack */
    .form-row, .form-inline, .input-group {
        flex-direction: column;
    }

    .form-row > *, .form-inline > * {
        width: 100%;
        margin-bottom: 10px;
    }

    .input-group > * {
        border-radius: 0.25rem !important;
    }

    .input-group .form-control {
        border-right: 1px solid #ced4da !important;
    }

    .input-group-append, .input-group-prepend {
        margin-top: 5px;
    }

    /* Button groups stack */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        border-radius: 0.25rem !important;
        margin-bottom: 5px;
    }

    /* Login form compact */
    .compact-login-form {
        flex-direction: column !important;
    }

    .compact-login-form .form-group {
        width: 100% !important;
        margin-bottom: 10px !important;
    }

    .compact-login-form .form-control-sm {
        width: 100% !important;
    }
}

/* ============================================
   TABLE MOBILE FIXES
   ============================================ */

@media (max-width: 767.98px) {
    /* Responsive tables */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Stack table cells on very small screens */
    .table-stack-mobile thead {
        display: none;
    }

    .table-stack-mobile tbody tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #dee2e6;
        border-radius: 0.25rem;
    }

    .table-stack-mobile tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
        border-bottom: 1px solid #eee;
    }

    .table-stack-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: 10px;
    }
}

/* ============================================
   MODAL MOBILE FIXES
   ============================================ */

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    .modal-content {
        border-radius: 0.5rem;
    }

    .modal-header {
        padding: 15px;
    }

    .modal-body {
        padding: 15px;
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 15px;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 5px 0;
    }
}

/* ============================================
   AI CHATBOT MOBILE FIXES
   ============================================ */

@media (max-width: 480px) {
    .pars-ai-trigger {
        bottom: 20px;
        right: 15px;
    }

    .ai-trigger-btn {
        width: 50px;
        height: 50px;
    }

    .pars-ai-chatbot.floating {
        bottom: 80px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: none;
    }

    .pars-ai-chatbot .chatbot-messages {
        height: 250px;
    }
}

/* ============================================
   ARTICLE CONTENT MOBILE FIXES
   ============================================ */

@media (max-width: 767.98px) {
    .com-content-article {
        padding: 20px 15px;
    }

    .com-content-article__body h2 {
        font-size: 1.35rem;
        margin-top: 25px;
    }

    .com-content-article__body h3 {
        font-size: 1.15rem;
        margin-top: 20px;
    }

    /* Inline styles override for grid layouts */
    [style*="display: grid"], [style*="display:grid"] {
        display: block !important;
    }

    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Flex layouts stack */
    [style*="display: flex"][style*="gap"]:not(.navbar):not(.nav) {
        flex-direction: column !important;
    }
}

/* ============================================
   AUTH BAR MOBILE FIXES
   ============================================ */

@media (max-width: 575.98px) {
    /* Auth bar stacks fully on small screens */
    .pars-auth-bar {
        padding: 4px 0;
    }
    .auth-bar-inner {
        flex-direction: column;
        padding: 4px 0;
        gap: 4px;
    }
    .auth-bar-services {
        width: 100%;
        justify-content: flex-start;
        padding: 0 8px;
        gap: 2px;
    }
    .auth-bar-services .service-link {
        padding: 6px 6px;
        font-size: 10px;
        gap: 3px;
    }
    .auth-bar-services .service-link i {
        font-size: 10px;
    }
    .auth-bar-login {
        width: 100%;
        justify-content: center;
        gap: 6px;
        padding: 4px 8px;
    }
    /* Ensure auth buttons meet 44px touch target on mobile */
    .auth-btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 8px 14px;
    }
}

/* ============================================
   PRINT STYLES - MOBILE FRIENDLY
   ============================================ */

@media print {
    body {
        font-size: 12pt;
        line-height: 1.5;
    }

    .navbar, .pars-navbar, .pars-topbar, .pars-footer,
    .pars-ai-trigger, .pars-ai-chatbot, .modal,
    #pars-dev-banner, .btn, button {
        display: none !important;
    }

    .container, .container-fluid {
        max-width: 100%;
        padding: 0;
    }

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

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

/* Focus indicators */
*:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 99999;
}

.skip-to-content:focus {
    left: 10px;
    top: 10px;
    width: auto;
    height: auto;
    padding: 10px 20px;
    background: #0066cc;
    color: white;
    text-decoration: none;
    border-radius: 4px;
}

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

/* High contrast mode */
@media (prefers-contrast: high) {
    body {
        background: white;
        color: black;
    }

    a {
        color: #0000EE;
        text-decoration: underline;
    }

    button, .btn {
        border: 2px solid black;
    }
}

/* ============================================
   SAFE AREA INSETS (iPhone X+, Notched Devices)
   ============================================ */

@supports (padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .pars-footer {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .pars-ai-trigger {
        bottom: calc(20px + env(safe-area-inset-bottom));
        right: calc(20px + env(safe-area-inset-right));
    }
}

/* ============================================
   LANDSCAPE ORIENTATION FIXES
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .pars-navbar {
        padding: 5px 0;
    }

    .navbar-brand img {
        max-height: 30px;
    }

    .banner, .pars-hero-section {
        padding: 20px 15px !important;
    }

    .modal-body {
        max-height: 50vh;
    }
}

/* ============================================
   DARK MODE SUPPORT (If User Prefers)
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Only apply if site supports dark mode */
    .dark-mode-enabled body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }

    .dark-mode-enabled .card {
        background-color: #2d2d2d;
        border-color: #404040;
    }
}

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

/* Fix for Bootstrap grid on older devices */
@media (max-width: 767.98px) {
    .col-1, .col-2, .col-3, .col-4, .col-5, .col-6,
    .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* Login wrapper mobile */
@media (max-width: 575.98px) {
    .login-wrapper {
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 20px 15px !important;
    }
}

/* Dropdown menu positioning fix */
@media (max-width: 991.98px) {
    .dropdown-menu.show {
        position: static !important;
        transform: none !important;
    }
}

/* Ensure clickable areas don't overlap */
.nav-item, .nav-link, .btn, button, a {
    position: relative;
    z-index: 1;
}

/* Fix z-index stacking for dropdowns */
.dropdown.show {
    z-index: 1001;
}

.dropdown-menu.show {
    z-index: 1002;
}
