:root {
    /* Primary UI Elements */
    --brand-main: #3949ab;
    --brand-accent: #e8eaf6;
    --accent-start: #3949ab;
    --accent-end: #8c9eff;
    --separator: #c9c9c9;
    --content: #212121;
    --interactive: #e3e5f1;
    --surface-main: #f5f5f5;
    --surface-elevated: white;
    --overlay: rgba(0, 0, 0, 0.2);
    --focus-ring: #3949ab;
    --accessibility-note: "7:1 ratio for AAA compliance";

    /* Supporting UI Elements */
    --neutral-lightest: #ffffff;
    --brand-translucent-medium: rgba(92, 107, 192, 0.4);
    --brand-translucent-light: rgba(92, 107, 192, 0.15);
    --brand-translucent-regular: rgba(92, 107, 192, 0.3);
    --focus-indicator: rgba(63, 81, 181, 0.4);
    --overlay-medium: rgba(0, 0, 0, 0.3);
    --overlay-heavy: rgba(0, 0, 0, 0.5);
    --overlay-maximum: rgba(0, 0, 0, 0.8);
    --highlight-light: #d1d9ff;

    /* Status and Feedback */
    --alert: #e53935;
    --alert-surface: #ffebee;
    --alert-border: #ffcdd2;
    --alert-bg-translucent: rgba(229, 57, 53, 0.1);
}

[data-theme="dark"] {
    /* Primary UI Elements */
    --brand-main: #8c9eff;
    --brand-accent: #1a237e;
    --accent-start: #3949ab;
    --accent-end: #1a237e;
    --separator: #666;
    --content: var(--neutral-lightest);
    --interactive: #353964;
    --surface-main: #121212;
    --surface-elevated: #242424;
    --overlay: var(--overlay-heavy);
    --focus-ring: #8c9eff;

    /* Dark theme specific elements */
    --header-bg: #1a237e;
    --header-hover: #283593;

    /* Supporting UI Elements */
    --neutral-lightest: #ffffff;
    --brand-translucent-medium: rgba(92, 107, 192, 0.4);
    --brand-translucent-light: rgba(92, 107, 192, 0.15);
    --brand-translucent-regular: rgba(92, 107, 192, 0.3);
    --focus-indicator: rgba(63, 81, 181, 0.4);
    --overlay-medium: rgba(0, 0, 0, 0.3);
    --overlay-heavy: rgba(0, 0, 0, 0.5);
    --overlay-maximum: rgba(0, 0, 0, 0.8);
    --highlight-light: #d1d9ff;

    /* Status and Feedback */
    --alert: #e53935;
    --alert-surface: #ffebee;
    --alert-border: #ffcdd2;
    --alert-bg-translucent: rgba(229, 57, 53, 0.1);
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--content);
    background-color: var(--surface-main);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    font-size: 14px;
}

h1 {
    color: var(--brand-main);
    text-align: center;
    margin: 0.5rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--brand-main);
    font-weight: 700;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    padding: 0.5rem;
    box-sizing: border-box;
}

.summary-container {
    margin-bottom: 1rem;
}

.summary-box {
    background: linear-gradient(135deg, var(--accent-start) 0%, var(--accent-end) 100%);
    color: var(--content);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px var(--overlay);
}

.summary-content h2 {
    margin-top: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.summary-content p {
    margin-bottom: 1rem;
    opacity: 1;
}

.summary-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}

.stat-item {
    background-color: var(--surface-elevated);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    flex: 1 1 auto;
    min-width: 100px;
    backdrop-filter: blur(5px);
    border: 1px solid var(--separator);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.85rem;
    opacity: 1;
}

.search-container {
    padding: 0.5rem 0;
    margin-bottom: 1rem;
}

.search-wrapper {
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}

.filters-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.filter-group {
    position: relative;
    min-width: 180px;
    flex: 1;
}

.filter-select,
#searchInput {
    border: 2px solid var(--separator);
    border-radius: 6px;
    background-color: var(--surface-elevated);
    color: var(--content);
    box-shadow: 0 1px 3px var(--overlay);
    transition: all 0.3s ease;
}

.filter-select {
    width: 100%;
    padding: 0.6rem 2.5rem 0.6rem 1rem;
    font-size: 0.9rem;
    appearance: none;
    cursor: pointer;
}

