:root {
    color-scheme: light;
    --bg: #f4f7f7;
    --surface: #ffffff;
    --surface-2: #edf4f2;
    --text: #18212a;
    --muted: #62717c;
    --line: #d6e0df;
    --line-strong: #aebfbc;
    --accent: #0f766e;
    --accent-strong: #115e59;
    --accent-soft: #dff5f1;
    --secondary: #315a7d;
    --secondary-soft: #e2edf7;
    --danger: #b42318;
    --danger-soft: #fee4e2;
    --warning: #a65f00;
    --warning-soft: #fff3d8;
    --success: #087443;
    --success-soft: #dcfae6;
    --shadow: 0 14px 35px rgba(15, 23, 42, 0.08);
    --shadow-strong: 0 22px 60px rgba(15, 23, 42, 0.2);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        linear-gradient(180deg, #dfeeea 0, rgba(244, 247, 247, 0) 330px),
        var(--bg);
    color: var(--text);
}

button,
input,
select,
textarea {
    font: inherit;
}

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

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
    padding: 4px 2px 0;
}

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

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

.save-state {
    min-width: 180px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbfb;
    color: var(--muted);
    padding: 10px 12px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.summary-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.summary-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 10px 12px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.summary-item span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.summary-item strong {
    display: block;
    font-size: 21px;
    line-height: 1.1;
}

.summary-item.warning strong {
    color: var(--warning);
}

.summary-item:nth-child(2) strong {
    color: var(--success);
}

.toolbar,
.submit-bar {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    padding: 8px;
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn {
    min-height: 36px;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    background: #f9fbfb;
    color: var(--text);
    padding: 7px 11px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.btn:hover {
    border-color: var(--secondary);
    background: var(--secondary-soft);
    transform: translateY(-1px);
}

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

.btn.primary,
.btn.submit {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
}

.btn.primary:hover,
.btn.submit:hover {
    background: var(--accent-strong);
}

.btn.danger {
    border-color: #f6b7ae;
    background: #fff8f7;
    color: var(--danger);
}

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

.grid-wrap {
    overflow: auto;
    max-height: calc(100vh - 288px);
    min-height: 390px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.07);
}

.data-grid {
    width: max(1510px, 100%);
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}

.data-grid th,
.data-grid td {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 5px;
    vertical-align: top;
}

.data-grid th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #20313a;
    color: #ffffff;
    font-size: 11px;
    text-align: left;
    white-space: nowrap;
}

.data-grid tr:nth-child(even) td {
    background: #fbfcfd;
}

.data-grid tr.has-error td {
    background: var(--warning-soft);
}

.data-grid tr.has-duplicate td {
    background: #fce7f3;
}

.data-grid tr.has-duplicate td:first-child {
    box-shadow: inset 4px 0 0 #be185d;
}

.data-grid tr.is-ready td:first-child {
    box-shadow: inset 4px 0 0 var(--success);
}

.data-grid input,
.data-grid select {
    width: 100%;
    height: 32px;
    border: 1px solid #c8d5d3;
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
    padding: 5px 7px;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.data-grid input:focus,
.data-grid select:focus {
    border-color: var(--accent);
    background: #ffffff;
    box-shadow: 0 0 0 3px var(--accent-soft), inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.data-grid .invalid {
    border-color: var(--danger);
    background: var(--danger-soft);
}

.data-grid input.has-recommendation {
    background-image: linear-gradient(90deg, rgba(15, 118, 110, 0.08), rgba(255, 255, 255, 0));
}

.row-number {
    display: grid;
    min-height: 34px;
    place-items: center;
    color: var(--muted);
    font-weight: 800;
}

.col-number {
    width: 48px;
}

.col-actions {
    width: 96px;
}

.cell-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
}

.icon-btn {
    display: grid;
    height: 32px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    color: var(--muted);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

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

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

.submit-bar {
    position: sticky;
    bottom: 0;
    z-index: 25;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 10px;
    padding: 10px 12px;
}

.submit-bar strong,
.submit-bar span {
    display: block;
}

.submit-bar span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.toast {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    z-index: 50;
    display: none;
    width: min(520px, calc(100vw - 32px));
    min-height: 86px;
    border-radius: 10px;
    background: #17202a;
    color: #ffffff;
    padding: 18px 20px 16px;
    box-shadow: var(--shadow-strong);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
}

.toast-title {
    margin-bottom: 6px;
    font-size: 18px;
    font-weight: 900;
}

.toast-message {
    color: rgba(255, 255, 255, 0.9);
}

.toast-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
}

.toast-action {
    min-height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    padding: 7px 11px;
    font-weight: 900;
    cursor: pointer;
}

.toast-action:hover {
    background: rgba(255, 255, 255, 0.24);
}

.toast-action.primary {
    border-color: #ffffff;
    background: #ffffff;
    color: #17352f;
}

.toast.success {
    background: var(--success);
}

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

.toast.warning {
    background: var(--warning);
}

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

    .topbar,
    .toolbar,
    .submit-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .save-state {
        width: 100%;
    }

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

    .grid-wrap {
        max-height: calc(100vh - 340px);
    }

    .btn.submit {
        width: 100%;
    }
}
