:root {
    --bg: #f6f7f8;
    --text: #1d242b;
    --muted: #64717d;
    --line: #d9dee3;
    --panel: #ffffff;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
}

.page {
    width: min(1420px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 44px;
}

.main-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
}

.main-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    padding: 0 14px;
    font-weight: 800;
    text-decoration: none;
}

.main-nav a.active,
.main-nav a:hover {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(320px, 520px);
    gap: 24px;
    align-items: end;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(28px, 4vw, 44px);
    line-height: 1.05;
    letter-spacing: 0;
}

.topbar p,
.table-head span,
.metrics span {
    color: var(--muted);
}

.search span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-weight: 600;
}

.search-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.search-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

input,
select,
button,
.reset {
    min-height: 44px;
    border-radius: 6px;
    font: inherit;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    padding: 0 12px;
    background: #fff;
}

button,
.reset {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    padding: 0 14px;
    font-weight: 700;
    cursor: pointer;
}

.reset {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    background: #fff;
    color: var(--accent-dark);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 20px 0;
}

.result-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 20px;
}

.result-summary div {
    background: #fff;
    border: 1px solid var(--line);
    border-left: 5px solid var(--accent);
    border-radius: 8px;
    padding: 16px;
}

.result-summary strong {
    display: block;
    font-size: 30px;
    line-height: 1.05;
}

.result-summary span {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-weight: 700;
}

.metrics div {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.metrics strong {
    display: block;
    font-size: 26px;
    line-height: 1.1;
}

.metrics span {
    display: block;
    margin-top: 4px;
}

.table-wrap,
.notice,
.chart-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.table-wrap .dt-container {
    padding: 14px 18px 18px;
}

.table-wrap .dt-search input,
.table-wrap .dt-length select {
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 36px;
}

.table-wrap .dt-paging-button {
    border-radius: 6px !important;
}

.notice {
    padding: 18px;
}

.error {
    color: var(--danger);
}

.table-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

h2 {
    font-size: 20px;
    letter-spacing: 0;
}

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

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0;
    background: #fafbfb;
}

.num {
    text-align: right;
    white-space: nowrap;
}

.lot {
    font-weight: 800;
    white-space: nowrap;
}

.lot a {
    color: var(--accent-dark);
    text-decoration: none;
}

.lot a:hover {
    text-decoration: underline;
}

.reasons {
    max-width: 520px;
}

.badge {
    display: inline-block;
    min-width: 74px;
    border-radius: 999px;
    padding: 4px 9px;
    color: #fff;
    text-align: center;
    font-size: 13px;
    font-weight: 800;
}

.s0,
.s1 {
    background: #607080;
}

.s2 {
    background: #287a52;
}

.s3 {
    background: #a16207;
}

.s4 {
    background: #c2410c;
}

.s5 {
    background: #b42318;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 26px;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 0 0 20px;
}

.chart-panel {
    padding: 16px;
}

.chart-panel.wide {
    grid-column: 1 / -1;
}

.chart-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: baseline;
    margin-bottom: 12px;
}

.chart-head span {
    color: var(--muted);
    font-size: 14px;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 360px;
}

.chart-panel.wide .chart-box {
    height: 400px;
}

.chart-box canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.stats-table {
    margin-top: 20px;
}

.legal-page {
    max-width: 920px;
    margin-top: 20px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px;
}

.legal-page h2 {
    margin-top: 22px;
}

.legal-page h2:first-child {
    margin-top: 0;
}

.legal-page p {
    margin-top: 8px;
    line-height: 1.6;
}

.legal-page a {
    color: var(--accent-dark);
}

.detail-header {
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
}

.back-link {
    display: inline-flex;
    margin-bottom: 10px;
    color: var(--accent-dark);
    font-weight: 700;
    text-decoration: none;
}

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

.detail-metrics {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.state-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 20px;
}

.state-strip span,
.symptom-tags span,
.flag {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 700;
}

.state-strip strong {
    margin-left: 6px;
}

.reports-list {
    display: grid;
    gap: 14px;
}

.report-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.report-card-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.report-card-head h2 {
    margin-bottom: 4px;
}

.report-card-head p {
    color: var(--muted);
}

.report-grid,
.detail-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 0 0 14px;
}

.report-grid div,
.detail-list div {
    min-width: 0;
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

dd {
    margin: 3px 0 0;
}

.flag-row,
.symptom-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 12px 0;
}

.flag.hot {
    border-color: #f3b6ac;
    background: #fff3f0;
    color: var(--danger);
}

.report-text {
    margin-top: 12px;
}

.report-text h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.report-text p {
    line-height: 1.55;
}

details {
    margin-top: 14px;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

summary {
    cursor: pointer;
    color: var(--accent-dark);
    font-weight: 800;
}

.detail-list {
    grid-template-columns: 1fr;
    margin-top: 12px;
}

@media (max-width: 860px) {
    .topbar,
    .metrics,
    .result-summary,
    .search-grid,
    .charts-grid {
        grid-template-columns: 1fr;
    }

    .search-actions {
        justify-content: stretch;
        flex-direction: column;
    }

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

    table {
        min-width: 920px;
    }

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

    .report-card-head {
        display: block;
    }

    .report-card-head .badge {
        margin-top: 10px;
    }

    .chart-panel.wide {
        grid-column: auto;
    }

    .chart-head {
        display: block;
    }

    .chart-box,
    .chart-panel.wide .chart-box {
        height: 340px;
    }
}
