:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-muted: #eef3f8;
    --text: #15202b;
    --text-soft: #5f6c7b;
    --text-faint: #8996a6;
    --line: #dbe3ec;
    --line-strong: #b8c6d6;
    --primary: #2764c7;
    --primary-soft: #e7f0ff;
    --success: #12805c;
    --success-soft: #dff6ed;
    --warning: #d97706;
    --warning-soft: #fff4df;
    --danger: #c24132;
    --danger-soft: #fff0ee;
    --well-default: #f8fafc;
    --well-data: #e0f2fe;
    --well-gene: #eef2ff;
    --well-selected: #ffe7a8;
    --well-control: #dcfce7;
    --radius: 8px;
    --shadow: 0 12px 30px rgba(37, 56, 88, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

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

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
}

.app-shell {
    width: min(1800px, 100%);
    margin: 0 auto;
    padding: 20px;
}

.app-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

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

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1.1;
}

h2 {
    font-size: 17px;
    line-height: 1.2;
}

.header-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.header-stats span {
    padding: 7px 10px;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text-soft);
    font-size: 13px;
    white-space: nowrap;
}

.main-content {
    display: grid;
    grid-template-columns: minmax(280px, 330px) minmax(0, 1fr) minmax(340px, 430px);
    gap: 16px;
    align-items: start;
}

.left-panel,
.right-panel,
.center-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.panel-heading,
.panel-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-heading {
    justify-content: flex-start;
}

.panel-heading p,
.panel-title-row p {
    margin-top: 4px;
    color: var(--text-soft);
    font-size: 13px;
}

.step-badge {
    display: inline-flex;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid #c8dcff;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 700;
}

.upload-area {
    display: grid;
    place-items: center;
    gap: 6px;
    min-height: 132px;
    padding: 18px;
    border: 1.5px dashed var(--line-strong);
    border-radius: var(--radius);
    background: #fbfdff;
    color: var(--text-soft);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.18s ease, background 0.18s ease;
}

.upload-area:hover,
.upload-area.is-dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.upload-icon {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
}

.upload-area strong {
    color: var(--text);
}

.upload-area small,
.muted-line {
    color: var(--text-faint);
    font-size: 13px;
}

.file-info,
.notice,
.selection-info,
.well-chip-list {
    margin-top: 10px;
    padding: 9px 10px;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text-soft);
    font-size: 13px;
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.notice {
    background: var(--success-soft);
    border-color: #b8ead7;
    color: #116149;
}

.field-row {
    display: grid;
    gap: 6px;
    margin-bottom: 10px;
}

.field-row label {
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 700;
}

input[type="text"],
select {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
}

input[type="text"]:focus,
select:focus {
    outline: 2px solid #bfd5ff;
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 13px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.btn-primary {
    width: 100%;
    background: var(--primary);
    color: white;
}

.btn-secondary {
    width: 100%;
    background: var(--success);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger-soft);
    border-color: #ffd0ca;
    color: var(--danger);
}

.btn-ghost {
    background: #fbfdff;
    border-color: var(--line);
    color: var(--text-soft);
}

.btn-sm {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 13px;
}

.btn-large {
    min-height: 46px;
    font-size: 15px;
}

.icon-btn {
    display: inline-grid;
    width: 30px;
    height: 30px;
    place-items: center;
    background: transparent;
    border-radius: 50%;
    color: var(--text-soft);
    cursor: pointer;
    font-size: 18px;
}

.icon-btn:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.gene-list {
    display: grid;
    gap: 8px;
    margin: 12px 0;
}

