:root {
    --bg: #f6f8f5;
    --surface: #ffffff;
    --ink: #17211c;
    --muted: #637066;
    --line: #dce5dc;
    --green: #24755a;
    --green-dark: #174d3d;
    --lime: #d9ed92;
    --amber: #f2bd5b;
    --blue: #4d84a9;
    --danger: #b65d4b;
    --shadow: 0 18px 46px rgba(32, 49, 40, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-header {
    background:
        linear-gradient(135deg, rgba(23, 77, 61, 0.94), rgba(36, 117, 90, 0.82)),
        url("https://images.unsplash.com/photo-1490645935967-10de6ba17061?auto=format&fit=crop&w=1800&q=80") center/cover;
    color: #fff;
}

.topbar,
main {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.topbar {
    position: fixed;
    top: 12px;
    left: 50%;
    z-index: 40;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: 8px;
    transition: min-height 180ms ease, background 180ms ease, border-color 180ms ease, box-shadow 180ms ease, color 180ms ease;
}

.topbar.is-scrolled {
    min-height: 52px;
    background: rgba(255, 255, 255, 0.78);
    border-color: rgba(220, 229, 220, 0.82);
    box-shadow: 0 12px 34px rgba(23, 33, 28, 0.12);
    color: var(--ink);
    backdrop-filter: blur(14px);
}

.topbar.is-scrolled .nav-links {
    color: rgba(23, 33, 28, 0.78);
}

.brand {
    font-weight: 800;
    letter-spacing: 0;
    font-size: 1.05rem;
}

.menu-toggle {
    display: none;
    position: relative;
    align-items: center;
    min-height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    padding: 0 10px 0 34px;
    font-size: 0.84rem;
    font-weight: 800;
    cursor: pointer;
}

.menu-toggle span {
    position: absolute;
    left: 11px;
    width: 14px;
    height: 2px;
    display: block;
    border-radius: 999px;
    background: currentColor;
}

.menu-toggle span:nth-child(1) {
    top: 12px;
}

.menu-toggle span:nth-child(2) {
    top: 18px;
}

.menu-toggle span:nth-child(3) {
    top: 24px;
}

.nav-links {
    display: flex;
    gap: 22px;
    color: rgba(255, 255, 255, 0.86);
    font-size: 0.94rem;
}

.hero {
    width: min(1180px, calc(100% - 32px));
    min-height: 440px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    align-items: center;
    gap: 40px;
    padding: 110px 0 72px;
}

.hero-copy h1 {
    max-width: 760px;
    margin: 10px 0 18px;
    font-size: clamp(2.2rem, 5vw, 4.9rem);
    line-height: 1.02;
    letter-spacing: 0;
}

.hero-copy p {
    max-width: 650px;
    margin: 0;
    color: rgba(255, 255, 255, 0.88);
    font-size: 1.05rem;
}

.eyebrow {
    margin: 0;
    color: var(--lime);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 800;
}

.eyebrow-muted {
    color: #24755a;
}

.hero-panel {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 8px;
    padding: 22px;
    backdrop-filter: blur(14px);
}

.hero-panel span,
.metric span,
.hint,
.note {
    color: var(--muted);
    font-size: 0.88rem;
}

.hero-panel span,
.hero-panel p {
    color: rgba(255, 255, 255, 0.78);
}

.hero-panel strong {
    display: block;
    margin: 10px 0;
    font-size: 1.7rem;
}

.metrics-grid,
.workspace,
.analysis-grid {
    margin-top: 24px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.metric,
.control-panel,
.results,
.analysis-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric {
    padding: 18px;
}

.metric strong {
    display: block;
    margin-top: 4px;
    font-size: 1.65rem;
}

.workspace {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.control-panel {
    position: sticky;
    top: 16px;
    padding: 18px;
}

.panel-section + .panel-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

h2 {
    margin: 0 0 14px;
    font-size: 1.25rem;
}

label {
    display: block;
    margin: 14px 0 7px;
    color: #354138;
    font-size: 0.9rem;
    font-weight: 700;
}

input,
select,
button {
    font: inherit;
}

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

input[type="search"],
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    background: #fbfdfb;
    color: var(--ink);
}

input[type="range"] {
    width: 100%;
    accent-color: var(--green);
}

.upload-box {
    display: block;
    margin: 10px 0;
    padding: 14px;
    border: 1px dashed var(--green);
    border-radius: 8px;
    background: #f4faf6;
    cursor: pointer;
}

.upload-box span,
.status-text {
    display: block;
    color: var(--muted);
    font-size: 0.86rem;
}

.upload-box strong {
    display: block;
    margin-top: 4px;
    color: var(--green-dark);
    overflow-wrap: anywhere;
}

.status-text {
    margin: 8px 0 0;
}

.dataset-validation {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.dataset-validation strong {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.dataset-validation p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.validation-grid,
.summary-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.validation-grid span,
.summary-chips span {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 4px 9px;
    background: #edf6f1;
    color: var(--green-dark);
    font-size: 0.78rem;
    font-weight: 800;
}

.validation-grid span.warn {
    background: #fff5df;
    color: #8a5a12;
}

.preset-grid,
.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.preset-grid button {
    flex: 1 1 120px;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfb;
    color: var(--green-dark);
    font-size: 0.86rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.preset-grid button:hover,
.ghost-button:hover {
    border-color: var(--green);
    background: #edf8f1;
}

.preset-grid button.active {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32), 0 8px 18px rgba(36, 117, 90, 0.18);
}

.weight-row {
    display: grid;
    grid-template-columns: 94px minmax(0, 1fr) 28px;
    gap: 10px;
    align-items: center;
    margin: 10px 0;
}

.weight-row label {
    margin: 0;
    text-transform: capitalize;
}

.weight-row output {
    text-align: right;
    font-weight: 800;
    color: var(--green-dark);
}

.results,
.analysis-card {
    padding: 20px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.section-heading.compact {
    margin-bottom: 6px;
}

.ghost-button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbf9;
    color: var(--green-dark);
    min-height: 40px;
    padding: 0 14px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
}

.top-cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.summary-panel {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    margin-bottom: 18px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfb;
}

.summary-panel h3 {
    margin: 4px 0 0;
    font-size: 1rem;
}

.decision-summary {
    margin: -2px 0 18px;
    padding: 16px;
    border: 1px solid #cfe0d4;
    border-left: 5px solid var(--green);
    border-radius: 8px;
    background: #f7fbf8;
}

.decision-summary h3 {
    margin: 5px 0 6px;
    font-size: 1.05rem;
}

.decision-summary p:last-child {
    margin: 0;
    color: #354138;
}

.food-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: #fbfdfb;
}

.rank-badge {
    display: inline-grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    border-radius: 999px;
    background: var(--green);
    color: #fff;
    font-weight: 900;
}

.food-card h3 {
    margin: 12px 0 5px;
    font-size: 1.05rem;
}

.food-card p {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 0.9rem;
}

.score-line {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: 0.88rem;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

th,
td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 0.9rem;
    vertical-align: middle;
}

th {
    background: #eef5ee;
    color: #354138;
    font-size: 0.78rem;
    text-transform: uppercase;
}

th:nth-child(1),
td:nth-child(1) {
    width: 54px;
}

th:nth-child(2),
td:nth-child(2) {
    width: 58px;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6),
th:nth-child(7),
td:nth-child(7) {
    width: 92px;
}

.sort-button {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-weight: 900;
    padding: 0;
    text-transform: uppercase;
}

.sort-button.active {
    color: var(--green-dark);
}

.name-cell {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.name-cell strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.name-cell span {
    color: var(--muted);
    font-size: 0.78rem;
}

.compare-check {
    width: 18px;
    height: 18px;
    accent-color: var(--green);
}

.table-action {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--green-dark);
    width: fit-content;
    min-height: 28px;
    padding: 0 8px;
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
}

.table-action:hover {
    border-color: var(--green);
    background: #edf8f1;
}

tbody tr:hover {
    background: #f6faf6;
}

.cluster-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 9px;
    background: #edf6f1;
    color: var(--green-dark);
    font-weight: 800;
    font-size: 0.78rem;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 14px;
    color: var(--muted);
    font-size: 0.9rem;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0;
}

.page-link,
.page-ellipsis {
    min-width: 38px;
    min-height: 38px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-right: 0;
    background: #fff;
    color: var(--green-dark);
    font-weight: 800;
    font-size: 0.86rem;
}

.page-link:first-child {
    border-radius: 8px 0 0 8px;
}

.page-link:last-child {
    border-right: 1px solid var(--line);
    border-radius: 0 8px 8px 0;
}

.page-link.active {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.page-link:disabled {
    background: #f1f4f1;
    color: #9aa69d;
    cursor: not-allowed;
}

.compare-panel {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.compare-panel h3 {
    margin: 0;
    font-size: 1.05rem;
}

.ghost-button.small {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.86rem;
}

.compare-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.compare-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfb;
    padding: 14px;
}

.compare-card > strong {
    display: block;
    margin-bottom: 4px;
}

.compare-card > span {
    color: var(--muted);
    font-size: 0.86rem;
}

.compare-card dl,
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.compare-card dl div,
.detail-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 8px;
}

.compare-card dt,
.detail-grid span {
    color: var(--muted);
    font-size: 0.76rem;
}

.compare-card dd {
    margin: 2px 0 0;
    font-weight: 900;
}

.compare-card p,
.detail-reason {
    margin: 0;
    color: #354138;
    font-size: 0.88rem;
}

.analysis-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
    gap: 18px;
    margin-bottom: 40px;
}

.bar-chart {
    display: grid;
    gap: 10px;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(150px, 220px) minmax(0, 1fr) 54px;
    gap: 10px;
    align-items: center;
}

.bar-label {
    overflow: hidden;
    color: #354138;
    font-size: 0.86rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    height: 14px;
    overflow: hidden;
    border-radius: 999px;
    background: #edf6f1;
}

.bar-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--green), var(--blue));
}

