/**
 * Codified Ordinances Browser Styles
 * ==================================
 * Responsive, modern card-based interface for browsing ordinances by category
 */

/* =================================================================
   CONTAINER & GRID LAYOUT
   ================================================================= */

#codified-ordinances-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
    gap: 1.5rem;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* =================================================================
   CATEGORY CARDS
   ================================================================= */

.codified-category-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}

.codified-category-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.codified-category-card.expanded {
    grid-column: span 1;
}

/* =================================================================
   CATEGORY HEADER
   ================================================================= */

.codified-category-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    cursor: pointer;
    user-select: none;
    border-left: 4px solid transparent;
    transition: background-color 0.2s ease;
    position: relative;
}

.codified-category-header:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.codified-category-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.codified-category-info {
    flex: 1;
    min-width: 0;
}

.codified-category-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 0.25rem 0;
}

.codified-category-count {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0;
}

.codified-category-toggle {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: #f3f4f6;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.codified-category-toggle:hover {
    background: #e5e7eb;
    color: #374151;
}

.codified-category-toggle svg {
    transition: transform 0.3s ease;
}

/* =================================================================
   CATEGORY BODY (EXPANDABLE)
   ================================================================= */

.codified-category-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

/* =================================================================
   CATEGORY CONTROLS
   ================================================================= */

.codified-category-controls {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
}

.codified-search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.codified-search-input {
    width: 100%;
    padding: 0.625rem 0.875rem 0.625rem 2.5rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    background: #ffffff;
}

.codified-search-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.codified-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
}

.codified-year-filter {
    padding: 0.625rem 2rem 0.625rem 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
    background: #ffffff 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='%236b7280' d='M10.293 3.293L6 7.586 1.707 3.293A1 1 0 00.293 4.707l5 5a1 1 0 001.414 0l5-5a1 1 0 10-1.414-1.414z'/%3E%3C/svg%3E") no-repeat right 0.625rem center;
    appearance: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 130px;
}

.codified-year-filter:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* =================================================================
   ORDINANCES LIST
   ================================================================= */

.codified-ordinances-list {
    max-height: 500px;
    overflow-y: auto;
    padding: 0.5rem;
}

/* Custom scrollbar */
.codified-ordinances-list::-webkit-scrollbar {
    width: 8px;
}

.codified-ordinances-list::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 4px;
}

.codified-ordinances-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.codified-ordinances-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* =================================================================
   ORDINANCE ITEMS
   ================================================================= */

.codified-ordinance-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.codified-ordinance-item:hover {
    background: #f9fafb;
    border-color: #3b82f6;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.1);
}

.codified-ordinance-number {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    background: #f3f4f6;
    border-radius: 6px;
    min-width: 70px;
    flex-shrink: 0;
}

.ordinance-year {
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 600;
}

.ordinance-number {
    font-size: 1rem;
    color: #1f2937;
    font-weight: 700;
}

.codified-ordinance-content {
    flex: 1;
    min-width: 0;
}

.codified-ordinance-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 0.375rem 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.codified-ordinance-subject {
    font-size: 0.8125rem;
    color: #6b7280;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.codified-ordinance-action {
    color: #9ca3af;
    flex-shrink: 0;
}

.codified-ordinance-item:hover .codified-ordinance-action {
    color: #3b82f6;
}

/* =================================================================
   LOADING & ERROR STATES
   ================================================================= */

.codified-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.codified-error {
    padding: 2rem 1rem;
    text-align: center;
    color: #ef4444;
    background: #fef2f2;
    border-radius: 8px;
    margin: 1rem;
}

.codified-error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    color: #6b7280;
    grid-column: 1 / -1;
}

.codified-error-message svg {
    color: #ef4444;
    margin-bottom: 1rem;
}

.codified-error-message h3 {
    color: #1f2937;
    font-size: 1.25rem;
    margin: 0 0 0.5rem 0;
}

.codified-error-message p {
    margin: 0 0 1.5rem 0;
}

.retry-button {
    padding: 0.625rem 1.5rem;
    background: #3b82f6;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.retry-button:hover {
    background: #2563eb;
}

/* =================================================================
   STATISTICS
   ================================================================= */

#codified-stats {
    display: flex;
    gap: 2rem;
    justify-content: center;
    padding: 2rem 1rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    max-width: 1400px;
    margin: 0 auto 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #ffffff;
}

