/* Responsive and Accessibility Enhancements for RTP Application */

/* Fix for Bootstrap collapse conflict */
.navbar-vertical .navbar-collapse {
    display: block !important;
    height: auto !important;
}

.navbar-vertical-content {
    display: block !important;
    padding: 1rem;
}

/* Ensure sidebar has proper background and visibility */
.navbar-vertical {
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0,0,0,0.05);
}

/* Dark mode support */
[data-phoenix-theme="dark"] .navbar-vertical {
    background-color: #1e1e1e;
    border-right-color: rgba(255,255,255,0.1);
}

/* Ensure content area is properly displayed */
.content {
    position: relative;
    min-height: 100vh;
    background-color: #f8f9fa;
}

/* Fix main layout structure */
.main {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Desktop layout fix */
@media (min-width: 992px) {
    .main {
        display: block;
        position: relative;
    }
    
    .navbar-top {
        position: fixed;
        top: 0;
        left: 240px;
        right: 0;
        z-index: 1020;
        width: auto;
        height: auto;
    }
    
    /* Ensure content starts below the navbar */
    .content {
        padding-top: 56px; /* Height of navbar */
    }
}

@media (min-width: 1200px) {
    .navbar-top {
        left: 270px;
    }
}

/* Base responsive utilities */
@media (max-width: 576px) {
    /* Mobile first approach */
    .container, .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    /* Stack form elements on mobile */
    .row.flex-between-center {
        flex-direction: column;
    }
    
    /* Responsive tables */
    .table-responsive table {
        font-size: 0.875rem;
    }
    
    .table td, .table th {
        padding: 0.5rem;
    }
    
    /* Make forms more touch-friendly */
    .form-control, .form-select, .btn {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Responsive modals */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-lg {
        max-width: 100%;
    }
    
    /* Navigation adjustments */
    .navbar-vertical {
        position: fixed !important;
        z-index: 1040;
        width: 250px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        top: 0;
        left: 0;
        height: 100vh;
        background-color: var(--phoenix-body-bg, #fff);
        overflow-y: auto;
        border-right: 1px solid rgba(0,0,0,0.1);
    }
    
    .navbar-vertical.show {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
    }
    
    /* Content adjustments when sidebar is hidden */
    .content {
        margin-left: 0 !important;
        padding: 1rem;
        padding-top: 60px; /* Account for fixed top navbar */
        width: 100%;
    }
    
    /* Card and section spacing */
    .card {
        margin-bottom: 1rem;
    }
    
    .p-5 {
        padding: 1.5rem !important;
    }
    
    /* Hide non-essential columns in tables */
    .table .d-none-mobile {
        display: none;
    }
    
    /* Stack payment form elements */
    .auto-pay-form .row {
        margin-bottom: 1rem;
    }
    
    .auto-pay-form .col-md-2,
    .auto-pay-form .col-md-4,
    .auto-pay-form .col-md-6 {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Responsive unit selector */
    #unitSelector {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Tab navigation */
    .nav-tabs {
        flex-wrap: wrap;
    }
    
    .nav-tabs .nav-link {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Button groups */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Footer adjustments */
    .footer {
        position: relative;
        padding: 1rem;
    }
}

@media (min-width: 577px) and (max-width: 991px) {
    /* Tablet styles */
    .container {
        max-width: 720px;
    }
    
    /* Hide sidebar by default on tablets */
    .navbar-vertical {
        position: fixed !important;
        z-index: 1040;
        width: 250px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        top: 0;
        left: 0;
        height: 100vh;
        background-color: var(--phoenix-body-bg, #fff);
        overflow-y: auto;
        border-right: 1px solid rgba(0,0,0,0.1);
    }
    
    .navbar-vertical.show {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
    }
    
    .content {
        margin-left: 0 !important;
        padding-top: 60px; /* Account for fixed top navbar */
        width: 100%;
    }
    
    /* Adjust column widths for tablets */
    .col-md-2 {
        flex: 0 0 33.333333%;
        max-width: 33.333333%;
    }
    
    .col-md-4 {
        flex: 0 0 66.666667%;
        max-width: 66.666667%;
    }
}

@media (min-width: 992px) and (max-width: 1199px) {
    /* Small desktop styles */
    .container {
        max-width: 960px;
    }
    
    .navbar-vertical {
        width: 240px;
        position: fixed !important;
        transform: none !important;
        height: 100vh;
        border-right: 1px solid rgba(0,0,0,0.1);
        top: 0;
        left: 0;
        z-index: 1030;
    }
    
    .content {
        margin-left: 240px;
        width: calc(100% - 240px);
        padding-top: 0;
    }
    
    /* Hide toggle button on larger screens */
    #sidebarToggler {
        display: none !important;
    }
}

@media (min-width: 1200px) {
    /* Large desktop styles */
    .navbar-vertical {
        position: fixed !important;
        transform: none !important;
        width: 270px;
        height: 100vh;
        border-right: 1px solid rgba(0,0,0,0.1);
        top: 0;
        left: 0;
        z-index: 1030;
    }
    
    .content {
        margin-left: 270px;
        width: calc(100% - 270px);
        padding-top: 0;
        position: relative;
    }
    
    /* Hide toggle button on larger screens */
    #sidebarToggler {
        display: none !important;
    }
}

/* Sidebar overlay for mobile/tablet */
@media (max-width: 991px) {
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1039;
        display: none;
        cursor: pointer;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
    
    /* Ensure hamburger menu is visible */
    #sidebarToggler {
        display: inline-block !important;
        padding: 0.5rem;
        font-size: 1.25rem;
        background-color: transparent;
        border: 1px solid rgba(0, 0, 0, 0.1);
        cursor: pointer;
        z-index: 1041;
    }
    
    .navbar-toggler:hover,
    .navbar-toggler:focus {
        background-color: rgba(0, 0, 0, 0.05);
    }
    
    /* Fixed top navbar on mobile/tablet */
    .navbar-top {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1038;
        background-color: var(--phoenix-navbar-bg, #fff);
    }
    
    /* Adjust content padding */
    .content {
        padding-top: 70px;
    }
}

/* Accessibility Enhancements */

/* Focus styles for better keyboard navigation */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

/* Skip to content link for screen readers */
.skip-to-content {
    position: absolute;
    left: -9999px;
    z-index: 9999;
    padding: 1em;
    background-color: #000;
    color: #fff;
    text-decoration: none;
}

.skip-to-content:focus {
    left: 50%;
    transform: translateX(-50%);
    top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-primary {
        border: 2px solid;
    }
    
    .form-control,
    .form-select {
        border-width: 2px;
    }
    
    .alert {
        border: 2px solid;
    }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Ensure interactive elements are large enough for touch */
.btn,
.form-control,
.form-select,
.nav-link {
    min-width: 44px;
    min-height: 44px;
    line-height: 1.5;
}

/* Improve form label visibility */
.form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #333;
}

/* Dark mode accessibility */
@media (prefers-color-scheme: dark) {
    .form-label {
        color: #e0e0e0;
    }
    
    .table {
        color: #e0e0e0;
    }
}

/* Touch-friendly spacing for mobile */
@media (pointer: coarse) {
    .btn {
        padding: 0.75rem 1.5rem;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
    }
    
    .dropdown-item {
        padding: 0.75rem 1.25rem;
    }
}

/* Responsive text sizing */
@media (max-width: 576px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }
    
    .display-1 { font-size: 3rem; }
    .display-2 { font-size: 2.5rem; }
    .display-3 { font-size: 2rem; }
    .display-4 { font-size: 1.5rem; }
}

/* Ensure proper contrast ratios */
.text-body-tertiary {
    color: #6c757d !important;
}

.alert-warning {
    background-color: #fff3cd;
    color: #856404;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
}

/* Responsive navigation toggle */
.navbar-toggler {
    padding: 0.5rem;
    font-size: 1.25rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background-color: transparent;
    cursor: pointer;
}

.navbar-toggler:hover,
.navbar-toggler:focus {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Payment form responsive adjustments */
@media (max-width: 768px) {
    .payment-form-container {
        padding: 1rem;
    }
    
    .payment-methods-list {
        flex-direction: column;
    }
    
    .payment-method-item {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Stack inline forms on mobile */
    .d-inline-flex {
        display: flex !important;
        flex-direction: column;
        align-items: stretch !important;
    }
    
    .d-inline-flex input,
    .d-inline-flex button {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }
}

/* Ensure dropdowns are accessible */
.dropdown-menu {
    min-width: 200px;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: #f8f9fa;
    color: #212529;
}

/* Loading states */
.btn.loading {
    position: relative;
    color: transparent;
}

.btn.loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #f3f3f3;
    border-radius: 50%;
    border-top: 2px solid #3498db;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Print styles */
@media print {
    .navbar,
    .footer,
    .btn,
    .modal {
        display: none !important;
    }
    
    .content {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        border: 1px solid #000 !important;
        page-break-inside: avoid;
    }
}