.bar-row strong {
    text-align: right;
    font-size: 0.82rem;
}

.chart-wrap {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    grid-template-areas:
        "y plot"
        ". x";
    gap: 8px 10px;
    align-items: center;
}

.axis-title {
    color: #354138;
    font-size: 0.84rem;
    font-weight: 800;
}

.y-title {
    grid-area: y;
    writing-mode: vertical-rl;
    rotate: 180deg;
    justify-self: center;
}

.x-title {
    grid-area: x;
    text-align: center;
}

.scatter {
    grid-area: plot;
    position: relative;
    height: 360px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(90deg, rgba(36, 117, 90, 0.08) 1px, transparent 1px),
        linear-gradient(0deg, rgba(36, 117, 90, 0.08) 1px, transparent 1px),
        #fbfdfb;
    background-size: 64px 64px;
    overflow: hidden;
}

.chart-tick {
    position: absolute;
    z-index: 1;
    color: #6f7d72;
    font-size: 0.72rem;
    pointer-events: none;
}

.y-tick {
    left: 8px;
    transform: translateY(50%);
}

.x-tick {
    bottom: 6px;
    transform: translateX(-50%);
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.86rem;
}

.chart-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    display: inline-block;
    border-radius: 50%;
}

.legend-dot.good {
    background: var(--green);
}

