:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --ink: #17212b;
    --muted: #667085;
    --line: #d9dee7;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --warn: #b45309;
    --danger: #b42318;
    --success-bg: #e8f7ee;
    --error-bg: #fdecec;
    --shadow: 0 18px 50px rgba(16, 24, 40, 0.16);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
}

.shell {
    width: min(1380px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.login-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 20px;
}

.login-panel {
    display: grid;
    width: min(420px, 100%);
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 24px;
}

.login-panel label {
    display: grid;
    gap: 6px;
    color: #344054;
    font-weight: 700;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
    min-width: 0;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 18px;
}

.search {
    display: flex;
    flex: 1 1 360px;
    gap: 8px;
    min-width: 0;
}

.filters-row {
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
}

.filters-row select,
.filters-row input[type="search"],
.filters-row button {
    flex: 0 0 auto;
}

.filters-row input[type="search"] {
    flex: 1 1 260px;
    min-width: 220px;
}

.top-actions {
    display: flex;
    align-items: center;
    flex: 0 1 auto;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
}

.main-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin: -8px 0 22px;
    padding-bottom: 2px;
}

.main-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: #344054;
    font-weight: 700;
    padding: 0 13px;
    text-decoration: none;
    white-space: nowrap;
}

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

input[type="search"],
input[type="text"],
input[type="password"],
select,
input[type="file"] {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 9px 11px;
}

select {
    width: 150px;
}

button {
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    padding: 0 16px;
    white-space: nowrap;
}

button:hover {
    background: var(--accent-dark);
}

.notice {
    border-radius: 6px;
    margin: 0 0 12px;
    padding: 11px 14px;
}

.notice.success {
    background: var(--success-bg);
    color: #166534;
}

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

.upload-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 18px;
}

.panel p {
    margin: 6px 0 0;
    color: var(--muted);
}

.danger-panel {
    border-color: #f2b8b5;
    background: #fffafa;
}

.checkline {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.checkline input {
    width: 16px;
    height: 16px;
}

.danger-button {
    background: var(--danger);
}

.danger-button:hover {
    background: #8f1d14;
}

.table-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
}

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

.section-heading span {
    color: var(--muted);
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    padding: 0 12px;
    text-decoration: none;
    white-space: nowrap;
}

.link-button:hover {
    background: var(--accent-dark);
}

.secondary-link {
    background: #475467;
    flex: 0 1 auto;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.secondary-link:hover {
    background: #344054;
}

.text-link {
    color: var(--accent-dark);
    font-weight: 700;
}

.inline-upload-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 8px;
    min-width: 300px;
}

.small-button {
    min-height: 36px;
    padding: 0 12px;
}

.management-grid {
    display: grid;
    grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.uploaded-panel {
    min-width: 0;
}

.narrow-panel {
    max-width: 560px;
}

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

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

.wide-section {
    grid-column: 1 / -1;
}

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

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

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

.tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    padding: 10px 12px 0;
}

.tab-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: #eef2f6;
    color: #344054;
    padding: 0 14px;
}

.tab-button:hover,
.tab-button.active {
    background: var(--surface);
    color: var(--accent-dark);
}

.tab-button span {
    border-radius: 999px;
    background: #dfe7f0;
    color: #475467;
    font-size: 12px;
    padding: 2px 7px;
}

.tab-button.active span {
    background: #d7f0ea;
    color: var(--accent-dark);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.tab-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
}

.analysis-table,
.detail-table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    background: #eef2f6;
    color: #344054;
    font-size: 12px;
    text-transform: uppercase;
}

.sortable-header {
    cursor: pointer;
    user-select: none;
}

.sortable-header::after {
    content: " <>";
    color: #98a2b3;
    font-size: 11px;
}

.sortable-header[data-sort-direction="asc"]::after {
    content: " ^";
    color: var(--accent-dark);
}

.sortable-header[data-sort-direction="desc"]::after {
    content: " v";
    color: var(--accent-dark);
}

.analysis-table tbody tr {
    cursor: pointer;
}

.analysis-table tbody tr:hover {
    background: #f1faf8;
}

.analysis-table .batch-heading {
    cursor: default;
}

.analysis-table .batch-heading td {
    background: #dfeeea;
    color: var(--accent-dark);
    font-weight: 800;
    text-transform: uppercase;
}

.analysis-table .batch-heading:hover {
    background: transparent;
}

td strong {
    display: block;
    margin-bottom: 3px;
}

td span,
.muted {
    color: var(--muted);
}

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.48);
    padding: 22px;
    z-index: 50;
}

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

.modal {
    display: flex;
    flex-direction: column;
    width: min(980px, 100%);
    max-height: min(760px, calc(100vh - 44px));
    min-height: 0;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    min-height: 36px;
    padding: 0;
    background: #e5e7eb;
    color: var(--ink);
    font-size: 24px;
    line-height: 1;
}

.modal-close:hover {
    background: #d1d5db;
}

.modal-header {
    flex: 0 0 auto;
    border-bottom: 1px solid var(--line);
    padding: 20px 58px 16px 20px;
}

.modal-header span {
    display: inline-block;
    margin-top: 6px;
    color: var(--muted);
}

.modal-export {
    margin-top: 12px;
    width: fit-content;
}

.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 18px 20px 24px;
}

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

.metric {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px;
}

.metric b {
    display: block;
    font-size: 22px;
    margin-bottom: 4px;
}

.metric span {
    color: var(--muted);
}

.detail-block {
    margin-top: 20px;
}

.detail-block h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    background: #edf7f5;
    color: var(--accent-dark);
    font-weight: 700;
    padding: 4px 8px;
}

.badge.absent {
    background: #fff3e6;
    color: var(--warn);
}

@media (max-width: 760px) {
    .shell {
        width: min(100% - 20px, 1380px);
        padding-top: 18px;
    }

    .topbar,
    .top-actions,
    .search:not(.filters-row) {
        align-items: stretch;
        flex-direction: column;
    }

    .upload-grid,
    .management-grid,
    .metric-grid,
    .report-grid,
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .section-heading,
    .section-actions,
    .tab-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .filters-row {
        flex-wrap: nowrap;
    }

    h1 {
        font-size: 23px;
    }

    th,
    td {
        padding: 10px;
    }
}
