:root {
    --bg: #f3efe8;
    --panel: #fffdf9;
    --border: rgba(31, 42, 55, 0.18);
    --text: #1f2a37;
    --muted: #5f6c7a;
    --accent: #2f6c8f;
    --accent-strong: #18364c;
    --error: #8b2f25;
    --info: #205a8a;
    --shadow: 0 22px 50px rgba(24, 54, 76, 0.07);
    --radius: 24px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(47, 108, 143, 0.08), transparent 32%),
        linear-gradient(180deg, #fbf8f3 0%, #f3efe8 100%);
    line-height: 1.6;
}

h1, h2, h3 {
    font-family: Georgia, "Times New Roman", serif;
    letter-spacing: -0.03em;
}

a {
    color: var(--accent-strong);
}

.site-header {
    position: sticky;
    top: 0;
    border-bottom: 1px solid rgba(31, 42, 55, 0.1);
    background: rgba(251, 248, 243, 0.9);
    backdrop-filter: blur(10px);
}

.container {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
}

.site-header .container {
    padding: 1.5rem 0;
}

.brand {
    display: inline-block;
    margin-bottom: 0.35rem;
    font-size: 1.6rem;
    font-weight: 700;
    text-decoration: none;
    font-family: Georgia, "Times New Roman", serif;
}

.tagline {
    margin: 0;
    color: var(--muted);
}

main.container {
    padding: 2rem 0 3rem;
}