.legend-dot.warn {
    background: var(--amber);
}

.legend-dot.risk {
    background: var(--danger);
}

.dot {
    position: absolute;
    z-index: 2;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    transform: translate(-50%, 50%);
    background: var(--blue);
    border: 2px solid #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.dot.good {
    background: var(--green);
}

.dot.warn {
    background: var(--amber);
}

.dot.risk {
    background: var(--danger);
}

.method-list {
    display: grid;
    gap: 12px;
}

.method-list div {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfb;
}

.method-list p,
.note {
    margin: 5px 0 0;
}

.note {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(23, 33, 28, 0.58);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    width: min(760px, 100%);
    max-height: min(720px, calc(100vh - 36px));
    overflow: auto;
    background: #fff;
    border-radius: 8px;
    border: 1px solid var(--line);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
    padding: 22px;
}

.detail-reason {
    margin-bottom: 14px;
    padding: 12px;
    border-radius: 8px;
    background: #edf8f1;
}

.detail-grid div strong {
    display: block;
    margin-top: 3px;
}

@media (max-width: 920px) {
    .topbar {
        align-items: center;
        display: grid;
        grid-template-columns: 1fr auto;
        min-height: 62px;
    }

    .topbar.is-scrolled {
        min-height: 54px;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .nav-links {
        grid-column: 1 / -1;
        display: none;
        width: 100%;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
        padding: 8px 0 4px;
        color: inherit;
    }

    .topbar.menu-open {
        background: rgba(255, 255, 255, 0.9);
        border-color: rgba(220, 229, 220, 0.9);
        color: var(--ink);
        backdrop-filter: blur(14px);
    }

    .topbar.menu-open .nav-links {
        display: grid;
    }

    .nav-links a {
        min-height: 34px;
        display: grid;
        place-items: center;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.62);
        font-size: 0.84rem;
        font-weight: 800;
    }

    .hero,
    .workspace,
    .analysis-grid {
        grid-template-columns: 1fr;
    }

    .hero {
        min-height: auto;
    }

    .metrics-grid,
    .top-cards,
    .compare-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .action-row {
        width: 100%;
    }

    .action-row .ghost-button {
        flex: 1 1 120px;
    }

    .control-panel {
        position: static;
    }
}

