/**
 * Food Inspection Tool Styles
 * Version 3.0.0 - WCAG 2.1 AA Compliant
 * 
 * Accessibility Features:
 * - Color contrast ratios meet 4.5:1 minimum
 * - Visible focus indicators on all interactive elements
 * - Support for prefers-reduced-motion
 * - Support for prefers-contrast (high contrast mode)
 * - Minimum touch target sizes (44x44px)
 */

/* ========================================
   ACCESSIBILITY: Visually Hidden (Screen Reader Only)
   ======================================== */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.visually-hidden-focusable:focus,
.visually-hidden-focusable:active {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ========================================
   ACCESSIBILITY: Skip Link
   ======================================== */

.fi-skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #1a1a1a;
    color: #ffffff;
    padding: 12px 20px;
    z-index: 10000;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 4px 0;
}

.fi-skip-link:focus {
    top: 0;
    outline: 3px solid #ffcc00;
    outline-offset: 2px;
}

/* ========================================
   ACCESSIBILITY: Focus Styles (Global)
   ======================================== */

.food-inspection-container *:focus {
    outline: 3px solid #1976d2;
    outline-offset: 2px;
}

.food-inspection-container *:focus:not(:focus-visible) {
    outline: none;
}

.food-inspection-container *:focus-visible {
    outline: 3px solid #1976d2;
    outline-offset: 2px;
}

/* High contrast focus for dark backgrounds */
.fi-establishment-item.active:focus,
.fi-establishment-item.active:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px #1976d2;
}

/* ========================================
   CONTAINER
   ======================================== */

.food-inspection-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ========================================
   SIDEBAR STYLES (1/3 width)
   ======================================== */

.fi-sidebar {
    flex: 0 0 calc(33.333% - 10px);
    max-width: calc(33.333% - 10px);
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    max-height: calc(100vh - 200px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.fi-sidebar-header {
    flex-shrink: 0;
}

.fi-sidebar-header h3 {
    margin: 0 0 15px 0;
    color: #1a1a1a; /* WCAG AAA contrast */
    font-size: 1.4em;
}

/* ========================================
   SEARCH BOX - Accessible
   ======================================== */

.fi-search-box {
    position: relative;
    margin-bottom: 15px;
}

.fi-search-box label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #1a1a1a;
    font-size: 14px;
}

.fi-search-box input {
    width: 100%;
    padding: 12px 44px 12px 15px; /* Ensure touch target */
    border: 2px solid #595959; /* Darker border for contrast */
    border-radius: 4px;
    font-size: 16px; /* Prevent iOS zoom */
    box-sizing: border-box;
    min-height: 44px; /* Touch target minimum */
}

.fi-search-box input:focus {
    border-color: #1976d2;
    outline: 3px solid rgba(25, 118, 210, 0.4);
    outline-offset: 0;
}

.fi-search-box input::placeholder {
    color: #595959; /* 4.5:1 contrast */
}

.fi-search-icon {
    position: absolute;
    right: 12px;
    bottom: 12px;
    pointer-events: none;
    color: #595959;
    font-size: 18px;
}

/* ========================================
   FILTER BOX - Accessible
   ======================================== */

.fi-filter-box {
    margin-bottom: 15px;
}

.fi-filter-box label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #1a1a1a;
    font-size: 14px;
}

.fi-filter-box select {
    width: 100%;
    padding: 12px 35px 12px 12px;
    border: 2px solid #595959;
    border-radius: 4px;
    font-size: 16px;
    background: white;
    cursor: pointer;
    box-sizing: border-box;
    min-height: 44px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23595959' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.fi-filter-box select:focus {
    border-color: #1976d2;
    outline: 3px solid rgba(25, 118, 210, 0.4);
    outline-offset: 0;
}

/* ========================================
   RESULTS COUNT - Accessible
   ======================================== */

.fi-results-count {
    font-size: 14px;
    color: #1a1a1a; /* Fixed contrast */
    padding: 8px 0;
    margin-bottom: 10px;
    border-bottom: 1px solid #ccc;
}

