/* Mobile-First Responsive Design for DebtSettle.ai App */

/* iPad and Tablet Dropdown Menu Fix */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Force container to respect viewport */
    .container {
        max-width: 100% !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
    
    /* Ensure dropdown menu stays within viewport on iPads */
    .navbar-nav .dropdown-menu {
        position: absolute !important;
        right: 0 !important;
        left: auto !important;
        transform: translateX(0) !important;
        margin-top: 0.5rem !important;
        min-width: 200px !important;
        max-width: 250px !important;
        width: auto !important;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
        border: 1px solid var(--bs-border-color) !important;
        border-radius: 8px !important;
        overflow: hidden !important;
        z-index: 1050 !important;
    }
    
    /* Force dropdown to stay within screen bounds */
    .navbar-nav .nav-item.dropdown {
        position: relative !important;
    }
    
    /* Specific targeting for user dropdown */
    .navbar-nav .nav-item.dropdown:last-child .dropdown-menu {
        right: 0 !important;
        left: auto !important;
        transform: translateX(-5px) !important;
        margin-right: 0 !important;
    }
    
    .navbar-nav .dropdown-item {
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    /* Ensure proper spacing for dropdown toggle */
    .navbar-nav .dropdown-toggle::after {
        margin-left: 0.5rem !important;
    }
    
    /* Prevent navbar from collapsing on iPad landscape */
    .navbar-expand-lg {
        flex-wrap: nowrap !important;
    }
    
    .navbar-expand-lg .navbar-nav {
        flex-direction: row !important;
        padding: 0 !important;
    }
    
    .navbar-expand-lg .navbar-nav .nav-link {
        padding: 0.5rem 0.6rem !important;
        border-bottom: none !important;
        font-size: 0.85rem !important;
    }
    
    /* Ensure the navbar doesn't overflow */
    .navbar {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
}

/* Additional aggressive iPad dropdown fixes */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Force dropdown to appear fully within viewport */
    .navbar-nav .dropdown-menu.show {
        right: 0 !important;
        left: auto !important;
        transform: translateX(-15px) !important;
        max-width: 230px !important;
        width: 230px !important;
        margin-right: 10px !important;
    }
    
    /* Override Bootstrap's default positioning */
    .navbar-nav .nav-item.dropdown .dropdown-menu {
        inset: auto 0px auto auto !important;
    }
    
    /* Ensure container allows for dropdown overflow */
    .navbar > .container {
        overflow-x: visible !important;
        position: relative !important;
    }
    
    /* Force right-align for last dropdown */
    .navbar-nav .nav-item:last-child .dropdown-menu {
        right: 0 !important;
        left: auto !important;
    }
}

/* Mobile Navigation Improvements - Exclude iPad range */
@media (max-width: 767px) {
    .navbar-nav {
        padding: 1rem 0;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem !important;
        font-size: 1.1rem;
        border-bottom: 1px solid var(--bs-border-color);
    }
    
    .navbar-nav .nav-link:last-child {
        border-bottom: none;
    }
    
    .navbar-brand {
        font-size: 1.5rem !important;
    }
    
    /* Dropdown menu fixes for collapsed navbar */
    .navbar-nav .dropdown-menu {
        position: static !important;
        float: none !important;
        width: auto !important;
        margin-top: 0 !important;
        background-color: transparent !important;
        border: 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding-left: 1rem !important;
    }
    
    .navbar-nav .dropdown-item {
        padding: 0.5rem 1rem !important;
        color: rgba(255, 255, 255, 0.75) !important;
        background-color: transparent !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
    
    .navbar-nav .dropdown-item:hover {
        color: rgba(255, 255, 255, 0.9) !important;
        background-color: rgba(255, 255, 255, 0.1) !important;
    }
}

/* Mobile Card Layouts */
.mobile-card {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mobile-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.mobile-card-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.mobile-card-body {
    padding: 1.25rem;
}

/* Mobile Form Improvements */
@media (max-width: 767.98px) {
    .form-control {
        padding: 0.75rem;
        font-size: 1rem;
        min-height: 48px; /* Touch-friendly minimum */
    }
    
    .btn {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        min-height: 48px;
    }
    
    .btn-sm {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-height: 40px;
    }
    
    /* Stack form buttons on mobile */
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        margin-bottom: 0.5rem;
        border-radius: 0.375rem !important;
    }
    
    .btn-group .btn:last-child {
        margin-bottom: 0;
    }
}

/* Mobile Table Alternatives */
@media (max-width: 991.98px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Hide complex tables on mobile, show card alternatives */
    .mobile-hide {
        display: none !important;
    }
    
    .mobile-show {
        display: block !important;
    }
}

/* Mobile-Specific Spacing */
@media (max-width: 767.98px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    .col, .col-12, .col-sm-12, .col-md-12, .col-lg-12, .col-xl-12 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    /* Increase spacing between sections */
    .mb-3 {
        margin-bottom: 2rem !important;
    }
    
    .mb-4 {
        margin-bottom: 2.5rem !important;
    }
}

/* Debt Tracker Mobile Responsive */
@media (max-width: 991.98px) {
    /* Progress Overview Cards */
    .dashboard-card .card-body {
        padding: 1.5rem;
    }
    
    .dashboard-stat {
        font-size: 1.5rem;
        font-weight: 700;
        line-height: 1.1;
        word-break: break-all;
    }
    
    /* Settlement Cards Mobile Layout */
    .mobile-card {
        border-radius: 0.75rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.02);
        backdrop-filter: blur(10px);
    }
    
    .mobile-card-body {
        padding: 1.25rem;
    }
    
    .mobile-card .card-title {
        font-size: 1.1rem;
        color: inherit;
        margin-bottom: 0.5rem;
    }
    
    /* Settlement Balance Display */
    .mobile-card .h5 {
        font-size: 1.3rem;
        font-weight: 700;
    }
    
    .mobile-card .border-end {
        border-right: 1px solid rgba(255, 255, 255, 0.15) !important;
    }
    
    /* Progress Bars for Mobile */
    .progress-mobile {
        height: 8px;
        border-radius: 4px;
    }
    
    /* Action Button Styling */
    .mobile-card .btn-sm {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
        border-radius: 0.5rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .mobile-card .btn-group {
        width: 100%;
        gap: 0.5rem;
    }
    
    /* Settlement Status Badges */
    .mobile-card .badge {
        font-size: 0.75rem;
        padding: 0.4em 0.7em;
        border-radius: 0.5rem;
    }
    
    /* Settlement Terms Layout */
    .mobile-card .d-flex.justify-content-between {
        margin-bottom: 0.5rem;
        padding: 0.25rem 0;
    }
    
    .mobile-card .d-flex.justify-content-between:last-child {
        margin-bottom: 0;
    }
    
    /* Small text adjustments */
    .mobile-card small {
        font-size: 0.8rem;
        line-height: 1.3;
    }
    
    .mobile-card .fw-semibold {
        font-weight: 600;
        color: var(--bs-emphasis-color);
    }
}

/* Extra small devices */
@media (max-width: 575.98px) {
    .mobile-card-body {
        padding: 1rem;
    }
    
    .mobile-card .card-title {
        font-size: 1rem;
    }
    
    .mobile-card .h5 {
        font-size: 1.2rem;
    }
    
    .dashboard-stat {
        font-size: 1.3rem;
        line-height: 1.2;
    }
}

/* Dashboard Cards Mobile Optimization */
@media (max-width: 767.98px) {
    .dashboard-card .card-body {
        padding: 1rem 0.75rem;
    }
    
    .dashboard-card .dashboard-stat {
        font-size: 1.4rem;
        line-height: 1.1;
        margin-bottom: 0.25rem;
        word-break: break-all;
    }
    
    .dashboard-card small {
        font-size: 0.75rem;
        line-height: 1.2;
    }
}

/* Mobile Typography Improvements */
@media (max-width: 767.98px) {
    h1 {
        font-size: 1.75rem;
        line-height: 1.3;
    }
    
    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.25rem;
        line-height: 1.4;
    }
    
    h4 {
        font-size: 1.1rem;
        line-height: 1.4;
    }
    
    .h1, .h2, .h3, .h4 {
        font-weight: 600;
    }
    
    /* Improve readability */
    p, .card-text {
        line-height: 1.6;
    }
    
    small, .small {
        font-size: 0.875rem;
    }
}

/* Mobile Dashboard Cards */
@media (max-width: 991.98px) {
    .dashboard-card {
        margin-bottom: 1.5rem;
        padding: 1.5rem;
        text-align: center;
    }
    
    .dashboard-card .card-title {
        font-size: 1.1rem;
        font-weight: 600;
        margin-bottom: 1rem;
    }
    
    .dashboard-stat {
        font-size: 2rem;
        font-weight: 700;
        line-height: 1.2;
        margin-bottom: 0.5rem;
    }
    
    .dashboard-label {
        font-size: 0.9rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        opacity: 0.8;
    }
}

/* Mobile Modal Improvements */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 12px;
    }
    
    .modal-header {
        padding: 1.5rem;
        border-bottom: 1px solid var(--bs-border-color);
    }
    
    .modal-body {
        padding: 1.5rem;
    }
    
    .modal-footer {
        padding: 1.5rem;
        border-top: 1px solid var(--bs-border-color);
    }
    
    .modal-footer .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }
}