@media (max-width: 620px) {
    .topbar {
        min-height: 58px;
        padding: 10px 12px;
    }

    .topbar.is-scrolled {
        min-height: 52px;
    }

    .nav-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .hero {
        padding-top: 98px;
    }

    .hero-copy h1 {
        font-size: clamp(2rem, 11vw, 3.2rem);
    }

    .hero-panel {
        padding: 16px;
    }

    .control-panel,
    .results,
    .analysis-card {
        padding: 14px;
    }

    .metrics-grid,
    .top-cards,
    .compare-grid {
        grid-template-columns: 1fr;
    }

    .summary-panel {
        grid-template-columns: 1fr;
    }

    .table-wrap {
        overflow-x: visible;
    }

    th:nth-child(4),
    td:nth-child(4),
    th:nth-child(5),
    td:nth-child(5) {
        display: none;
    }

    th:nth-child(6),
    td:nth-child(6),
    th:nth-child(7),
    td:nth-child(7) {
        width: 82px;
    }

    .bar-row {
        grid-template-columns: 1fr 80px;
    }

    .bar-track {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .preset-grid button,
    .ghost-button {
        min-height: 36px;
        font-size: 0.82rem;
    }

    .table-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .pagination {
        justify-content: flex-start;
    }

    .page-link,
    .page-ellipsis {
        min-width: 34px;
        min-height: 34px;
    }

    .chart-wrap {
        grid-template-columns: 28px minmax(0, 1fr);
    }

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

@media print {
    .app-header,
    .control-panel,
    .analysis-grid,
    .ghost-button,
    .top-cards {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    main,
    .workspace {
        width: 100%;
        display: block;
        margin: 0;
    }

    .results {
        box-shadow: none;
        border: 0;
        padding: 0;
    }

    table {
        min-width: 0;
    }
}