.panel {
    padding: 1.5rem;
    border: 1px solid rgba(31, 42, 55, 0.12);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.hero {
    padding: 2rem;
}

.search-form {
    position: relative;
    margin-top: 1rem;
}

.search-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.search-input-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.search-input-row input {
    flex: 1;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

.filter-form input {
    width: 100%;
    padding: 0.8rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.98rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

.search-input-row button,
.back-nav {
    margin-bottom: 1.25rem;
}

.search-input-row button {
    flex-shrink: 0;
    padding: 0.9rem 1.8rem;
    border: none;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.2s ease;
}

.search-input-row button:hover {
    background: var(--accent-strong);
}

.button {
    display: inline-block;
    padding: 0.85rem 1.4rem;
    border: none;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    transition: background 0.2s ease;
}

.button.secondary {
    background: rgba(47, 108, 143, 0.12);
    color: var(--accent-strong);
}

.search-input-row button:hover,
.button:hover {
    background: var(--accent-strong);
}

.button.secondary:hover {
    background: rgba(47, 108, 143, 0.22);
    color: var(--accent-strong);
}

.drug-forms {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.drug-forms-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.drug-forms-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.matching-form-filter {
    margin-bottom: 1rem;
}

.drug-form-chip {
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.drug-form-chip:hover,
.drug-form-chip.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.comparison-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.comparison-card {
    padding: 1rem;
    border: 1px solid rgba(31, 42, 55, 0.12);
    border-radius: var(--radius);
    background: #fff;
}

.comparison-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
}

.quick-choices {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}

.quick-choice-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

.quick-choice-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    min-width: 110px;
}

.quick-choice-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.quick-chip {
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f2ede4;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.quick-chip:hover {
    background: rgba(47, 108, 143, 0.1);
    border-color: var(--accent);
}

.quick-chip.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.filter-grid label {
    display: block;
    margin-bottom: 0.45rem;
    font-weight: 700;
}

.filter-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.result-card,
.content-block {
    margin-top: 1rem;
    padding: 1rem;
    border: 1px solid rgba(31, 42, 55, 0.12);
    border-radius: 14px;
    background: #fff;
}

.results-panel {
    padding: 1.25rem;
}

.status-pill {
    display: inline-block;
    padding: 0.4rem 0.7rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
}

.status-pill.match {
    background: rgba(47, 108, 143, 0.14);
    color: var(--accent-strong);
}

.status-pill.exclude {
    background: rgba(139, 47, 37, 0.12);
    color: var(--error);
}

.details-list,
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem;
}

.details-list div {
    padding: 0.75rem;
    border-radius: 12px;
    background: rgba(31, 42, 55, 0.05);
}

.details-list dt {
    font-size: 0.85rem;
    color: var(--muted);
}

.details-list dd {
    margin: 0.35rem 0 0;
}

.subtle {
    color: var(--muted);
}

.message {
    padding: 0.75rem 1rem;
    border-radius: 12px;
}

.message.error {
    background: rgba(139, 47, 37, 0.1);
    color: var(--error);
}

.message.info {
    background: rgba(32, 90, 138, 0.1);
    color: var(--info);
}

.message.empty {
    background: rgba(31, 42, 55, 0.06);
}

.raw-block {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    white-space: pre-wrap;
    border-radius: 12px;
    background: #f2ede4;
}

.ingredient-list {
    margin: 0;
    padding-left: 1.2rem;
}

.ingredient-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ingredient-chip {
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    background: #f2ede4;
    border: 1px solid var(--border);
    font-size: 0.92rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid rgba(31, 42, 55, 0.1);
    text-align: left;
    vertical-align: top;
}

.matching-products-wrap {
    overflow-x: visible;
}

.matching-products-table {
    table-layout: fixed;
}

.matching-products-table th,
.matching-products-table td {
    padding: 0.5rem 0.55rem;
    font-size: 0.86rem;
    line-height: 1.24;
    overflow-wrap: anywhere;
    word-break: normal;
}

.matching-products-table th {
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}

.table-sort-button {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    text-align: left;
    cursor: pointer;
}

.table-sort-button::after {
    content: "↕";
    font-size: 0.78rem;
    color: var(--muted);
}

.table-sort-button[data-sort-direction="asc"]::after {
    content: "↑";
    color: var(--accent-strong);
}

.table-sort-button[data-sort-direction="desc"]::after {
    content: "↓";
    color: var(--accent-strong);
}

/* 1=Product 2=Form 3=Strength 4=Route 5=NDCs 6=Labeler 7=Include Match 8=Exclude Match */
.matching-products-table th:nth-child(1),
.matching-products-table td:nth-child(1) {
    width: 17%;
}

.matching-products-table th:nth-child(2),
.matching-products-table td:nth-child(2) {
    width: 10%;
}

.matching-products-table th:nth-child(3),
.matching-products-table td:nth-child(3) {
    width: 12%;
}

.matching-products-table th:nth-child(4),
.matching-products-table td:nth-child(4) {
    width: 11%;
}

.matching-products-table th:nth-child(5),
.matching-products-table td:nth-child(5) {
    width: 13%;
}

.matching-products-table th:nth-child(6),
.matching-products-table td:nth-child(6) {
    width: 15%;
}

.matching-products-table th:nth-child(7),
.matching-products-table td:nth-child(7),
.matching-products-table th:nth-child(8),
.matching-products-table td:nth-child(8) {
    width: 11%;
}

/* NDCs (5) small text */

.matching-products-table td:nth-child(5) {
    font-size: 0.82rem;
}

.matching-products-table td:nth-child(1) a {
    overflow-wrap: anywhere;
}

@media (max-width: 640px) {
    .search-input-row {
        flex-direction: column;
    }

    .search-input-row button,
    .button {
        width: 100%;
        text-align: center;
    }
}

/* ── Tagline link ── */
.tagline-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.tagline-link:hover {
    color: var(--accent-strong);
}

/* ── Footer ── */
.site-footer {
    border-top: 1px solid rgba(31, 42, 55, 0.1);
    margin-top: 3rem;
    padding: 2rem 0 1.5rem;
}

.footer-inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 18px;
    align-items: center;
}

.footer-brand {
    font-size: 0.9rem;
    color: var(--text);
    white-space: nowrap;
}

.footer-nav {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 0.86rem;
}

.footer-nav a {
    color: var(--muted);
    text-decoration: underline;
    text-decoration-color: rgba(47, 108, 143, 0.3);
    text-underline-offset: 0.16em;
}

.footer-nav a:hover {
    color: var(--accent);
}

.footer-email {
    font-size: 0.86rem;
    color: var(--muted);
    white-space: nowrap;
    text-decoration: underline;
    text-decoration-color: rgba(47, 108, 143, 0.3);
    text-underline-offset: 0.16em;
}

.footer-email:hover {
    color: var(--accent);
}

@media (max-width: 860px) {
    .footer-inner {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .footer-nav {
        justify-content: flex-start;
    }
}

/* ── Site navigation ── */
.site-nav {
    display: flex;
    align-items: center;
    gap: 0;
    margin-top: 0.5rem;
}

.site-nav a {
    font-size: 0.9rem;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    padding: 0.3rem 0.85rem;
    border-radius: 999px;
    transition: background 0.15s, color 0.15s;
}

.site-nav a:hover {
    color: var(--accent);
    background: rgba(47, 108, 143, 0.08);
}

.site-nav a:first-child {
    padding-left: 0;
    margin-right: 0.5rem;
    padding-right: 0.85rem;
    border-right: 1px solid rgba(31, 42, 55, 0.14);
    border-radius: 0;
    font-weight: 400;
    font-size: 0.85rem;
}

/* ── Osmotic risk page ── */
.osmotic-panel .tagline {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.97rem;
}

.osmotic-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.osmotic-label {
    margin: 0 0 0.45rem;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tag {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f2ede4;
    font-size: 0.85rem;
}

.tag-risk {
    background: rgba(139, 47, 37, 0.09);
    border-color: rgba(139, 47, 37, 0.25);
    color: var(--error);
}

.tag-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.78rem;
}

.unii-code {
    display: inline-block;
    margin-left: 0.25rem;
    font-size: 0.68rem;
    font-family: monospace;
    opacity: 0.6;
    letter-spacing: 0.02em;
}

.osmotic-run-form {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
}

.osmotic-run-btn {
    font-size: 1rem;
    padding: 0.9rem 2rem;
}

.osmotic-run-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.osmotic-hint {
    margin: 0;
    font-size: 0.86rem;
    color: var(--muted);
    max-width: 480px;
}

.osmotic-summary {
    margin-top: 1rem;
}

.osmotic-results {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ingredient-group {
    margin-top: 0;
    padding: 0;
    overflow: hidden;
}

.ingredient-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.ingredient-summary::-webkit-details-marker {
    display: none;
}

.ingredient-summary::before {
    content: "▶";
    font-size: 0.7rem;
    color: var(--muted);
    transition: transform 0.15s;
    flex-shrink: 0;
}

details[open] > .ingredient-summary::before {
    transform: rotate(90deg);
}

.ingredient-name {
    font-weight: 700;
    font-size: 1rem;
}

.ingredient-count {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
}

.ingredient-products {
    padding: 0 1rem 1rem;
    overflow-x: auto;
}

.ingredient-products .data-table th,
.ingredient-products .data-table td {
    font-size: 0.86rem;
    padding: 0.55rem 0.6rem;
}

.sugar-alcohol-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    padding-top: 0.6rem;
}

.ndc-cell {
    font-size: 0.8rem;
    color: var(--muted);
    max-width: 180px;
    word-break: break-all;
}

.index-status {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.index-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: rgba(47, 108, 143, 0.12);
    color: var(--accent-strong);
    font-size: 0.8rem;
    font-weight: 700;
    margin-right: 0.4rem;
}

.tier-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.tier-high {
    background: #fde8e6;
    color: #7a1f18;
    border: 1px solid #f5c6c2;
}

.tier-moderate {
    background: #fef3e2;
    color: #7a4a0a;
    border: 1px solid #f5ddb0;
}

.tier-review {
    background: #eef2fb;
    color: #1e3a6e;
    border: 1px solid #c2d0f0;
}

.index-status code {
    font-family: monospace;
    font-size: 0.85em;
    background: #f2ede4;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

/* Sugar Alcohol Risk page */
.sa-panel {}

.sa-stat-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.sa-stat-card {
    flex: 1 1 100px;
    min-width: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
}

.sa-stat-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(47, 108, 143, 0.12);
}

.sa-stat-card.active {
    border-color: var(--accent);
    background: rgba(47, 108, 143, 0.06);
}

.sa-stat-number {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent-strong);
}

.sa-stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-top: 0.3rem;
}

.sa-stat-desc {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.15rem;
    text-align: center;
}

.sa-updated {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0;
}

.sa-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
}