#searchInput {
    width: 100%;
    max-width: 400px;
    padding: 10px 15px;
    font-size: 14px;
}

.filter-select:focus,
#searchInput:focus {
    outline: none;
    border-color: var(--brand-main);
    box-shadow: 0 0 0 3px var(--brand-translucent-medium);
}

.filter-group::after {
    content: '⌄';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--brand-main);
    pointer-events: none;
    font-size: 1.4rem;
    font-weight: bold;
}

.filter-group:hover::after {
    color: var(--brand-main);
}

.reset-btn,
.theme-toggle {
    background: linear-gradient(135deg, var(--accent-start) 0%, var(--accent-end) 100%);
    color: var(--content);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px var(--overlay);
}

.reset-btn {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.reset-btn:hover {
    background-color: var(--interactive);
    transform: translateY(-2px);
    box-shadow: 0 3px 6px var(--overlay-medium);
}

.reset-btn:focus,
.theme-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.reset-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px var(--overlay-medium);
}

.theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    font-size: 18px;
}

.theme-toggle:hover {
    transform: rotate(30deg);
    background-color: var(--interactive);
    box-shadow: 0 3px 8px var(--overlay);
}

.table-container {
    flex: 1;
    overflow: auto;
    box-shadow: 0 3px 12px var(--overlay);
    border-radius: 8px;
    background: var(--surface-elevated);
    min-height: 0;
    border: 1px solid var(--separator);
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

th,
td {
    padding: 12px 0px 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--separator);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: none;
    padding: 6px 0px 6px 10px;
}

th {
    align-items: center;
    background-color: var(--brand-accent);
    box-shadow: 0 1px 3px var(--overlay);
    color: var(--brand-main);
    cursor: pointer;
    font-weight: 700;
    justify-content: space-between;
    position: sticky;
    top: 0;
    transition: background-color 0.2s;
    white-space: nowrap;
    width: auto;
    z-index: 10;
}

td ul {
    padding-left: 0;
    margin: 5px 0 5px 15px;
}

[data-theme="dark"] th {
    color: var(--neutral-lightest);
    background-color: var(--header-bg);
}

th:hover {
    background-color: var(--highlight-light);
}

[data-theme="dark"] th:hover {
    background-color: var(--header-hover);
}

.sort-indicator {
    margin-left: 8px;
    opacity: 0.9;
    font-size: 0.8rem;
    font-weight: bold;
}

th[aria-sort="ascending"] .sort-indicator::after {
    content: "↑";
}

th[aria-sort="descending"] .sort-indicator::after {
    content: "↓";
}

tr:hover {
    background-color: var(--interactive);
    cursor: pointer;
}

.swatch,
.modal-swatch {
    display: inline-block;
    border: 2px solid var(--separator);
    vertical-align: middle;
    position: relative;
    cursor: pointer;
}

.swatch {
    width: 24px;
    height: 24px;
    margin-right: 0px;
    border-radius: 4px;
}

.swatch-large {
    position: absolute;
    border-radius: 8px;
    border: 2px solid var(--separator);
    box-shadow: 0 5px 15px var(--overlay);
    z-index: 50;
    pointer-events: none;
    background-color: inherit;
    width: 100px;
    height: 100px;
}

.color-tooltip {
    display: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: -130px;
    background-color: var(--surface-elevated);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--overlay);
    z-index: 60;
    width: 120px;
    text-align: center;
    border: 2px solid var(--separator);
    flex-direction: column;
    align-items: center;
}

.swatch:hover .color-tooltip {
    display: flex;
}

.hex-code-text {
    margin-top: 8px;
    font-size: 12px;
    font-family: monospace;
    color: var(--content);
}

.modal-swatch {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    margin-right: 10px;
}

.modal-swatch:hover::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    width: 80px;
    height: 80px;
    background-color: inherit;
    border-radius: 8px;
    border: 2px solid var(--separator);
    box-shadow: 0 5px 15px var(--overlay);
    z-index: 100;
    margin-left: 10px;
}

.cell-content {
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
    position: relative;
}

.citation-link {
    display: inline-block;
    color: var(--brand-main);
    text-decoration: underline;
    font-weight: 600;
    border-radius: 3px;
    padding: 0 3px;
    margin: 0 2px;
    background-color: var(--brand-translucent-light);
    transition: all 0.2s ease;
    position: relative;
}

