:root {
    --bg: #e8edf2;
    --panel: #ffffff;
    --ink: #18212b;
    --muted: #6b7785;
    --line: #bcc8d3;
    --navy: #163a55;
    --navy-2: #245475;
    --active: #0f5d44;
    --hover-row: #fff3bd;
    --hover-col: #e7f4ff;
    --hover-cross: #ffd166;
    --selected: #ccebdc;
    --selected-strong: #7fc7a8;
    --warn-bg: #fff1c7;
    --warn-border: #e5a200;
    --danger-bg: #ffe2df;
    --danger-border: #c94a3d;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", Arial, sans-serif;
    line-height: 1.25;
    padding: 6px;
}

button,
select {
    font: inherit;
}

.operator-shell {
    width: min(100%, 1920px);
    margin: 0 auto;
}

.topbar {
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 4px 8px;
}

.brand {
    font-size: 20px;
    line-height: 1;
    font-weight: 850;
    color: var(--navy);
    white-space: nowrap;
}

.quick-links {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.quick-links a {
    color: #33485a;
    background: rgba(255, 255, 255, .75);
    border: 1px solid #cbd5df;
    border-radius: 6px;
    padding: 5px 9px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.quick-links a:hover {
    background: #fff;
    border-color: #8ea2b4;
}

.control-strip {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 46px;
    padding: 5px 7px;
    margin-bottom: 6px;
    background: var(--panel);
    border: 1px solid #cbd5df;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(20, 41, 60, .08);
    overflow: hidden;
}

.control-group {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding-right: 7px;
    border-right: 1px solid #dbe2e8;
    white-space: nowrap;
}

.control-group:last-child {
    padding-right: 0;
    border-right: 0;
}

.control-caption {
    margin-right: 2px;
    color: #596775;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.seg-btn,
.auto-btn {
    min-height: 32px;
    border: 1px solid #aebcc9;
    border-radius: 6px;
    background: #f5f8fa;
    color: #243544;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 800;
    transition: background .12s ease, border-color .12s ease, color .12s ease, transform .12s ease;
}

.seg-btn:hover,
.auto-btn:hover {
    background: #e8f0f5;
    border-color: #7890a5;
}

.seg-btn.active {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
}

.length-btn.active {
    background: #123e5f;
}

.species-btn {
    min-width: 36px;
    padding-left: 8px;
    padding-right: 8px;
}

.ex-btn {
    min-width: 35px;
    padding-left: 7px;
    padding-right: 7px;
}

.condition-btn {
    padding-left: 8px;
    padding-right: 8px;
}

.condition-btn[data-condition="frost"].active {
    background: #356d9c;
    border-color: #356d9c;
}

.condition-btn[data-condition="dry"].active {
    background: #8b641a;
    border-color: #8b641a;
}

.compact-select {
    height: 32px;
    border: 1px solid #aebcc9;
    border-radius: 6px;
    background: #fff;
    color: #243544;
    padding: 2px 26px 2px 8px;
    font-size: 14px;
    font-weight: 800;
}

.auto-btn {
    min-width: 49px;
    padding: 4px 7px;
    font-size: 11px;
    letter-spacing: .04em;
}

.auto-btn.active {
    background: #1d704f;
    border-color: #1d704f;
    color: #fff;
}

.table-card {
    background: var(--panel);
    border: 1px solid #aebdca;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(20, 41, 60, .1);
}

.table-meta {
    height: 34px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 3px 9px;
    background: #f4f7f9;
    border-bottom: 1px solid #c7d2dc;
}

.mode-summary {
    font-size: 15px;
    font-weight: 850;
    color: var(--navy);
    white-space: nowrap;
}

.table-hint {
    margin-left: auto;
    color: #687784;
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.speed-table-wrap {
    width: 100%;
    overflow: hidden;
}

.operator-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    border-spacing: 0;
}

.operator-table .label-col {
    width: 142px;
}

.operator-table th,
.operator-table td {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    text-align: center;
    overflow: hidden;
}

.operator-table th:last-child,
.operator-table td:last-child {
    border-right: 0;
}

.operator-table tbody tr:last-child td,
.operator-table tbody tr:last-child th {
    border-bottom: 0;
}

.corner-cell {
    height: 58px;
    background: var(--navy);
    color: #fff;
    padding: 5px 7px;
    text-align: left !important;
}

.corner-main {
    display: block;
    font-size: 17px;
    font-weight: 850;
}

.corner-sub {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 650;
    opacity: .75;
}

.pocket-head {
    height: 58px;
    background: var(--navy);
    color: #fff;
    padding: 3px 1px 2px;
    cursor: pointer;
    user-select: none;
    transition: background .08s ease, box-shadow .08s ease;
}

.pocket-head:hover,
.pocket-head:focus-visible {
    background: var(--navy-2);
    outline: none;
}

.pocket-number {
    display: block;
    font-size: clamp(18px, 1.45vw, 26px);
    line-height: 1;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.pocket-diameter {
    display: block;
    margin-top: 4px;
    font-size: clamp(9px, .72vw, 12px);
    line-height: 1;
    font-weight: 650;
    color: #cbdce8;
    white-space: nowrap;
}

.row-label {
    height: 54px;
    padding: 4px 8px;
    background: #e8eef3;
    color: #20313f;
    text-align: left !important;
    font-size: clamp(15px, 1.15vw, 20px);
    line-height: 1.05;
    font-weight: 850;
    white-space: nowrap;
}

.row-unit {
    display: block;
    margin-top: 3px;
    color: #7b8791;
    font-size: 10px;
    font-weight: 650;
}

.value-cell {
    height: 54px;
    padding: 2px 1px;
    background: #fff;
    color: #17222c;
    cursor: pointer;
    font-size: clamp(15px, 1.38vw, 23px);
    line-height: 1;
    font-weight: 900;
    letter-spacing: -.035em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    transition: background .06s linear, box-shadow .06s linear;
}

.value-cell.is-empty {
    color: #b2bbc2;
    font-weight: 650;
}

/* Перекрёстная подсветка: сначала строка, потом столбец, пересечение ярче. */
.operator-table .hover-row {
    background: var(--hover-row) !important;
}

.operator-table .hover-col {
    background: var(--hover-col) !important;
}

.operator-table .hover-cross {
    background: var(--hover-cross) !important;
    color: #151515 !important;
    box-shadow: inset 0 0 0 2px #d39b00;
}

.operator-table .pocket-head.hover-col,
.operator-table .pocket-head.hover-cross {
    background: #2b729f !important;
    color: #fff !important;
}

.operator-table .row-label.hover-row,
.operator-table .row-label.hover-cross {
    background: #e7be54 !important;
    color: #18212b !important;
}

/* Закреплённый рабочий карман виден даже после ухода мыши. */
.operator-table .selected-col {
    background: var(--selected) !important;
    box-shadow: inset 2px 0 0 var(--selected-strong), inset -2px 0 0 var(--selected-strong);
}

.operator-table .pocket-head.selected-col {
    background: var(--active) !important;
    color: #fff !important;
    box-shadow: inset 2px 0 0 #8de1bd, inset -2px 0 0 #8de1bd, inset 0 -3px 0 #8de1bd;
}

.operator-table .selected-col.hover-col,
.operator-table .selected-col.hover-cross {
    background: var(--hover-cross) !important;
    color: #151515 !important;
}

.operator-table .pocket-head.selected-col.hover-col,
.operator-table .pocket-head.selected-col.hover-cross {
    background: #1d7958 !important;
    color: #fff !important;
}

.work-pocket {
    margin-top: 6px;
    min-height: 58px;
    background: #fff;
    border: 1px solid #b9c6d1;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(20, 41, 60, .08);
    overflow: hidden;
}

.work-pocket-empty {
    padding: 15px 12px;
    color: #596875;
    font-size: 15px;
}

.work-pocket-content {
    padding: 7px 9px 8px;
}

.work-pocket-title {
    display: flex;
    align-items: baseline;
    gap: 9px;
    margin-bottom: 6px;
}

#selectedPocketTitle {
    color: var(--navy);
    font-size: 20px;
    font-weight: 900;
}

.selected-context {
    color: #64727e;
    font-size: 13px;
    font-weight: 750;
}

.selected-values {
    display: grid;
    grid-template-columns: repeat(5, minmax(110px, 1fr));
    gap: 5px;
}

.value-chip {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
    min-height: 40px;
    padding: 5px 8px;
    background: #eef3f6;
    border: 1px solid #d0d9e0;
    border-radius: 6px;
}

.value-chip-label {
    color: #52616e;
    font-size: 12px;
    font-weight: 800;
}

.value-chip-number {
    color: #142d40;
    font-size: 21px;
    line-height: 1;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.machine-notes {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
}

.machine-note {
    padding: 6px 9px;
    border: 1px solid var(--warn-border);
    border-radius: 6px;
    background: var(--warn-bg);
    color: #5b4300;
    font-size: 14px;
    font-weight: 850;
}

.machine-note.important {
    border-color: var(--danger-border);
    background: var(--danger-bg);
    color: #72271f;
}

.machine-note.info {
    border-color: #8eacc2;
    background: #edf6fc;
    color: #2b526d;
}

.secondary-panel {
    margin-top: 7px;
    background: #fff;
    border: 1px solid #c3ced8;
    border-radius: 7px;
    color: #41515f;
}

.secondary-panel summary {
    cursor: pointer;
    padding: 7px 10px;
    font-size: 13px;
    font-weight: 800;
}

.secondary-scroll {
    overflow-x: auto;
    padding: 0 8px 8px;
}

.grab-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.grab-table th,
.grab-table td {
    border: 1px solid #cdd6de;
    padding: 4px 5px;
    text-align: center;
}

.grab-table th {
    background: #e7edf2;
}

@media (max-width: 1450px) {
    body {
        padding: 4px;
    }

    .topbar {
        min-height: 34px;
        padding: 3px 5px;
    }

    .brand {
        font-size: 18px;
    }

    .quick-links a {
        padding: 4px 7px;
        font-size: 12px;
    }

    .control-strip {
        gap: 5px;
        min-height: 42px;
        padding: 4px 5px;
    }

    .control-group {
        gap: 2px;
        padding-right: 5px;
    }

    .control-caption {
        font-size: 10px;
    }

    .seg-btn,
    .compact-select {
        min-height: 30px;
        height: 30px;
        font-size: 13px;
    }

    .seg-btn {
        padding: 3px 7px;
    }

    .auto-btn {
        min-height: 30px;
        font-size: 10px;
    }

    .operator-table .label-col {
        width: 124px;
    }

    .corner-cell,
    .pocket-head {
        height: 54px;
    }

    .corner-main {
        font-size: 15px;
    }

    .row-label,
    .value-cell {
        height: 50px;
    }
}

@media (max-width: 1120px) {
    .brand {
        font-size: 16px;
    }

    .quick-links a:nth-child(2) {
        display: none;
    }

    .control-caption {
        display: none;
    }

    .control-strip {
        justify-content: space-between;
    }

    .operator-table .label-col {
        width: 108px;
    }

    .corner-main {
        font-size: 13px;
    }

    .corner-sub {
        font-size: 9px;
    }

    .row-label {
        padding-left: 5px;
    }

    .selected-values {
        grid-template-columns: repeat(5, 1fr);
    }

    .value-chip {
        padding-left: 5px;
        padding-right: 5px;
    }

    .value-chip-label {
        font-size: 10px;
    }

    .value-chip-number {
        font-size: 18px;
    }
}

@media (max-width: 900px) {
    .topbar {
        flex-wrap: wrap;
    }

    .quick-links {
        display: none;
    }

    .control-strip {
        flex-wrap: wrap;
        overflow: visible;
    }

    .operator-table .label-col {
        width: 96px;
    }

    .pocket-number {
        font-size: 14px;
    }

    .pocket-diameter {
        font-size: 8px;
    }

    .row-label,
    .value-cell {
        font-size: 12px;
    }
}

/* ===== Operator V2: понятный порядок Порода → Длина → EX → Режим → Сезон ===== */
.species-btn small {
    margin-left: 2px;
    font-size: 10px;
    font-weight: 750;
    opacity: .78;
}

.ex-group {
    position: relative;
    gap: 4px;
    padding: 3px 6px !important;
    border: 2px solid #d29a18 !important;
    border-radius: 8px;
    background: #fff8dc;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7);
}

.ex-caption {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-width: 86px;
    margin-right: 2px;
    line-height: 1;
    text-transform: none;
}

.ex-caption strong {
    color: #7b4b00;
    font-size: 18px;
    line-height: 1;
    letter-spacing: .03em;
}

.ex-caption small {
    margin-top: 3px;
    color: #765f2a;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0;
}

.ex-btn {
    min-width: 50px;
    min-height: 34px;
    padding: 4px 7px;
    border-color: #c4a14d;
    background: #fffdf4;
    color: #4d3b11;
    font-size: 16px;
    font-weight: 900;
}

.ex-btn:hover {
    background: #fff0b4;
    border-color: #a97800;
}

.ex-btn.active {
    background: #9a5a00;
    border-color: #774600;
    color: #fff;
    box-shadow: 0 0 0 2px #ffd86a, inset 0 -2px 0 rgba(0, 0, 0, .16);
}

.ex-group.needs-choice {
    border-color: #e29b00 !important;
    background: #fff3be;
    box-shadow: 0 0 0 2px rgba(226, 155, 0, .14);
}

.ex-group.choice-flash {
    animation: ex-choice-flash .7s ease;
}

@keyframes ex-choice-flash {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    50% { transform: translateX(3px); box-shadow: 0 0 0 4px rgba(226, 155, 0, .32); }
    75% { transform: translateX(-2px); }
}

.operator-guide {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    margin: 0 0 6px;
    padding: 5px 10px;
    border: 1px solid #d9b34b;
    border-radius: 8px;
    background: #fff9dc;
    color: #4a3b14;
    box-shadow: 0 1px 3px rgba(90, 66, 10, .08);
    font-size: 15px;
    font-weight: 750;
}

.operator-guide[hidden] {
    display: none !important;
}

.guide-step {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    opacity: .56;
    white-space: nowrap;
}

.guide-step > strong {
    display: inline-grid;
    place-items: center;
    min-width: 25px;
    height: 25px;
    padding: 0 5px;
    border-radius: 999px;
    background: #cbd3da;
    color: #33424e;
    font-size: 13px;
    font-weight: 950;
}

.guide-step.active {
    opacity: 1;
    color: #5a3a00;
    font-size: 16px;
}

.guide-step.active > strong {
    background: #d78b00;
    color: #fff;
}

.guide-step.done {
    opacity: .78;
    color: #315943;
}

.guide-step.done > strong {
    background: #327457;
    color: #fff;
}

.guide-arrow {
    color: #a88933;
    font-size: 18px;
    font-weight: 900;
}

.compact-select:disabled {
    opacity: .72;
    cursor: default;
    background: #eef2f4;
}

.operator-table.waiting-ex .value-cell {
    background: #f5f7f8;
    color: #c1c9cf;
}

@media (max-width: 1450px) {
    .ex-caption {
        min-width: 72px;
    }

    .ex-caption strong {
        font-size: 16px;
    }

    .ex-caption small {
        font-size: 8px;
    }

    .ex-btn {
        min-width: 44px;
        min-height: 30px;
        font-size: 14px;
        padding: 3px 5px;
    }

    .operator-guide {
        min-height: 34px;
        padding-top: 4px;
        padding-bottom: 4px;
        font-size: 14px;
    }

    .guide-step.active {
        font-size: 15px;
    }
}

@media (max-width: 1120px) {
    .ex-group .ex-caption {
        display: flex;
    }

    .ex-caption small,
    .species-btn small {
        display: none;
    }

    .ex-caption {
        min-width: auto;
        margin-right: 1px;
    }

    .ex-caption strong {
        font-size: 15px;
    }

    .operator-guide {
        justify-content: flex-start;
        overflow: hidden;
        font-size: 13px;
    }

    .guide-step.active {
        font-size: 14px;
    }
}
