/* CSS Variables */
:root {
    --cncf-blue: #446ca9;
    --cncf-blue-dark: #365589;
    --cncf-blue-light: #5a82bf;
    --cncf-blue-tint: rgba(68, 108, 169, 0.08);
    --cncf-blue-tint-strong: rgba(68, 108, 169, 0.15);
    --color-bg: #f8f9fa;
    --color-bg-white: #ffffff;
    --color-text: #212529;
    --color-text-muted: #565e66;
    --color-text-on-dark-muted: #c9ced6;
    --color-border: #dee2e6;
    --color-error: #b3261e;
    --color-highlight: #fff4cc;

    --status-approved-bg: #d7f0dc;
    --status-approved-fg: #1b5e20;
    --status-denied-bg: #b3261e;
    --status-denied-fg: #ffffff;
    --status-not-eligible-bg: #8a4b00;
    --status-not-eligible-fg: #ffffff;
    --status-allowlisted-bg: #d6e6fb;
    --status-allowlisted-fg: #0b3d7a;
    --status-apache-bg: #e4e6ea;
    --status-apache-fg: #2f3640;

    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

    --text-xs: 0.8125rem;
    --text-sm: 0.875rem;
    --text-md: 0.9375rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2.5rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-pill: 999px;
    --focus-ring: 2px solid var(--cncf-blue);
    --focus-offset: 2px;
    --duration: 0.2s;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-padding-top: var(--space-7);
}

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
}

a {
    color: var(--cncf-blue-dark);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--space-5);
}

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

/* Focus */
:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

.header a:focus-visible,
.footer a:focus-visible,
.footer button:focus-visible,
#exceptions-table thead .sort-btn:focus-visible {
    outline-color: var(--color-bg-white);
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--cncf-blue) 0%, var(--cncf-blue-dark) 100%);
    color: white;
    padding: var(--space-6) 0;
    text-align: center;
}

.header h1 {
    margin: 0;
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.header .subtitle {
    margin: var(--space-2) 0 0;
    opacity: 0.92;
    font-size: var(--text-lg);
}

/* Intro */
.intro {
    margin: var(--space-5) 0 0;
    padding: var(--space-4) var(--space-5);
    background: var(--color-bg-white);
    border-left: 4px solid var(--cncf-blue);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.intro p {
    margin: 0;
    max-width: 70ch;
    color: var(--color-text);
    font-size: var(--text-md);
}

/* Filters */
.filters {
    background: var(--color-bg-white);
    padding: var(--space-5);
    margin: var(--space-5) 0;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.filters-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}

.filter-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.filter-group-search {
    grid-column: 1 / -1;
}

.filter-group label {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-bottom: 0.375rem;
}

.filter-group input,
.filter-group select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0.625rem var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: var(--text-base);
    color: var(--color-text);
    background-color: var(--color-bg-white);
    transition: border-color var(--duration), box-shadow var(--duration);
}

.filter-group select {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-group input:focus-visible,
.filter-group select:focus-visible {
    border-color: var(--cncf-blue);
}

.filters-footer {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-4);
    flex-wrap: wrap;
}

/* Status Legend */
.status-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    flex: 1 1 auto;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: var(--text-md);
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--duration), transform 0.1s;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    flex-shrink: 0;
}

.btn-secondary:hover {
    background-color: var(--color-border);
}

.link-btn {
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

.link-btn:hover {
    color: var(--cncf-blue-light);
}

/* Sort Controls */
.sort-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
    gap: var(--space-4);
}

.results-summary {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.results-count {
    font-size: var(--text-lg);
    font-weight: 500;
    color: var(--color-text);
}

.results-count strong {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--cncf-blue-dark);
    font-variant-numeric: tabular-nums;
}

.results-note {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    padding: var(--space-1) var(--space-2);
    background: var(--cncf-blue-tint);
    border-radius: var(--radius-sm);
}

.sort-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.sort-group label {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.sort-group select {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: var(--text-sm);
    color: var(--color-text);
    background-color: var(--color-bg-white);
    max-width: 100%;
    min-width: 0;
}

/* Results Table */
.results {
    background: var(--color-bg-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

#exceptions-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--text-md);
}

.col-package { width: 24%; }
.col-status { width: 10%; }
.col-license { width: 20%; }
.col-project { width: 14%; }
.col-scope { width: 17%; }
.col-date { width: 9%; }
.col-issue { width: 6%; }

#exceptions-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--cncf-blue);
    color: white;
    padding: 0;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

#exceptions-table thead th:first-child {
    border-top-left-radius: var(--radius-md);
}

#exceptions-table thead th:last-child {
    border-top-right-radius: var(--radius-md);
}

#exceptions-table thead th:not(.sortable) {
    padding: var(--space-4);
}

#exceptions-table th.sortable {
    transition: background-color var(--duration);
}

#exceptions-table th.sortable:hover,
#exceptions-table th.sortable.sorted {
    background-color: var(--cncf-blue-dark);
}

.sort-btn {
    display: block;
    width: 100%;
    padding: var(--space-4);
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    user-select: none;
}

.sort-btn:focus-visible {
    outline-offset: -4px;
}

#exceptions-table th .sort-indicator {
    font-size: 0.75rem;
    opacity: 0.9;
}

#exceptions-table td {
    padding: 0.875rem var(--space-4);
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

#exceptions-table tbody tr:hover {
    background-color: rgba(68, 108, 169, 0.04);
}

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

#exceptions-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: var(--radius-md);
}

#exceptions-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: var(--radius-md);
}

.exception-row.highlighted td {
    background-color: var(--color-highlight);
    box-shadow: inset 4px 0 0 var(--cncf-blue);
}

