/* 
 * Acutus Mobile Responsive Styles
 * Ensures no horizontal scrolling and hamburger menus for all portals
 * Comprehensive mobile support with touch-friendly interfaces
 */

/* ========================================
   CORE RESPONSIVE RULES
   ======================================== */

* {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

/* Prevent any element from causing horizontal scroll */
.container, .row, [class*="col-"] {
    max-width: 100%;
}

/* Mobile viewport meta tag support */
@viewport {
    width: device-width;
}

/* ========================================
   KEYBOARD NAVIGATION FOCUS STYLES
   Focus-visible for keyboard navigation accessibility
   ======================================== */

/* Base focus-visible styles for all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible:not([tabindex="-1"]) {
    outline: 2px solid var(--acutus-primary, #00d4ff);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Navigation items focus styles */
.portal-nav-item:focus-visible,
.expert-nav-item:focus-visible,
.hamburger-nav-item:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible {
    outline: 2px solid var(--acutus-primary, #00d4ff);
    outline-offset: 2px;
    background-color: rgba(0, 212, 255, 0.1);
}

/* Admin navigation focus styles */
.hamburger-nav-item:focus-visible {
    background-color: var(--acutus-gray-100, #f3f4f6);
    outline-color: var(--acutus-primary, #0066FF);
}

/* Button focus styles */
.btn:focus-visible,
.btn-portal-secondary:focus-visible,
.btn-expert-secondary:focus-visible {
    outline: 2px solid var(--acutus-primary, #00d4ff);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 212, 255, 0.2);
}

/* Skip link visibility on focus */
.skip-to-content:focus,
.skip-link:focus {
    position: fixed !important;
    top: 10px;
    left: 10px;
    z-index: 10000;
    padding: 1rem 1.5rem;
    background: var(--acutus-primary, #00d4ff);
    color: #1a1d29;
    font-weight: 600;
    text-decoration: none;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    outline: none;
}

/* Mobile menu toggle focus */
.mobile-toggle:focus-visible,
.hamburger-btn:focus-visible,
.navbar-toggler:focus-visible,
.sidebar-collapse-btn:focus-visible {
    outline: 2px solid var(--acutus-primary, #00d4ff);
    outline-offset: 2px;
}

/* Dropdown toggle focus */
.dropdown-toggle:focus-visible {
    outline: 2px solid var(--acutus-primary, #00d4ff);
    outline-offset: 2px;
}

/* Remove default focus ring for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    a:focus-visible,
    button:focus-visible,
    [role="button"]:focus-visible {
        outline: 3px solid currentColor;
        outline-offset: 3px;
    }
}

/* 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;
    }
}

/* ========================================
   TOUCH TARGET ACCESSIBILITY
   Minimum 44x44px for touch targets per WCAG 2.1
   ======================================== */

@media (pointer: coarse) {
    /* Touch-friendly button sizes */
    .btn, 
    button:not(.navbar-toggler),
    [role="button"],
    .portal-nav-item,
    .expert-nav-item,
    .mobile-nav-menu a,
    .dropdown-item {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
    
    /* Touch-friendly form elements */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    input[type="number"],
    input[type="date"],
    textarea,
    select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }
    
    /* Touch-friendly links in navigation */
    .nav-link,
    .navbar-nav .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    /* Touch-friendly checkboxes and radios */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
    }
    
    /* Touch-friendly table cells with actions */
    .table td .btn,
    .table td a.btn {
        padding: 8px 12px;
        min-height: 36px;
    }
}

/* ========================================
   HAMBURGER MENU COMPONENT
   ======================================== */

.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1050;
    background: #00d4ff;
    border: none;
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
    min-width: 48px;
    min-height: 48px;
}

.hamburger-icon {
    width: 24px;
    height: 20px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hamburger-icon span {
    display: block;
    height: 3px;
    width: 100%;
    background: #1a1d29;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(1) {
    transform: translateY(8.5px) rotate(45deg);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(3) {
    transform: translateY(-8.5px) rotate(-45deg);
}

/* ========================================
   MOBILE NAV OVERLAY (PUBLIC SITE)
   ======================================== */

@media (max-width: 991px) {
    /* Show hamburger menu */
    .mobile-menu-toggle {
        display: block;
    }
    
    /* Hide desktop navigation by default */
    .desktop-nav {
        display: none;
    }
    
    /* Mobile navigation overlay */
    .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(26, 29, 41, 0.95);
        z-index: 1040;
        display: none;
        overflow-y: auto;
        padding: 80px 20px 20px;
    }
    
    .mobile-nav-overlay.active {
        display: block;
    }
    
    .mobile-nav-menu {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    
    .mobile-nav-menu li {
        margin-bottom: 12px;
    }
    
    .mobile-nav-menu a {
        display: block;
        padding: 16px 20px;
        min-height: 52px;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 12px;
        color: #ffffff;
        text-decoration: none;
        font-weight: 600;
        font-size: 1.1rem;
        border-left: 4px solid transparent;
        transition: all 0.2s ease;
    }
    
    .mobile-nav-menu a:hover,
    .mobile-nav-menu a.active {
        background: rgba(0, 212, 255, 0.15);
        border-left-color: #00d4ff;
        transform: translateX(4px);
    }
    
    .mobile-nav-section-title {
        color: #00d4ff;
        font-size: 0.85rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin: 24px 0 12px;
        padding-left: 20px;
    }
}

/* ========================================
   EXPERT & SUBSCRIBER PORTAL MOBILE STYLES
   ======================================== */

/* Tablet Breakpoint (1023px and below) */
@media (max-width: 1023px) {
    /* Portal/Expert sidebar - slide out with overlay */
    .expert-sidebar,
    .portal-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 280px;
        transform: translateX(-100%);
        z-index: 1050;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
    }
    
    .expert-sidebar.open,
    .portal-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }
    
    /* Main content - full width on mobile */
    .expert-main,
    .portal-main {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Show mobile toggle button */
    .mobile-toggle,
    .btn-expert-secondary.mobile-toggle,
    .btn-portal-secondary.mobile-toggle {
        display: flex !important;
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 8px;
        color: #374151;
    }
    
    .mobile-toggle:hover {
        background: rgba(0, 0, 0, 0.1);
    }
    
    /* Overlay backdrop when sidebar is open */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* Medium Breakpoint (768px and below) */
@media (max-width: 768px) {
    /* Portal topbar adjustments */
    .expert-topbar,
    .portal-topbar {
        padding: 0 12px !important;
        height: auto;
        min-height: 56px;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }
    
    .expert-topbar-left,
    .portal-topbar-left {
        flex: 1;
        min-width: 0;
    }
    
    /* Truncate long titles on mobile */
    .expert-topbar-title,
    .portal-topbar-title {
        font-size: 1rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 200px;
    }
    
    .expert-topbar-right,
    .portal-topbar-right {
        gap: 8px;
    }
    
    /* Hide username on mobile, show just avatar */
    .expert-user-menu > span,
    .portal-user-menu > span {
        display: none;
    }
    
    /* Content padding reduction */
    .expert-content,
    .portal-content {
        padding: 12px !important;
    }
    
    /* Card padding reduction */
    .expert-card-body,
    .portal-card-body,
    .card-body {
        padding: 1rem !important;
    }
    
    /* Card header padding */
    .expert-card-header,
    .portal-card-header,
    .card-header {
        padding: 1rem !important;
    }
}

/* Small Phone Breakpoint (480px and below) */
@media (max-width: 480px) {
    /* Extra small device adjustments */
    .expert-topbar-title,
    .portal-topbar-title {
        font-size: 0.9rem !important;
        max-width: 150px;
    }
    
    /* Content padding for very small screens */
    .expert-content,
    .portal-content {
        padding: 8px !important;
    }
    
    /* Topbar badge - smaller on mobile */
    .expert-topbar .badge,
    .portal-topbar .badge {
        font-size: 0.65rem !important;
        padding: 4px 8px !important;
    }
    
    /* Stacked buttons on very small screens */
    .expert-topbar-right .btn,
    .portal-topbar-right .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    /* Switch portal button - icon only on very small screens */
    .portal-topbar-right a[href*="switch-to"] {
        padding: 8px;
    }
    
    .portal-topbar-right a[href*="switch-to"] svg + span,
    .portal-topbar-right a[href*="switch-to"]:not(:has(svg)) {
        display: inline;
    }
}

/* ========================================
   SUBSCRIBER PORTAL MOBILE STYLES
   ======================================== */

@media (max-width: 767px) {
    /* Header adjustments */
    .d-flex.justify-content-between {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 16px;
    }
    
    .d-flex.gap-2 {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .d-flex.gap-2 a {
        flex: 1 1 calc(50% - 8px);
        text-align: center;
    }
    
    /* Search form responsiveness */
    .row.g-3 .col-md-5,
    .row.g-3 .col-md-4,
    .row.g-3 .col-md-3 {
        width: 100% !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    
    /* Brief cards */
    .briefs-list .card {
        margin-bottom: 16px !important;
    }
    
    /* Typography adjustments for mobile */
    h1 {
        font-size: 1.5rem !important;
        line-height: 1.3;
    }
    
    h2 {
        font-size: 1.25rem !important;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.1rem !important;
    }
    
    h4 {
        font-size: 1rem !important;
    }
}

@media (max-width: 575px) {
    /* Extra small devices */
    .container {
        padding-left: 12px;
        padding-right: 12px;
    }
    
    /* Button adjustments */
    .btn {
        font-size: 0.875rem !important;
        padding: 10px 16px !important;
    }
    
    /* Full-width buttons on very small screens */
    .btn-block-mobile {
        width: 100% !important;
        display: block !important;
    }
    
    .badge {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
    }
}

@media (max-width: 480px) {
    /* Ultra small devices (older phones) */
    .container {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    h1 {
        font-size: 1.3rem !important;
    }
    
    h2 {
        font-size: 1.15rem !important;
    }
    
    /* Smaller base font for very small screens */
    body {
        font-size: 14px;
    }
    
    .btn {
        font-size: 0.8rem !important;
        padding: 8px 12px !important;
    }
}

/* ========================================
   ADMIN PORTAL MOBILE STYLES
   ======================================== */

@media (max-width: 991px) {
    /* Admin sidebar - hide by default on mobile */
    .admin-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        transition: transform 0.3s ease;
        z-index: 1045;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
    }
    
    .admin-sidebar.mobile-open {
        transform: translateX(280px);
    }
    
    /* Admin main content - full width on mobile */
    .admin-main {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Admin header adjustments */
    .admin-header {
        padding-left: 70px !important;
    }
    
    /* Admin tables - horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
    }
    
    /* Admin cards */
    .admin-card {
        margin-bottom: 16px !important;
    }
}

@media (max-width: 767px) {
    /* Admin stats grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Admin action buttons */
    .admin-actions {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    
    .admin-actions .btn {
        width: 100% !important;
        margin-bottom: 8px !important;
    }
}

/* ========================================
   EXPERT PORTAL MOBILE STYLES
   ======================================== */

@media (max-width: 767px) {
    /* Expert response form */
    .expert-form .form-group {
        margin-bottom: 20px;
    }
    
    .expert-form textarea {
        min-height: 200px;
    }
    
    /* Expert question cards */
    .question-card {
        padding: 12px !important;
        margin-bottom: 12px !important;
    }
    
    /* Expert navigation */
    .expert-nav {
        flex-direction: column;
        gap: 12px;
    }
    
    /* Navigation items - touch friendly */
    .expert-nav-item,
    .portal-nav-item {
        padding: 14px 16px !important;
        min-height: 48px;
    }
}

/* ========================================
   TABLE RESPONSIVENESS
   ======================================== */

/* Table wrapper for horizontal scrolling */
.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

.table-responsive-wrapper table {
    width: 100%;
    min-width: 600px;
}

@media (max-width: 991px) {
    /* Make all tables scrollable on mobile */
    table:not(.table-auto) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Ensure proper table structure */
    table:not(.table-auto) thead,
    table:not(.table-auto) tbody {
        display: table;
        width: 100%;
    }
    
    table:not(.table-auto) tr {
        display: table-row;
    }
    
    th, td {
        padding: 12px 8px !important;
        font-size: 0.875rem;
        white-space: nowrap;
    }
    
    /* Allow text wrap for description columns */
    td.text-wrap,
    th.text-wrap {
        white-space: normal !important;
        min-width: 200px;
    }
}

@media (max-width: 767px) {
    th, td {
        padding: 10px 6px !important;
        font-size: 0.8rem;
    }
}

/* Mobile card view for tables */
.admin-table-mobile-card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
}

.admin-table-mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
}

.admin-table-mobile-card-row:last-child {
    border-bottom: none;
}

.admin-table-mobile-card-label {
    font-weight: 600;
    color: #4b5563;  /* WCAG AA compliant (7:1 ratio on white) */
    font-size: 0.85rem;
}

.admin-table-mobile-card-value {
    color: #111827;
    font-size: 0.9rem;
    text-align: right;
}

/* ========================================
   FORM RESPONSIVENESS
   ======================================== */

@media (max-width: 767px) {
    /* Stack form groups vertically */
    .form-row,
    .row.g-3 {
        flex-direction: column;
    }
    
    .form-row > [class*="col-"],
    .row.g-3 > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin-bottom: 12px;
    }
    
    /* Form labels */
    .form-label,
    label {
        font-size: 0.875rem;
        margin-bottom: 6px;
    }
    
    /* Form inputs */
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
        border-radius: 8px;
    }
    
    /* Form groups spacing */
    .form-group,
    .mb-3 {
        margin-bottom: 16px !important;
    }
}

/* ========================================
   MODAL & DIALOG RESPONSIVENESS
   ======================================== */

@media (max-width: 767px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 12px;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 16px;
    }
    
    .modal-footer {
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0 !important;
    }
}

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

.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 991px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
}

@media (max-width: 767px) {
    .tablet-hide {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .phone-hide {
        display: none !important;
    }
}

/* Prevent text overflow */
.text-truncate-mobile {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 767px) {
    .text-truncate-mobile {
        max-width: 100%;
    }
}

/* Mobile text alignment */
@media (max-width: 767px) {
    .text-center-mobile {
        text-align: center !important;
    }
    
    .text-start-mobile {
        text-align: left !important;
    }
}

/* ========================================
   BOOTSTRAP OVERRIDE FOR NO SCROLL
   ======================================== */

@media (max-width: 767px) {
    .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
    .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12,
    .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6,
    .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* Responsive images */
img {
    max-width: 100%;
    height: auto;
}

/* Responsive iframes (embeds) */
iframe {
    max-width: 100%;
}

/* ========================================
   FLEX GAP MOBILE ADJUSTMENTS
   ======================================== */

@media (max-width: 767px) {
    .gap-4 {
        gap: 1rem !important;
    }
    
    .gap-3 {
        gap: 0.75rem !important;
    }
    
    .g-4 {
        --bs-gutter-x: 1rem !important;
        --bs-gutter-y: 1rem !important;
    }
}

/* ========================================
   NAVBAR MOBILE IMPROVEMENTS
   ======================================== */

@media (max-width: 991px) {
    .navbar-collapse {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: linear-gradient(135deg, #1a1d29 0%, #2d3142 100%);
        padding: 20px;
        border-top: 1px solid rgba(0, 212, 255, 0.1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }
    
    .navbar-nav {
        gap: 0;
    }
    
    .navbar-nav .nav-link {
        padding: 14px 16px !important;
        border-radius: 8px;
        margin-bottom: 4px;
    }
    
    .navbar-nav .nav-link:hover {
        background: rgba(255, 255, 255, 0.05);
    }
    
    .navbar-toggler {
        min-width: 44px;
        min-height: 44px;
        padding: 8px;
    }
    
    .navbar-nav .btn {
        width: 100%;
        margin-top: 12px;
        margin-left: 0 !important;
    }
}

/* ========================================
   FOOTER MOBILE STYLES
   ======================================== */

@media (max-width: 767px) {
    footer .row {
        text-align: center;
    }
    
    footer .col-lg-4 {
        margin-bottom: 32px;
    }
    
    footer .text-lg-end {
        text-align: center !important;
    }
    
    footer nav h2 {
        margin-top: 24px;
    }
    
    footer ul {
        margin-bottom: 16px;
    }
}

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

@media print {
    .mobile-menu-toggle,
    .mobile-toggle,
    .sidebar-collapse-btn,
    .portal-sidebar,
    .expert-sidebar,
    .admin-sidebar {
        display: none !important;
    }
    
    .portal-main,
    .expert-main,
    .admin-main {
        margin-left: 0 !important;
    }
}