/* Live region announcement */
.fi-live-region {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* ========================================
   ESTABLISHMENT LIST - Accessible
   ======================================== */

.fi-establishment-list {
    flex: 1;
    overflow-y: auto;
    border-top: 1px solid #ccc;
    padding-top: 15px;
}

/* Use role="listbox" for the list */
.fi-establishment-list[role="listbox"] {
    /* Listbox styling */
}

.fi-establishment-item {
    padding: 14px 15px;
    margin-bottom: 8px;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid #767676; /* 4.5:1 contrast border */
    min-height: 44px; /* Touch target */
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.fi-establishment-item:hover {
    background: #e3f2fd;
    border-color: #1976d2;
}

.fi-establishment-item:focus {
    outline: 3px solid #1976d2;
    outline-offset: 2px;
}

.fi-establishment-item[aria-selected="true"],
.fi-establishment-item.active {
    background: #1565c0; /* Slightly darker for better contrast */
    color: white;
    border-color: #1565c0;
}

.fi-establishment-item.active .fi-est-item-location {
    color: #e3f2fd; /* Light blue - 4.5:1 on #1565c0 */
}

.fi-est-item-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.fi-est-item-location {
    font-size: 13px;
    color: #454545; /* Fixed contrast: 7:1 on white */
}

/* ========================================
   LOADING & STATUS STATES - Accessible
   ======================================== */

.fi-loading {
    text-align: center;
    padding: 20px;
    color: #1a1a1a;
}

.fi-loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: fi-spin 1s linear infinite;
    margin-right: 10px;
    vertical-align: middle;
}

@keyframes fi-spin {
    to { transform: rotate(360deg); }
}

.fi-no-results {
    text-align: center;
    padding: 20px;
    color: #1a1a1a; /* Fixed contrast */
    line-height: 1.6;
}

.fi-no-results strong {
    color: #1a1a1a;
}

.fi-no-results small {
    color: #454545; /* Fixed contrast */
    font-size: 13px;
}

/* Error state with role="alert" */
.fi-error {
    background: #ffebee;
    border: 2px solid #c62828;
    border-radius: 4px;
    color: #b71c1c; /* Dark red for contrast */
    padding: 15px;
}

.fi-error strong {
    color: #b71c1c;
}

/* ========================================
   MAIN CONTENT STYLES (2/3 width)
   ======================================== */

.fi-content {
    flex: 0 0 calc(66.666% - 10px);
    max-width: calc(66.666% - 10px);
    background: white;
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.fi-content-header h2 {
    color: #1a1a1a;
    margin-bottom: 15px;
}

.fi-intro-text {
    color: #454545; /* Fixed contrast */
    line-height: 1.6;
    font-size: 15px;
}

/* ========================================
   ESTABLISHMENT DETAILS HEADER
   ======================================== */

.fi-establishment-info {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.fi-establishment-info h2 {
    margin: 0 0 10px 0;
    color: #0d47a1; /* Darker blue for better contrast */
    font-size: 1.6em;
}

.fi-est-location {
    color: #454545;
    margin-bottom: 15px;
    font-size: 15px;
}

/* ========================================
   EXPORT BUTTON - Accessible
   ======================================== */

.fi-export-btn {
    background: #2e7d32; /* Darker green for contrast */
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    min-height: 44px;
    min-width: 44px;
    transition: background-color 0.15s ease;
}

.fi-export-btn:hover {
    background: #1b5e20;
}

.fi-export-btn:focus {
    outline: 3px solid #1976d2;
    outline-offset: 2px;
}

.fi-export-btn:active {
    background: #1b5e20;
}

.fi-export-btn:disabled {
    background: #757575;
    cursor: not-allowed;
    color: #e0e0e0;
}

/* ========================================
   INSPECTIONS TABLE - Accessible
   ======================================== */

.fi-inspections-table-container {
    overflow-x: auto;
    /* Ensure scrollable region is keyboard accessible */
    tabindex: 0;
}

.fi-inspections-table-container:focus {
    outline: 3px solid #1976d2;
    outline-offset: 2px;
}

.fi-inspections-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

/* Caption for screen readers */
.fi-inspections-table caption {
    text-align: left;
    font-weight: 600;
    padding: 10px 0;
    color: #1a1a1a;
    font-size: 16px;
}

.fi-inspections-table caption.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.fi-inspections-table thead {
    background: #1565c0; /* Slightly darker for contrast */
    color: white;
}

.fi-inspections-table th {
    padding: 14px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

.fi-inspections-table td {
    padding: 14px 12px;
    border-bottom: 1px solid #ccc;
    vertical-align: top;
    color: #1a1a1a;
}

.fi-inspections-table tbody tr:hover {
    background: #f5f5f5;
}

.fi-inspections-table tbody tr:nth-child(even) {
    background: #fafafa;
}

.fi-inspections-table tbody tr:nth-child(even):hover {
    background: #f0f0f0;
}

/* Focus within table rows */
.fi-inspections-table tbody tr:focus-within {
    outline: 2px solid #1976d2;
    outline-offset: -2px;
}

/* ========================================
   VIOLATION CODES - Two Column Layout (Accessible)
   ======================================== */

.fi-violation-codes {
    font-size: 14px;
    max-width: 300px;
}

/* Use list for multiple violations */
.fi-violation-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.fi-violation-list li {
    margin-bottom: 6px;
}

.fi-violation-code {
    display: block;
    margin-bottom: 6px;
    padding: 8px 12px;
    background: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 4px;
    line-height: 1.5;
    color: #1a1a1a;
}

/* No violations state */
.fi-no-violations {
    color: #454545;
    font-style: italic;
}

/* Table header subtext for column descriptions */
.fi-th-subtext {
    font-weight: normal;
    font-size: 11px;
    opacity: 0.9;
}

/* ========================================
   NOTES
   ======================================== */

.fi-notes {
    font-size: 14px;
    color: #454545; /* Fixed contrast */
    font-style: italic;
    max-width: 250px;
    line-height: 1.5;
}

/* ========================================
   NO INSPECTIONS MESSAGE
   ======================================== */

.fi-no-inspections {
    text-align: center;
    padding: 40px;
    color: #454545; /* Fixed contrast */
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 1024px) {
    .food-inspection-container {
        flex-direction: column;
    }
    
    .fi-sidebar,
    .fi-content {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    .fi-sidebar {
        max-height: 450px;
    }
}

@media (max-width: 768px) {
    .food-inspection-container {
        padding: 10px;
    }
    
    .fi-sidebar,
    .fi-content {
        padding: 15px;
    }
    
    .fi-inspections-table {
        font-size: 14px;
    }
    
    .fi-inspections-table th,
    .fi-inspections-table td {
        padding: 10px 8px;
    }
    
    .fi-violation-codes {
        max-width: 250px;
    }
    
    .fi-notes {
        max-width: 180px;
    }
}

@media (max-width: 480px) {
    .fi-establishment-info h2 {
        font-size: 1.3em;
    }
    
    /* Stack table on very small screens */
    .fi-inspections-table thead {
        position: absolute;
        left: -9999px;
        /* Keep for screen readers but hide visually */
    }
    
    .fi-inspections-table tr {
        display: block;
        margin-bottom: 15px;
        border: 2px solid #767676;
        border-radius: 4px;
        background: white;
    }
    
    .fi-inspections-table td {
        display: block;
        padding: 10px 12px;
        border-bottom: 1px solid #e0e0e0;
        position: relative;
        padding-left: 45%;
    }
    
    .fi-inspections-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 12px;
        width: 40%;
        font-weight: 600;
        color: #0d47a1;
    }
    
    .fi-inspections-table td:last-child {
        border-bottom: none;
    }
    
    .fi-violation-codes,
    .fi-notes {
        max-width: 100%;
    }
}

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

@media print {
    .fi-sidebar,
    .fi-export-btn,
    .fi-search-box,
    .fi-filter-box,
    .fi-skip-link {
        display: none !important;
    }
    
    .fi-content {
        width: 100% !important;
        max-width: 100% !important;
        box-shadow: none !important;
        padding: 0 !important;
    }
    
    .food-inspection-container {
        padding: 0;
    }
    
    .fi-inspections-table {
        font-size: 11px;
    }
    
    .fi-inspections-table thead {
        background: #333 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ========================================
   REDUCED MOTION (Accessibility)
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .fi-establishment-item,
    .fi-export-btn,
    .fi-search-box input,
    .fi-filter-box select {
        transition: none;
    }
    
    .fi-loading-spinner {
        animation: none;
        border-top-color: #1976d2;
    }
}

/* ========================================
   HIGH CONTRAST MODE (Accessibility)
   ======================================== */

@media (prefers-contrast: more) {
    .fi-establishment-item {
        border-width: 3px;
        border-color: #000;
    }
    
    .fi-establishment-item.active {
        background: #000;
        color: #fff;
    }
    
    .fi-search-box input,
    .fi-filter-box select {
        border-width: 3px;
        border-color: #000;
    }
    
    .fi-violation-code {
        border-left-width: 6px;
        border-color: #000;
        background: #fff;
    }
    
    .fi-export-btn {
        border: 3px solid #000;
    }
}

/* ========================================
   SCROLLBAR STYLING (with native fallback)
   ======================================== */

@supports (scrollbar-width: thin) {
    .fi-establishment-list {
        scrollbar-width: thin;
        scrollbar-color: #767676 #f1f1f1;
    }
}

.fi-establishment-list::-webkit-scrollbar {
    width: 10px;
}

.fi-establishment-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.fi-establishment-list::-webkit-scrollbar-thumb {
    background: #767676;
    border-radius: 4px;
    border: 2px solid #f1f1f1;
}

.fi-establishment-list::-webkit-scrollbar-thumb:hover {
    background: #595959;
}

.fi-establishment-list::-webkit-scrollbar-thumb:focus {
    background: #1976d2;
}