.stat-label {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* =================================================================
   DARK MODE SUPPORT
   ================================================================= */

@media (prefers-color-scheme: dark) {
    .codified-category-card {
        background: #1f2937;
        border-color: #374151;
    }

    .codified-category-header:hover {
        background-color: rgba(255, 255, 255, 0.05);
    }

    .codified-category-name {
        color: #f9fafb;
    }

    .codified-category-count {
        color: #9ca3af;
    }

    .codified-category-toggle {
        background: #374151;
        color: #9ca3af;
    }

    .codified-category-toggle:hover {
        background: #4b5563;
        color: #d1d5db;
    }

    .codified-category-body {
        background: #111827;
        border-top-color: #374151;
    }

    .codified-category-controls {
        background: #1f2937;
        border-bottom-color: #374151;
    }

    .codified-search-input,
    .codified-year-filter {
        background: #111827;
        border-color: #4b5563;
        color: #f9fafb;
    }

    .codified-ordinances-list::-webkit-scrollbar-track {
        background: #1f2937;
    }

    .codified-ordinances-list::-webkit-scrollbar-thumb {
        background: #4b5563;
    }

    .codified-ordinances-list::-webkit-scrollbar-thumb:hover {
        background: #6b7280;
    }

    .codified-ordinance-item {
        background: #1f2937;
        border-color: #374151;
    }

    .codified-ordinance-item:hover {
        background: #111827;
    }

    .codified-ordinance-number {
        background: #111827;
    }

    .codified-ordinance-title {
        color: #f9fafb;
    }

    .codified-ordinance-subject {
        color: #9ca3af;
    }

    .codified-error-message h3 {
        color: #f9fafb;
    }

    .codified-error-message p {
        color: #9ca3af;
    }
}

/* =================================================================
   RESPONSIVE DESIGN
   ================================================================= */

/* Tablets and small desktops */
@media (max-width: 1024px) {
    #codified-ordinances-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
        gap: 1.25rem;
    }

    .codified-category-card.expanded {
        grid-column: span 1;
    }
}

/* Mobile devices */
@media (max-width: 768px) {
    #codified-ordinances-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 0.75rem;
    }

    .codified-category-header {
        padding: 1rem;
    }

    .codified-category-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .codified-category-name {
        font-size: 1rem;
    }

    .codified-category-count {
        font-size: 0.8125rem;
    }

    .codified-category-controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .codified-search-box,
    .codified-year-filter {
        min-width: 100%;
    }

    .codified-ordinances-list {
        max-height: 400px;
    }

    .codified-ordinance-item {
        gap: 0.75rem;
        padding: 0.875rem;
    }

    .codified-ordinance-number {
        min-width: 60px;
    }

    .ordinance-number {
        font-size: 0.9375rem;
    }

    .codified-ordinance-title {
        font-size: 0.875rem;
        -webkit-line-clamp: 3;
    }

    #codified-stats {
        gap: 1rem;
        padding: 1.5rem 1rem;
        margin-bottom: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .codified-ordinance-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .codified-ordinance-number {
        flex-direction: row;
        gap: 0.5rem;
        align-items: center;
        min-width: 100%;
        justify-content: center;
    }

    .ordinance-year::after {
        content: '•';
        margin: 0 0.25rem;
    }
}

/* =================================================================
   PRINT STYLES
   ================================================================= */

@media print {
    #codified-ordinances-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .codified-category-card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }

    .codified-category-toggle {
        display: none;
    }

    .codified-category-body {
        max-height: none !important;
        overflow: visible;
    }

    .codified-category-controls {
        display: none;
    }

    .codified-ordinances-list {
        max-height: none;
        overflow: visible;
    }

    .codified-ordinance-item {
        page-break-inside: avoid;
    }

    .codified-ordinance-action {
        display: none;
    }

    #codified-stats {
        background: none;
        border: 1px solid #000;
        color: #000;
    }

    .stat-value,
    .stat-label {
        color: #000;
    }
}

/* =================================================================
   ACCESSIBILITY
   ================================================================= */

/* Focus styles for keyboard navigation */
.codified-category-header:focus-visible,
.codified-search-input:focus-visible,
.codified-year-filter:focus-visible,
.codified-ordinance-item:focus-visible,
.retry-button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .spinner {
        animation: none;
        border-top-color: #3b82f6;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .codified-category-card {
        border-width: 2px;
    }

    .codified-ordinance-item {
        border-width: 2px;
    }

    .codified-search-input:focus,
    .codified-year-filter:focus {
        outline-width: 3px;
    }
}
