/* Accessibility Improvements for Finance System */

/* Import color variables */
@import url('variables.css');

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #7bbc32;
        --secondary-color: #003a71;
        --accent-color: #f8b33a;
        --text-color: #000000;
        --background-color: #ffffff;
        --border-color: #000000;
    }
    
    .btn-primary {
        background: var(--primary-color);
        border: 2px solid var(--border-color);
    }
    
    .alert-danger {
        background-color: #ffebee;
        color: #d32f2f;
        border: 2px solid #d32f2f;
    }
    
    .alert-success {
        background-color: #e8f5e8;
        color: #2e7d32;
        border: 2px solid #2e7d32;
    }
}

/* Focus Indicators */
*:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus,
input:focus,
select:focus,
textarea:focus,
a:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Skip to Main Content Link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--secondary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 1000;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 6px;
}

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

/* Improved Color Contrast for Error Messages */
.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    font-weight: 500;
}

.alert-success {
    background-color: #e8f5e8;
    color: var(--primary-color-dark);
    border: 1px solid var(--primary-color);
    font-weight: 500;
}

.alert-warning {
    background-color: #fff8e1;
    color: #856404;
    border: 1px solid var(--accent-color);
    font-weight: 500;
}

/* Touch Target Improvements */
@media (pointer: coarse) {
    button, 
    .btn, 
    .btn-primary, 
    .btn-secondary, 
    .btn-danger, 
    .btn-logout,
    .action-link,
    input[type="submit"],
    input[type="button"],
    .tab-btn,
    .calc-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
    
    /* Increase spacing between touch targets */
    .action-links {
        gap: 12px;
    }
    
    .town-actions {
        gap: 12px;
    }
    
    .dashboard-controls {
        gap: 16px;
    }
}

/* Mobile Responsive Tables */
@media (max-width: 768px) {
    /* Make tables scrollable */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Stack table content for mobile */
    .data-table,
    .table {
        display: block;
        min-width: 600px;
    }
    
    .data-table thead,
    .table thead {
        display: none;
    }
    
    .data-table tbody,
    .table tbody {
        display: block;
    }
    
    .data-table tr,
    .table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e9ecef;
        border-radius: 8px;
        padding: 1rem;
        background: white;
    }
    
    .data-table td,
    .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border: none;
    }
    
    .data-table td:before,
    .table td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #333;
        flex: 1;
    }
    
    .data-table td:after,
    .table td:after {
        content: attr(data-value);
        flex: 2;
        text-align: right;
    }
    
    /* Special handling for action links */
    .data-table td:last-child,
    .table td:last-child {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid #e9ecef;
    }
    
    .data-table td:last-child:before,
    .table td:last-child:before {
        content: "Actions";
        margin-bottom: 8px;
    }
    
    .data-table td:last-child:after,
    .table td:last-child:after {
        content: none;
    }
    
    .action-links {
        flex-direction: column;
        width: 100%;
    }
    
    .action-link {
        text-align: center;
        padding: 12px 8px;
    }
}

/* Reduced Motion Support */
@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;
    }
}

/* Keyboard Navigation Improvements */
.keyboard-nav *:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Modal Accessibility */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}

.modal[aria-hidden="false"] {
    display: block;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 10px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* Form Accessibility */
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(123, 188, 50, 0.2);
}

/* Error State Improvements */
.form-group.error input,
.form-group.error select,
.form-group.error textarea {
    border-color: #dc3545;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2);
}

.form-group.error label {
    color: #dc3545;
}

.form-error {
    color: #dc3545;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

/* Loading State Accessibility */
.loading[aria-live="polite"] {
    position: relative;
}

.loading[aria-live="polite"]:before {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 1rem;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Search Results Accessibility */
.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 5px 5px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.search-result-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.search-result-item:hover,
.search-result-item:focus {
    background-color: #f8f9fa;
}

/* Tab Navigation Accessibility */
.tab-btn {
    background: none;
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border-radius: 5px;
    font-weight: 600;
    color: #666;
    transition: all 0.3s ease;
}

.tab-btn:hover:not(.active),
.tab-btn:focus:not(.active) {
    background-color: #f5f5f5;
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

/* Status Badge Improvements */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
}

.status-active {
    background-color: #e8f5e8;
    color: var(--primary-color-dark);
}

.status-completed {
    background-color: #cce5ff;
    color: var(--secondary-color-dark);
}

.status-defaulted {
    background-color: #f8d7da;
    color: #721c24;
}

/* Dashboard Card Accessibility */
.dashboard-card {
    background: white;
    padding: 1.5rem;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.dashboard-card:hover,
.dashboard-card:focus-within {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}

/* EMI Item Accessibility */
.emi-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.emi-item:hover,
.emi-item:focus-within {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Payment Item Accessibility */
.payment-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.payment-item:hover,
.payment-item:focus-within {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Print Styles */
@media print {
    .navbar,
    .btn-logout,
    .dashboard-controls,
    .search-container,
    .modal {
        display: none !important;
    }
    
    .container {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }
    
    .dashboard-card,
    .emi-item,
    .payment-item {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