/* Mobile Alert Improvements */
@media (max-width: 767.98px) {
    .alert {
        padding: 1rem;
        margin-bottom: 1.5rem;
        border-radius: 8px;
        font-size: 0.95rem;
        line-height: 1.5;
    }
    
    .alert-dismissible .btn-close {
        padding: 1rem;
    }
}

/* Mobile Badge and Status Improvements */
@media (max-width: 767.98px) {
    .badge {
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
        font-weight: 500;
    }
    
    .badge.fs-6 {
        font-size: 0.9rem !important;
        padding: 0.6rem 1rem;
    }
}

/* Mobile Progress Indicators */
@media (max-width: 767.98px) {
    .progress {
        height: 12px;
        border-radius: 6px;
        margin-bottom: 1rem;
    }
    
    .progress-bar {
        font-size: 0.75rem;
        line-height: 12px;
    }
}

/* Mobile Dropdown Improvements */
@media (max-width: 767.98px) {
    .dropdown-menu {
        border-radius: 8px;
        box-shadow: 0 4px 16px rgba(0,0,0,0.15);
        border: 1px solid var(--bs-border-color);
    }
    
    .dropdown-item {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
    
    .dropdown-item:hover {
        background-color: var(--bs-light);
    }
}

/* Mobile List Group Improvements */
@media (max-width: 767.98px) {
    .list-group-item {
        padding: 1rem;
        border-radius: 8px !important;
        margin-bottom: 0.5rem;
        border: 1px solid var(--bs-border-color) !important;
    }
    
    .list-group-item:last-child {
        margin-bottom: 0;
    }
}

/* Mobile Accordion Improvements */
@media (max-width: 767.98px) {
    .accordion-item {
        border-radius: 8px !important;
        margin-bottom: 0.5rem;
        border: 1px solid var(--bs-border-color) !important;
    }
    
    .accordion-button {
        padding: 1rem;
        font-size: 1rem;
        font-weight: 500;
    }
    
    .accordion-body {
        padding: 1rem;
    }
}

/* Mobile Tab Improvements */
@media (max-width: 767.98px) {
    .nav-tabs {
        border-bottom: none;
        margin-bottom: 1rem;
    }
    
    .nav-tabs .nav-link {
        padding: 0.75rem 1rem;
        margin-bottom: 0.25rem;
        border-radius: 8px;
        border: 1px solid var(--bs-border-color);
        background-color: var(--bs-body-bg);
    }
    
    .nav-tabs .nav-link.active {
        background-color: var(--bs-primary);
        color: white;
        border-color: var(--bs-primary);
    }
}

/* Mobile Utility Classes */
@media (max-width: 767.98px) {
    .mobile-text-center {
        text-align: center !important;
    }
    
    .mobile-w-100 {
        width: 100% !important;
    }
    
    .mobile-mb-3 {
        margin-bottom: 1.5rem !important;
    }
    
    .mobile-p-3 {
        padding: 1.5rem !important;
    }
    
    .mobile-rounded {
        border-radius: 12px !important;
    }
}

/* Touch-friendly interactions */
@media (max-width: 767.98px) {
    /* Larger tap targets */
    .btn, .form-control, .dropdown-toggle, .nav-link, .page-link {
        min-height: 44px;
    }
    
    /* Prevent text selection on touch */
    .btn, .dropdown-item, .nav-link, .page-link {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* Smooth scrolling */
    html {
        scroll-behavior: smooth;
    }
    
    /* Prevent zoom on form focus (iOS) */
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .card, .mobile-card {
        border-width: 2px;
    }
    
    .btn {
        border-width: 2px;
    }
    
    .badge {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .mobile-card, .btn, * {
        transition: none !important;
        animation: none !important;
    }
}