.list-heading,
.result-heading {
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.gene-item,
.experimental-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.gene-item {
    padding: 10px;
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.item-name {
    color: var(--text);
    font-weight: 800;
    word-break: break-word;
}

.item-meta {
    margin-top: 2px;
    color: var(--text-faint);
    font-size: 12px;
    word-break: break-word;
}

.group-create {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.experimental-groups {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.experimental-group-item {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.well-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 40px;
    align-items: center;
}

.well-chip {
    padding: 4px 8px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text-soft);
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
}

.well-chip:hover {
    border-color: var(--danger);
    color: var(--danger);
}

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

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

.group-quick-grid {
    display: grid;
    grid-template-columns: minmax(240px, 0.8fr) minmax(320px, 1.2fr);
    gap: 14px;
}

.group-box {
    min-width: 0;
    padding: 12px;
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.plate-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.plate-scroll {
    overflow-x: auto;
    padding-bottom: 2px;
}

.plate-grid {
    display: grid;
    width: 100%;
    grid-template-columns: 24px repeat(12, minmax(38px, 1fr));
    grid-template-rows: 24px repeat(8, minmax(38px, 1fr));
    gap: 5px;
    min-width: 560px;
    padding: 10px;
    background: #edf3f9;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    user-select: none;
}

.well-label {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 800;
}

.well {
    position: relative;
    display: flex;
    aspect-ratio: 1;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2px;
    background: var(--well-default);
    border: 2px solid var(--line);
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    overflow: hidden;
}

.well:hover {
    border-color: var(--primary);
}

.well.has-data {
    box-shadow: inset 0 0 0 4px var(--well-data);
}

.well.assigned {
    background: var(--well-gene);
    border-color: #9aa9ff;
}

.well.control {
    background: var(--well-control);
    border-color: var(--success);
}

.well.experimental {
    border-color: var(--warning);
}

.well.selected {
    background: var(--well-selected) !important;
    border-color: var(--warning) !important;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.22);
}

.well-gene {
    max-width: 92%;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 900;
    line-height: 1.1;
}

.well-ct {
    display: block;
    width: calc(100% - 8px);
    max-width: 44px;
    margin-top: 1px;
    padding: 1px 2px;
    background: rgba(255, 255, 255, 0.78);
    border-radius: 999px;
    color: var(--text-soft);
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 10px;
    font-weight: 900;
    line-height: 1.15;
    overflow: visible;
    text-align: center;
    white-space: nowrap;
}

.plate-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
    color: var(--text-soft);
    font-size: 13px;
}

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

.legend-dot {
    width: 14px;
    height: 14px;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
}

.selected-dot {
    background: var(--well-selected);
}

.gene-dot {
    background: var(--well-gene);
}

.control-dot {
    background: var(--well-control);
}

.exp-dot {
    background: var(--warning-soft);
}

.data-dot {
    background: var(--well-data);
}

.action-panel {
    display: grid;
    gap: 10px;
    padding: 12px;
    margin-bottom: 14px;
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.precision-field {
    margin-bottom: 0;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 86px 76px;
    gap: 8px;
}

.action-buttons .btn {
    min-width: 0;
    padding-inline: 8px;
}

.results-panel {
    min-height: 520px;
}

.results-container {
    min-height: 420px;
}

.empty-state {
    display: grid;
    min-height: 340px;
    place-content: center;
    gap: 8px;
    color: var(--text-soft);
    text-align: center;
}

.empty-state strong {
    color: var(--text);
}

.result-block {
    display: grid;
    gap: 14px;
}

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

.gene-chart {
    padding: 12px;
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.chart-title {
    margin-bottom: 10px;
    color: var(--text);
    font-weight: 900;
}

.bar-chart {
    display: flex;
    min-height: 190px;
    align-items: end;
    gap: 12px;
    padding: 10px 8px 0;
    border-left: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.bar-item {
    display: grid;
    min-width: 56px;
    flex: 1;
    align-items: end;
    gap: 6px;
    text-align: center;
}

.bar-value {
    color: var(--text-soft);
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 11px;
    font-weight: 800;
}

.bar-track {
    display: flex;
    height: 120px;
    align-items: end;
    justify-content: center;
}

.bar-fill {
    width: min(44px, 72%);
    min-height: 2px;
    border-radius: 6px 6px 0 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.bar-label {
    min-height: 34px;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.results-table {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 13px;
}

th,
td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    background: var(--surface-muted);
    color: var(--text-soft);
    font-weight: 900;
}

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

tr:hover td {
    background: #fbfdff;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 20;
    max-width: min(420px, calc(100vw - 36px));
    padding: 12px 14px;
    background: #163a5f;
    border-radius: var(--radius);
    color: white;
    box-shadow: 0 16px 36px rgba(21, 32, 43, 0.22);
    font-size: 14px;
}

.toast.is-error {
    background: var(--danger);
}

[hidden] {
    display: none !important;
}

@media (max-width: 1450px) {
    .main-content {
        grid-template-columns: minmax(280px, 310px) minmax(0, 1fr);
    }

    .right-panel {
        grid-column: 1 / -1;
    }

    .results-panel {
        min-height: 0;
    }
}

@media (max-width: 980px) {
    .app-shell {
        padding: 12px;
    }

    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-stats {
        justify-content: flex-start;
    }

    .main-content {
        grid-template-columns: 1fr;
    }

    .panel-title-row {
        flex-direction: column;
    }

    .plate-actions {
        justify-content: flex-start;
    }

    .action-buttons {
        grid-template-columns: 1fr 1fr 1fr;
    }

    .group-quick-grid,
    .group-create {
        grid-template-columns: 1fr;
    }

    .bar-chart {
        overflow-x: auto;
    }

    .bar-item {
        min-width: 72px;
    }
}

@media (max-width: 560px) {
    .app-shell {
        padding: 8px;
    }

    .panel {
        padding: 12px;
    }

    .plate-grid {
        grid-template-columns: 22px repeat(12, 40px);
        grid-template-rows: 22px repeat(8, 40px);
        min-width: 530px;
    }

    .well-gene {
        font-size: 10px;
    }

    .well-ct {
        width: calc(100% - 6px);
        font-size: 8px;
    }
}
