/* ===========================
   Comprehensive Responsive Fixes
   =========================== */

/* ===== BASE RESPONSIVE RULES ===== */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Reduce space between navbar and content on mobile */
@media (max-width: 768px) {
    body {
        padding-top: 56px !important;
    }
    
    main.container {
        padding-top: 0.25rem !important;
    }
    
    /* Reduce breadcrumb margin on mobile */
    .modern-breadcrumb:first-child {
        margin-top: 0.25rem !important;
    }
}

@media (max-width: 575px) {
    body {
        padding-top: 52px !important;
    }
    
    main.container {
        padding-top: 0.125rem !important;
    }
    
    .modern-breadcrumb:first-child {
        margin-top: 0.125rem !important;
    }
}

/* ===== CONTAINER FIXES ===== */
@media (max-width: 575px) {
    .container,
    .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    /* Prevent horizontal scroll */
    .row {
        margin-left: -10px;
        margin-right: -10px;
    }
    
    .row > * {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* ===== TABLE RESPONSIVE FIXES ===== */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: -ms-autohiding-scrollbar;
}

/* Prevent table from breaking layout */
.table-responsive > .table {
    margin-bottom: 0;
    min-width: 600px; /* Minimum width to prevent cramping */
}

/* Provider comparison table specific */
@media (max-width: 767px) {
    .provider-comparison-table {
        font-size: 0.75rem;
    }
    
    .provider-comparison-table th,
    .provider-comparison-table td {
        padding: 0.375rem 0.25rem;
        white-space: nowrap;
    }
    
    /* Hide less important columns */
    .provider-comparison-table .hide-mobile {
        display: none;
    }
}

/* ===== CARD RESPONSIVE FIXES ===== */
@media (max-width: 575px) {
    .card {
        border-radius: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    /* Modern price cards */
    .modern-price-card {
        min-width: unset;
        width: 100%;
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }
    
    .modern-price-card .price-value {
        font-size: 1.1rem;
    }
    
    .modern-price-card .asset-name {
        font-size: 0.95rem;
    }
    
    .modern-price-card .asset-symbol {
        font-size: 0.8rem;
    }
}

/* ===== FORM RESPONSIVE FIXES ===== */
@media (max-width: 575px) {
    /* Prevent zoom on iOS */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    .form-control,
    .form-select {
        font-size: 16px !important;
        padding: 0.5rem 0.75rem;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 1rem;
        min-height: 44px;
    }
    
    .btn-sm {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
        min-height: 40px;
    }
}

/* ===== NAVBAR RESPONSIVE FIXES ===== */
@media (max-width: 991px) {
    .navbar-collapse {
        max-height: calc(100vh - 80px);
        overflow-y: auto;
    }
    
    .navbar .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        margin-top: 0.125rem;
        background-color: rgba(248, 249, 250, 0.95);
    }
    
    .navbar .mega-menu {
        position: relative !important;
        width: 100% !important;
        left: auto !important;
        transform: none !important;
        box-shadow: none;
        border: none;
        padding: 1rem;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }
}

@media (max-width: 575px) {
    .navbar-brand {
        font-size: 1.25rem;
    }
    
    /* Logo height managed by navbar-simple.css */
    
    /* Search input */
    .navbar .search-input {
        width: 100% !important;
        max-width: none !important;
    }
}

/* ===== MODAL RESPONSIVE FIXES ===== */
@media (max-width: 575px) {
    .modal-dialog {
        margin: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
    }
    
    .modal-content {
        height: 100%;
        border-radius: 0;
    }
    
    .modal-body {
        overflow-y: auto;
        max-height: calc(100vh - 120px);
    }
    
    .modal.fade .modal-dialog {
        transform: translateX(100%);
        transition: transform 0.3s ease-out;
    }
    
    .modal.show .modal-dialog {
        transform: translateX(0);
    }
}

/* ===== DROPDOWN RESPONSIVE FIXES ===== */
@media (max-width: 575px) {
    .dropdown-menu {
        width: 100%;
        border-radius: 0.5rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
    
    /* Notification dropdown */
    .notifications-dropdown {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: 60px !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100vh - 60px);
        border-radius: 0;
        transform: none !important;
    }
}

/* ===== TOOLTIP & POPOVER FIXES ===== */
@media (max-width: 767px) {
    .tooltip {
        font-size: 0.875rem;
    }
    
    .popover {
        max-width: 276px;
    }
}

/* ===== IMAGE RESPONSIVE FIXES ===== */
img {
    max-width: 100%;
}

.img-fluid {
    max-width: 100%;
    height: auto;
}

/* ===== ADSENSE RESPONSIVE FIXES ===== */
@media (max-width: 767px) {
    ins.adsbygoogle {
        width: 100% !important;
        max-width: 100vw !important;
        overflow: hidden !important;
    }
    
    .adsense-zone {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
        padding: 0 10px;
    }
}

/* ===== CHART RESPONSIVE FIXES ===== */
@media (max-width: 767px) {
    #priceChart,
    .chart-container {
        height: 300px !important;
        margin-top: 1rem;
    }
    
    .chart-period-selector {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }
    
    .chart-period-selector button {
        display: inline-block;
        margin-right: 0.5rem;
    }
}

/* ===== BADGE & PILL RESPONSIVE ===== */
@media (max-width: 575px) {
    .badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    
    .badge-pill {
        padding-right: 0.6rem;
        padding-left: 0.6rem;
    }
}

/* ===== UTILITY CLASSES FOR RESPONSIVE ===== */
/* Text truncation */
@media (max-width: 767px) {
    .text-truncate-mobile {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 200px;
    }
}

@media (max-width: 575px) {
    .text-truncate-mobile {
        max-width: 150px;
    }
}

/* Hide scrollbars but keep functionality */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Responsive spacing */
@media (max-width: 575px) {
    .py-sm-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
    .px-sm-2 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
    .my-sm-2 { margin-top: 0.5rem !important; margin-bottom: 0.5rem !important; }
    .mx-sm-2 { margin-left: 0.5rem !important; margin-right: 0.5rem !important; }
}

/* ===== BREADCRUMB RESPONSIVE ===== */
@media (max-width: 768px) {
    .modern-breadcrumb {
        padding: 0.875rem 1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .breadcrumb {
        font-size: 0.95rem;
        padding: 0.5rem 0;
        margin-bottom: 0;
    }
    
    .breadcrumb-item {
        line-height: 1.5;
    }
    
    .breadcrumb-item a {
        padding: 0.25rem 0.375rem;
        margin: -0.25rem -0.375rem;
        display: inline-block;
        text-decoration: none;
        border-radius: 0.25rem;
        transition: background-color 0.2s;
    }
    
    .breadcrumb-item a:active {
        background-color: rgba(255, 183, 0, 0.1);
    }
    
    .breadcrumb-item + .breadcrumb-item {
        padding-left: 0.4rem;
    }
    
    .breadcrumb-item + .breadcrumb-item::before {
        padding-right: 0.4rem;
        font-size: 1.1rem;
    }
    
    .breadcrumb-item i {
        font-size: 0.9rem;
    }
}

@media (max-width: 575px) {
    .modern-breadcrumb {
        padding: 0.75rem 0.875rem !important;
        border-radius: 0.5rem !important;
    }
    
    .breadcrumb {
        font-size: 0.9rem;
        padding: 0.375rem 0;
    }
    
    .breadcrumb-item a {
        padding: 0.375rem 0.5rem;
        margin: -0.375rem -0.5rem;
        font-weight: 500;
    }
    
    .breadcrumb-item + .breadcrumb-item {
        padding-left: 0.35rem;
    }
    
    .breadcrumb-item + .breadcrumb-item::before {
        padding-right: 0.35rem;
    }
    
    /* Active item bold */
    .breadcrumb-item.active {
        font-weight: 600;
    }
}

@media (max-width: 400px) {
    .breadcrumb {
        font-size: 0.85rem;
    }
    
    .breadcrumb-item + .breadcrumb-item {
        padding-left: 0.3rem;
    }
    
    .breadcrumb-item + .breadcrumb-item::before {
        padding-right: 0.3rem;
        content: "›";
    }
    
    /* Hide home icon on very small screens to save space */
    .breadcrumb-item:first-child i {
        display: none;
    }
}

/* ===== TAB RESPONSIVE FIXES ===== */
@media (max-width: 767px) {
    .nav-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .nav-tabs .nav-link {
        white-space: nowrap;
        padding: 0.5rem 1rem;
    }
}

/* ===== PAGINATION RESPONSIVE ===== */
@media (max-width: 575px) {
    .pagination {
        font-size: 0.875rem;
    }
    
    .page-link {
        padding: 0.375rem 0.5rem;
    }
    
    /* Hide some page numbers on mobile */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child):nth-child(n+4):nth-last-child(n+4) {
        display: none;
    }
}

/* ===== ALERT RESPONSIVE ===== */
@media (max-width: 575px) {
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        border-radius: 0.5rem;
    }
    
    .alert .btn-close {
        padding: 0.5rem;
    }
}

