:root {
    color-scheme: light;
    --bg: #f5f7fa;
    --panel: #ffffff;
    --ink: #1d2935;
    --muted: #667789;
    --line: #d9e0e7;
    --line-soft: #edf1f5;
    --green: #1f7a6d;
    --blue: #2f6fdd;
    --amber: #c27a20;
    --coral: #c85f5a;
    --radius: 8px;
    --shadow: 0 8px 24px rgba(21, 35, 52, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    letter-spacing: 0;
    color: var(--ink);
    background: var(--bg);
}

body {
    margin: 0;
    min-width: 320px;
}

a {
    color: var(--green);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

code {
    padding: 2px 6px;
    border-radius: 5px;
    background: #eef3f7;
    color: #344254;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 64px;
    padding: 10px clamp(16px, 4vw, 44px);
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 8px;
    background: var(--green);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
    line-height: 1.1;
}

.brand small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.78rem;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.92rem;
}

.shell {
    width: min(1240px, calc(100% - 32px));
    margin: 28px auto 54px;
}

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

.page-head h1 {
    margin: 5px 0 8px;
    font-size: clamp(1.35rem, 2.4vw, 2.05rem);
    line-height: 1.15;
}

.page-head p {
    max-width: 780px;
    margin: 0;
    color: var(--muted);
}

.back-link {
    display: inline-block;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.panel {
    margin-top: 18px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

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

.section-title h2 {
    margin: 0;
    font-size: 1.08rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin: 18px 0;
}

.stat,
.metric {
    min-width: 0;
    padding: 17px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.stat span,
.metric span {
    display: block;
    color: var(--muted);
    font-size: 0.84rem;
}

.stat strong {
    display: block;
    margin-top: 8px;
    font-size: 1.7rem;
    line-height: 1;
}

.upload-panel {
    padding: 16px;
}

.upload-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: end;
}

.file-input span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 0.84rem;
}

.file-input input {
    width: 100%;
    min-height: 44px;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfd;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 7px;
    background: var(--green);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button:hover {
    background: #18665b;
}

.flash {
    margin: 14px 0;
    padding: 12px 14px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: #fff;
}

.flash-success {
    border-color: #a8d5c8;
    background: #eef9f5;
    color: #14594f;
}

.flash-error {
    border-color: #e9aaa6;
    background: #fff1f0;
    color: #8b302c;
}

.table-wrap,
.sheet-preview {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

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

.data-table th,
.data-table td {
    padding: 12px 13px;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f7fafc;
    color: #415164;
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.data-table.compact th,
.data-table.compact td {
    padding: 9px 10px;
}

.strong-link {
    font-weight: 800;
}

.muted {
    color: var(--muted);
    font-size: 0.88rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #f8fafc;
    color: #415164;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.badge-ready {
    border-color: #9fcfbd;
    background: #ebf8f3;
    color: #126050;
}

.badge-processing {
    border-color: #e7ca8a;
    background: #fff8e8;
    color: #80530c;
}

.badge-failed {
    border-color: #dfa19e;
    background: #fff1f0;
    color: #8b302c;
}

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

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-top: 18px;
}

.chart-panel {
    min-height: 310px;
}

.chart-title {
    margin: 0 0 12px;
    font-size: 1rem;
}

.chart-svg {
    display: block;
    width: 100%;
    height: auto;
}

.chart-label {
    fill: #415164;
    font-size: 12px;
}

.chart-value {
    fill: #263341;
    font-size: 12px;
    font-weight: 700;
}

.chart-axis {
    stroke: #cbd5df;
    stroke-width: 1;
}

.chart-bar:nth-of-type(4n + 1) {
    fill: var(--green);
}

.chart-bar:nth-of-type(4n + 2) {
    fill: var(--blue);
}

.chart-bar:nth-of-type(4n + 3) {
    fill: var(--amber);
}

.chart-bar:nth-of-type(4n + 4) {
    fill: var(--coral);
}

.chart-fallback {
    color: var(--muted);
}

.processing-panel {
    border-color: #b7d8d1;
    background: #f8fcfb;
}

.progress-track {
    width: 100%;
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #dbe8e6;
}

.progress-track span {
    display: block;
    min-width: 4%;
    height: 100%;
    border-radius: inherit;
    background: var(--green);
    transition: width 0.25s ease;
}

.processing-message {
    margin: 12px 0 0;
    color: var(--muted);
}

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

.metric {
    box-shadow: none;
}

.metric strong {
    display: block;
    margin-top: 8px;
    overflow-wrap: anywhere;
    font-size: 1.15rem;
}

.metric small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
}

.sheet-table {
    border-collapse: collapse;
    min-width: 900px;
    background: #fff;
    table-layout: fixed;
}

.sheet-table th,
.sheet-table td {
    min-width: 96px;
    max-width: 160px;
    height: 32px;
    padding: 6px 8px;
    border: 1px solid #dfe5eb;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.82rem;
}

.sheet-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    min-width: 48px;
    background: #eef3f7;
    color: #415164;
    text-align: center;
}

.sheet-table tbody th {
    left: 0;
    z-index: 1;
}

.range-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.range-list span {
    padding: 6px 9px;
    border-radius: 999px;
    background: #eef3f7;
    color: #415164;
    font-size: 0.84rem;
}

.setup-list p {
    margin: 0 0 12px;
}

@media (max-width: 900px) {
    .stat-grid,
    .chart-grid,
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .topbar,
    .page-head,
    .upload-form {
        align-items: stretch;
        flex-direction: column;
    }

    .upload-form,
    .stat-grid,
    .chart-grid,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .shell {
        width: min(100% - 20px, 1240px);
        margin-top: 18px;
    }

    .panel {
        padding: 14px;
    }
}