.sa-search {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    outline: none;
}

.sa-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(47, 108, 143, 0.15);
}

.sa-search-count {
    white-space: nowrap;
    font-size: 0.85rem;
    color: var(--muted);
}

/* ── Responsive ── */
@media (max-width: 640px) {
    /* Header & nav */
    .site-header .container {
        padding: 1rem 0;
    }

    .brand {
        font-size: 1.3rem;
    }

    .site-nav {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    /* Search */
    .search-input-row {
        flex-direction: column;
    }

    .search-input-row button,
    .button {
        width: 100%;
        text-align: center;
    }

    /* Detail metadata grid — single column */
    .details-list,
    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Sugar alcohol toolbar — stack search and count */
    .sa-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .sa-search-count {
        text-align: center;
        white-space: normal;
    }

    /* Stat cards — two per row minimum */
    .sa-stat-card {
        flex: 1 1 80px;
    }

    .sa-stat-number {
        font-size: 1.5rem;
    }

    /* Tables — scroll horizontally */
    .ingredient-products,
    .content-block .data-table {
        overflow-x: auto;
        display: block;
    }

    /* Ingredient group summary — allow wrapping */
    .ingredient-summary {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Panel padding */
    .panel {
        padding: 1rem;
    }

    main.container {
        padding: 1rem 0 2rem;
    }
}