/* ===== FOOTER RESPONSIVE ===== */
@media (max-width: 767px) {
    footer {
        padding: 2rem 0 1rem;
    }
    
    footer .row > div {
        margin-bottom: 2rem;
    }
    
    footer h5 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }
    
    footer ul li {
        margin-bottom: 0.5rem;
    }
}

/* ===== LANDSCAPE ORIENTATION FIXES ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .navbar {
        padding: 0.25rem 0;
    }
    
    .modal-body {
        max-height: calc(100vh - 100px);
    }
    
    .sticky-top {
        position: relative !important;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .navbar,
    .sidebar,
    .btn,
    .dropdown,
    .modal,
    .toast,
    .adsense-zone,
    .floating-action-btn,
    footer {
        display: none !important;
    }
    
    .container {
        width: 100%;
        max-width: none;
    }
    
    .table-responsive {
        overflow: visible;
    }
    
    .table {
        font-size: 10pt;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--bs-primary);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

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

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
/* Reduce animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== SPECIFIC COMPONENT FIXES ===== */
/* Section Headers responsive */
@media (max-width: 575px) {
    .section-header .d-flex {
        gap: 0.5rem !important;
    }
    
    .section-header .btn-link {
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .section-title {
        flex-shrink: 1;
        min-width: 0;
    }
}

/* Price ticker responsive */
@media (max-width: 575px) {
    .price-ticker {
        font-size: 0.875rem;
    }
    
    .price-ticker .ticker-item {
        padding: 0.5rem;
    }
}

/* Asset grid responsive */
@media (max-width: 767px) {
    .asset-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }
}

/* Comments section responsive */
@media (max-width: 575px) {
    .comment-item {
        padding: 0.75rem;
    }
    
    .comment-avatar {
        width: 32px;
        height: 32px;
    }
    
    .comment-content {
        font-size: 0.875rem;
    }
}

/* Calculator widget responsive */
@media (max-width: 575px) {
    .calculator-widget {
        padding: 1rem;
    }
    
    .calculator-input {
        font-size: 16px !important;
    }
}

/* Social tabs responsive */
@media (max-width: 767px) {
    .social-tabs .nav-tabs {
        border-bottom: none;
        background: #f8f9fa;
        padding: 0.5rem;
        border-radius: 0.5rem;
    }
    
    .social-tabs .nav-link {
        border-radius: 0.375rem;
        margin: 0 0.25rem;
    }
}