.error-cell {
    text-align: center;
    padding: var(--space-6);
    color: var(--color-error);
}

.cell-empty {
    color: var(--color-text-muted);
}

.policy-date {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    font-style: italic;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

/* Package cell */
.package-cell {
    min-width: 0;
}

.package-link {
    color: var(--cncf-blue-dark);
    text-decoration: none;
    word-break: break-word;
}

.package-link:hover {
    text-decoration: underline;
}

.package-name {
    word-break: break-word;
}

.comment-toggle {
    margin-left: var(--space-2);
    vertical-align: middle;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--cncf-blue);
    font-size: var(--text-base);
    line-height: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color var(--duration), color var(--duration);
}

.comment-toggle:hover,
.comment-toggle[aria-expanded="true"] {
    background-color: var(--cncf-blue-tint-strong);
    color: var(--cncf-blue-dark);
}

/* Comment row */
.comment-row td {
    padding: var(--space-3) var(--space-4) var(--space-4);
    background: var(--color-bg);
    font-size: var(--text-sm);
    color: var(--color-text);
    box-shadow: inset 4px 0 0 var(--cncf-blue);
}

#exceptions-table tbody .comment-row:hover {
    background-color: transparent;
}

.comment-label {
    display: inline-block;
    margin-right: var(--space-2);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.comment-text {
    white-space: pre-wrap;
}

/* Issue Link */
.results-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--cncf-blue-dark);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: 500;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    background-color: var(--cncf-blue-tint);
    transition: background-color var(--duration), color var(--duration);
}

.results-link:hover {
    background-color: var(--cncf-blue-tint-strong);
}

/* License Badge */
.license-badge {
    display: inline-block;
    background: var(--color-bg);
    color: var(--color-text);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    overflow-wrap: break-word;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: var(--space-1) 0.625rem;
    border-radius: var(--radius-pill);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.status-glyph::before {
    content: attr(data-glyph);
    font-size: 0.75rem;
}

.status-approved {
    background-color: var(--status-approved-bg);
    color: var(--status-approved-fg);
}

.status-allowlisted {
    background-color: var(--status-allowlisted-bg);
    color: var(--status-allowlisted-fg);
}

.status-apache-2-0 {
    background-color: var(--status-apache-bg);
    color: var(--status-apache-fg);
}

.status-denied {
    background-color: var(--status-denied-bg);
    color: var(--status-denied-fg);
}

.status-not-eligible {
    background-color: var(--status-not-eligible-bg);
    color: var(--status-not-eligible-fg);
}

/* No Results */
.no-results {
    padding: var(--space-7) var(--space-5);
    text-align: center;
    color: var(--color-text-muted);
}

.no-results p {
    margin: 0 auto;
    max-width: 60ch;
    font-size: var(--text-base);
}

.no-results-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-2) !important;
}

/* Footer */
.footer {
    background: var(--color-text);
    color: white;
    padding: var(--space-6) 0;
    margin-top: var(--space-7);
}

.footer .container {
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: var(--space-6);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.footer-links a,
.footer-links button {
    color: white;
    text-decoration: none;
    font-size: var(--text-md);
    transition: opacity var(--duration);
}

.footer-links a:hover,
.footer-links button:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.footer-meta {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--color-text-on-dark-muted);
}

/* Responsive: stacked cards below 768px */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.75rem;
    }

    .header .subtitle {
        font-size: var(--text-base);
    }

    .filters-row {
        grid-template-columns: 1fr;
    }

    .filters-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .legend-item {
        width: 100%;
    }

    .sort-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .sort-group {
        width: 100%;
    }

    .sort-group select {
        flex: 1 1 auto;
    }

    .results {
        background: transparent;
        box-shadow: none;
    }

    #exceptions-table,
    #exceptions-table tbody,
    #exceptions-table tr,
    #exceptions-table td {
        display: block;
    }

    #exceptions-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    #exceptions-table {
        font-size: var(--text-sm);
    }

    #exceptions-table tbody tr {
        background: var(--color-bg-white);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
        margin-bottom: var(--space-3);
        overflow: hidden;
    }

    #exceptions-table tbody tr:hover {
        background-color: var(--color-bg-white);
    }

    #exceptions-table tbody tr[hidden] {
        display: none;
    }

    #exceptions-table td {
        display: grid;
        grid-template-columns: 7rem 1fr;
        gap: var(--space-3);
        align-items: start;
        padding: var(--space-2) var(--space-4);
        border-bottom: 1px solid var(--color-border);
    }

    #exceptions-table td:first-child {
        padding-top: var(--space-3);
    }

    #exceptions-table tbody tr td:last-child {
        border-bottom: none;
        padding-bottom: var(--space-3);
        border-radius: 0;
    }

    #exceptions-table td::before {
        content: attr(data-label);
        font-size: 0.6875rem;
        font-weight: 700;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--color-text-muted);
        padding-top: 0.2em;
    }

    #exceptions-table td > * {
        justify-self: start;
        max-width: 100%;
    }

    #exceptions-table td:not([data-label]) {
        display: block;
    }

    .exception-row.highlighted td {
        box-shadow: none;
    }

    .exception-row.highlighted {
        outline: 2px solid var(--cncf-blue);
    }

    .comment-row {
        margin-top: calc(-1 * var(--space-3) - 1px) !important;
        border-top-left-radius: 0 !important;
        border-top-right-radius: 0 !important;
    }

    .comment-row td {
        box-shadow: none;
        border-top: 1px dashed var(--color-border);
    }

    .footer-links {
        flex-direction: column;
        gap: var(--space-4);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }

    .btn:hover {
        transform: none;
    }
}