.citation-link:hover {
    background-color: var(--brand-translucent-regular);
    text-decoration: underline;
}

.citation-link:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-indicator);
}

.citation-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--surface-elevated);
    color: var(--content);
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 3px 10px var(--overlay);
    font-size: 0.9rem;
    width: 200px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    border: 1px solid var(--separator);
    margin-bottom: 10px;
}

.citation-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: var(--surface-elevated) transparent transparent transparent;
}

.citation-link:hover .citation-tooltip {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--overlay-maximum);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--surface-elevated);
    width: auto;
    max-width: 90%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 5px 30px var(--overlay);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    border: 2px solid var(--separator);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.5rem;
    border-bottom: 2px solid var(--separator);
    background-color: var(--brand-accent);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--brand-main);
    margin: 0;
    display: flex;
    align-items: center;
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] footer {
    color: var(--neutral-lightest);
}

[data-theme="dark"] .modal-title,
[data-theme="dark"] .detail-section h3 {
    color: var(--brand-main);
}

.modal-close {
    border: none;
    background: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--content);
    transition: color 0.2s;
    padding: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.modal-close:hover {
    color: var(--alert);
    background-color: var(--alert-bg-translucent);
}

.modal-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.detail-grid {
    display: flex;
    flex-direction: column;
}

.detail-section {
    margin-bottom: 2rem;
    padding: 0.5rem;
    border-radius: 6px;
}

.detail-section h3 {
    color: var(--brand-main);
    border-bottom: 2px solid var(--separator);
    margin-top: 0;
    padding-bottom: 0.5rem;
    font-size: 1.2rem;
    font-weight: 700;
}

.detail-item {
    margin-bottom: 1.2rem;
}

.detail-label {
    font-weight: 700;
    display: block;
    margin-bottom: 0.3rem;
    color: var(--content);
}

.detail-value {
    display: block;
}

.detail-list {
    margin: 0;
    padding-left: 1.5rem;
}

.detail-list li {
    margin-bottom: 0.5rem;
}

.modal-color-preview {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    margin-right: 1rem;
    box-shadow: 0 2px 5px var(--overlay);
    border: 2px solid var(--separator);
    position: relative;
}

.modal-color-preview:hover::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    width: 120px;
    height: 120px;
    background-color: inherit;
    border-radius: 8px;
    border: 2px solid var(--separator);
    box-shadow: 0 5px 15px var(--overlay);
    z-index: 100;
    margin-left: 10px;
}

.modal-footnotes {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 2px solid var(--separator);
}

.modal-footnotes h3 {
    font-size: 1.2rem;
    margin-top: 0;
    color: var(--brand-main);
    font-weight: 700;
}

.footnote-list {
    padding-left: 1.5rem;
    margin: 0;
}

.footnote-item {
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
}

.footnote-link {
    color: var(--brand-main);
    text-decoration: underline;
    margin-right: 0.5rem;
    font-weight: 600;
}

footer {
    text-align: center;
    background-color: var(--brand-accent);
    color: var(--content);
    font-size: 0.95rem;
    border-top: 2px solid var(--separator);
}

footer a {
    color: var(--brand-main);
    text-decoration: underline;
    font-weight: 600;
}

[data-theme="dark"] footer a {
    color: var(--neutral-lightest);
}

footer a:hover {
    text-decoration: underline;
}

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

@media (max-width: 768px) {

    th,
    td {
        padding: 8px 10px;
        font-size: 13px;
    }

    .cell-content {
        max-height: 100px;
        overflow-y: auto;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .search-wrapper {
        flex-direction: column;
        align-items: flex-start;
    }

    #searchInput {
        max-width: none;
        width: 100%;
    }

    .theme-toggle {
        top: 0.5rem;
        right: 0.5rem;
    }

    .column-origin,
    .column-toxicity {
        display: none;
    }
}

.error-message {
    color: var(--alert);
    border: 1px solid var(--alert-border);
    border-radius: 4px;
    background-color: var(--alert-surface);
    padding: 1rem;
    text-align: center;
}

.sort-ascending {
    background: var(--brand-accent);
}

.sort-descending {
    background: var(--highlight-light);
}

sub {
    font-size: 75%;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
    bottom: -0.25em;
}

.column-color_swatch {
    width: 24px;
    text-align: center;
}