/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --warning-bg: #fef3c7;
    --warning-border: #fbbf24;
    --warning-text: #92400e;
    --info-bg: #dbeafe;
    --info-border: #60a5fa;
    --info-text: #1e40af;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 16px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Header styles */
header {
    margin-bottom: 2rem;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

/* Controls bar */
.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Dropdown styles */
.dropdown-wrapper {
    position: relative;
}

.dropdown {
    appearance: none;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    font-size: 1rem;
    color: var(--text-primary);
    cursor: pointer;
    min-width: 250px;
    transition: all 0.2s ease;
}

.dropdown:hover {
    border-color: var(--primary-color);
}

.dropdown:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Dropdown arrow */
.dropdown-wrapper::after {
    content: '';
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--text-secondary);
    pointer-events: none;
}

/* Language toggle button */
.language-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.language-btn:hover {
    border-color: var(--primary-color);
}

.lang-text {
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.lang-text.active {
    color: var(--primary-color);
    font-weight: 600;
}

.lang-divider {
    color: var(--border-color);
}

/* Search box */
.search-wrapper {
    margin-bottom: 1.5rem;
}

.search-box {
    position: relative;
    max-width: 500px;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

#search {
    width: 100%;
    padding: 0.875rem 1rem 0.875rem 3rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    transition: all 0.2s ease;
}

#search:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#search::placeholder {
    color: var(--text-secondary);
}

/* Warning styles */
.warnings-container {
    margin-bottom: 1rem;
}

.warning-banner {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    position: relative;
    border: 1px solid;
}

.warning-banner.global {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.warning-banner.sheet {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info-text);
}

.warning-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.warning-content {
    flex: 1;
    font-size: 0.95rem;
}

.warning-content p {
    margin: 0;
    line-height: 1.5;
}

.warning-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    transition: opacity 0.2s;
    padding: 0.25rem;
}

.warning-close:hover {
    opacity: 1;
}

/* Table styles */
.table-wrapper {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 2rem;
    min-height: auto; /* Ensure wrapper doesn't have fixed height */
}

table {
    width: 100%;
    min-width: 800px;
    border-collapse: collapse;
    table-layout: auto; /* Changed back to auto for dynamic columns */
}

/* Dynamic column sizing - works for any number of columns */
th, td {
    width: auto;
    min-width: 120px; /* Base minimum for most columns */
}

/* Make the last column (typically contains the most text) wider */
th:last-child, td:last-child {
    width: 40%; /* Last column gets more space */
    min-width: 280px;
}

/* Make first few columns more compact for common short content */
th:first-child, td:first-child {
    width: 12%;
    min-width: 100px;
}

th:nth-child(2), td:nth-child(2) {
    width: 12%;
    min-width: 100px;
}

th:nth-child(3), td:nth-child(3) {
    width: 12%;
    min-width: 100px;
}

/* General padding and styling */
th, td {
    padding: 0.75rem;
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

td {
    border-bottom: 1px solid var(--border-color);
    word-wrap: break-word;
    hyphens: auto; /* Added for better text wrapping */
}

/* Special handling for the last column (typically has the most text) */
td:last-child {
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    line-height: 1.4;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-secondary);
}

/* Link styles */
a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

a:hover {
    text-decoration: underline;
}

/* Loading and error states */
.loading-message,
.error-message,
.no-results-row td {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.error-message {
    color: #dc2626;
}

/* Card styles for mobile */
.cards-container {
    display: none;
}

.resource-card {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

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

.card-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.card-details {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.detail-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.detail-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-value {
    color: var(--text-primary);
    word-break: break-word;
}

.detail-value a {
    display: inline-block;
    margin-right: 0.5rem;
    margin-top: 0.25rem;
}

/* Utility classes */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .controls-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .controls-left,
    .controls-right {
        width: 100%;
        justify-content: center;
    }

    .dropdown {
        min-width: 100%;
    }

    .language-btn {
        width: 100%;
        justify-content: center;
    }

    .search-box {
        max-width: 100%;
    }

    /* Hide table, show cards */
    .table-wrapper {
        display: none;
    }

    .cards-container {
        display: block;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .dropdown {
        min-width: 200px;
    }

    th, td {
        padding: 0.65rem;
        font-size: 0.95rem;
    }
    
    /* Responsive column adjustments for tablets */
    th:last-child, td:last-child { width: 35%; }
    th:first-child, td:first-child { width: 15%; }
    th:nth-child(2), td:nth-child(2) { width: 15%; }
    th:nth-child(3), td:nth-child(3) { width: 15%; }
}

/* Large text mode for accessibility */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #1e40af;
        --border-color: #9ca3af;
    }

    .dropdown,
    #search,
    .language-btn {
        border-width: 3px;
    }
}

/* Smooth transitions */
* {
    transition: background-color 0.2s ease, border-color 0.2s ease;
}
