/* Business Mirror V2 — readiness screen.
   Industrial instrument panel for a sugar factory's maintenance floor, not a
   "startup dashboard": flat surfaces separated by lines (no shadows), color
   spent only on the readiness grading and the accent (focus/highlight), and
   every technical number set in a monospace face so it reads like an
   instrument readout. See tasks/05_screen_redesign.md for the source spec —
   the palette, type scale and layout below are copied from it verbatim. */

:root {
    /* Light theme (default: the floor is read in daylight). */
    --ground: #EEF1F3;
    --panel: #F8FAFC;
    --ink: #16212A;
    --ink-2: #46586A;
    --line: #C9D3DA;
    --accent: #BE6B2E;
    --ok: #35785E;
    --warn: #B5892A;
    --alert: #C2703B;
    --critical: #A34038;
    /* Cell colour = support maturity (заплатка 04), not state, not permission.
       Grey is the honest default for the NF export: MANUAL_RESPONSIBILITY. */
    --cell-manual: #C9D2D6;
    --cell-observed: #B9CDE6;
    --cell-candidate: #E6D9A8;
    --cell-confirmed: #BFD8C4;

    --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: ui-monospace, Consolas, monospace;
    --radius: 2px;
    --transition: 140ms ease;
}

@media (prefers-color-scheme: dark) {
    /* Fallback for the rare case JS did not run (see the inline bootstrap
       script in index.html, which normally sets data-theme before paint). */
    :root {
        --ground: #0F1620;
        --panel: #16212C;
        --ink: #DCE5EB;
        --ink-2: #93A6B4;
        --line: #263642;
        --accent: #D5843F;
        --ok: #4E9878;
        --warn: #CBA043;
        --alert: #D18A52;
        --critical: #C25A50;
    --cell-manual: #2B3640;
    --cell-observed: #2D4358;
    --cell-candidate: #4F4523;
    --cell-confirmed: #2F463A;
    }
}

:root[data-theme="light"] {
    --ground: #EEF1F3;
    --panel: #F8FAFC;
    --ink: #16212A;
    --ink-2: #46586A;
    --line: #C9D3DA;
    --accent: #BE6B2E;
    --ok: #35785E;
    --warn: #B5892A;
    --alert: #C2703B;
    --critical: #A34038;
    --cell-manual: #C9D2D6;
    --cell-observed: #B9CDE6;
    --cell-candidate: #E6D9A8;
    --cell-confirmed: #BFD8C4;
}

:root[data-theme="dark"] {
    --ground: #0F1620;
    --panel: #16212C;
    --ink: #DCE5EB;
    --ink-2: #93A6B4;
    --line: #263642;
    --accent: #D5843F;
    --ok: #4E9878;
    --warn: #CBA043;
    --alert: #D18A52;
    --critical: #C25A50;
    --cell-manual: #2B3640;
    --cell-observed: #2D4358;
    --cell-candidate: #4F4523;
    --cell-confirmed: #2F463A;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
}

body {
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.4;
    overflow: hidden;
}

button {
    font: inherit;
    color: inherit;
}

/* Technical identifiers, quantities, dates — anything read as an instrument
   value rather than prose. Applied to both HTML and SVG <text> elements. */
.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* Small uppercase captions: section headings, panel labels. */
.label {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-2);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* --- App shell: header + three-column body, fills the viewport exactly. */

#app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
}

#context-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 52px;
    padding: 0 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

#context-bar-left {
    display: flex;
    align-items: center;
    gap: 18px;
    min-width: 0;
    padding: 8px 0;
}

#app-mark {
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

/* Ссылка на экран назначения ролей (ТЗ №17). */
.nav-link {
    color: var(--ink-2);
    font-size: 13px;
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 3px 8px;
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--accent);
    border-color: var(--accent);
}

#breadcrumbs {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    flex-wrap: wrap;
}

.crumb {
    color: var(--ink-2);
    padding: 3px 6px;
    border-radius: var(--radius);
}

.crumb-root {
    font-style: italic;
}

button.crumb-link {
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color var(--transition), background-color var(--transition);
}

button.crumb-link:hover {
    color: var(--accent);
    background: var(--ground);
}

.crumb-active {
    color: var(--ink);
    font-weight: 600;
}

.crumb-sep {
    color: var(--line);
}

#context-bar-right {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 8px 0;
}

/* Search box: left of the shown-counter per spec. Results drop down below
   the input as an absolutely-positioned panel — it must float above the
   field/card body, not push the header taller or shift layout. */
#search-box {
    position: relative;
    flex: 0 1 240px;
    min-width: 140px;
}

#search-input {
    width: 100%;
    background: var(--ground);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    transition: border-color var(--transition);
}

#search-input::placeholder {
    color: var(--ink-2);
}

#search-input:focus-visible {
    outline: none;
    border-color: var(--accent);
}

#search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: max(100%, 380px);
    max-height: min(70vh, 520px);
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    z-index: 50;
}

.search-result-list {
    list-style: none;
    display: flex;
    flex-direction: column;
}

.search-result {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    padding: 9px 12px;
    text-align: left;
    cursor: pointer;
    color: inherit;
    font: inherit;
}

li:last-child > .search-result {
    border-bottom: none;
}

.search-result:hover,
.search-result:focus-visible {
    background: var(--ground);
}

.search-result-main {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.search-result-tech {
    flex: 0 0 auto;
    font-size: 12px;
}

.search-result-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-type {
    color: var(--ink-2);
}

.search-result-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.search-result-location {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--ink-2);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-readiness {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
}

.search-result-readiness-manual { color: var(--ink-2); }
.search-result-readiness-observed { color: #5A82B0; }
.search-result-readiness-candidate { color: var(--warn); }
.search-result-readiness-confirmed { color: var(--ok); }
.search-result-readiness-unknown { color: var(--ink-2); opacity: 0.6; }

.search-empty, .search-more {
    padding: 10px 12px;
    font-size: 12px;
    color: var(--ink-2);
}

.search-more {
    border-top: 1px solid var(--line);
}

#shown-counter {
    color: var(--ink-2);
    font-size: 13px;
    white-space: nowrap;
}

#up-btn {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 6px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
}

#up-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

#up-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Theme switch: a two-position rocker, not an animated pill — this is an
   instrument panel, not a mobile app. */
#theme-toggle {
    display: flex;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

#theme-toggle button {
    background: var(--panel);
    border: none;
    color: var(--ink-2);
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: color var(--transition), background-color var(--transition);
}

#theme-toggle button + button {
    border-left: 1px solid var(--line);
}

#theme-toggle button[aria-pressed="true"] {
    background: var(--ground);
    color: var(--accent);
    font-weight: 600;
}

#theme-toggle button:hover {
    color: var(--accent);
}

/* --- Three-column body: obstacles / field / card. ---------------------- */

#layout {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

/* --- Left: obstacles panel ---------------------------------------------- */

/* Левая колонка держит две панели — препятствия и категории. Рамка и
   прокрутка принадлежат колонке, а не отдельной панели, иначе панели
   прокручивались бы независимо и разъезжались. */
#left-panels {
    flex: 0 0 272px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}

#obstacles-panel,
#categories-panel {
    padding: 14px 16px;
    min-width: 0;
}

#categories-panel {
    border-top: 1px solid var(--line);
}

.panel-heading {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-2);
    margin-bottom: 8px;
}

.panel-summary {
    font-size: 12px;
    color: var(--ink-2);
    margin-bottom: 14px;
}

.panel-summary .mono {
    color: var(--ink);
}

.panel-note {
    font-size: 12px;
    color: var(--ink-2);
    font-style: italic;
}

.obstacles-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.obstacle-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 7px 8px;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    color: var(--ink);
    transition: background-color var(--transition), border-color var(--transition);
}

.obstacle-row:hover {
    background: var(--ground);
    border-color: var(--line);
}

.obstacle-row[aria-pressed="true"] {
    background: var(--ground);
    border-color: var(--accent);
}

.obstacle-title {
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
}

.obstacle-count {
    color: var(--ink-2);
    font-size: 13px;
}

.obstacle-row[aria-pressed="true"] .obstacle-count {
    color: var(--ink);
}

.obstacle-row:disabled {
    cursor: default;
    opacity: 0.55;
}

/* Small filled circle marking a support-maturity level — reused in the panel
   and the equipment card so both speak the same visual vocabulary as the
   cells. Colour = maturity, never severity (заплатка 04). */
.maturity-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
    margin-right: 6px;
}

.maturity-dot-manual { background: var(--ink-2); }
.maturity-dot-observed { background: #5A82B0; }
.maturity-dot-candidate { background: var(--warn); }
.maturity-dot-confirmed { background: var(--ok); }
.maturity-dot-unknown { background: var(--ink-2); opacity: 0.5; }

/* --- Center: hex field --------------------------------------------------- */

#field-container {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    background: var(--ground);
}

#hex-field {
    display: block;
    width: 100%;
    height: 100%;
}

.cell {
    cursor: pointer;
}

.cell-shape {
    stroke-width: 2px;
    transition: fill var(--transition), stroke var(--transition), opacity var(--transition);
}

/* Cell label: real HTML inside an SVG <foreignObject>, laid out by the
   browser (flexbox centering + line-clamp) instead of hand-measured text —
   see hex-field.js's header comment for why. pointer-events:none hands
   clicks straight through to .cell-shape underneath. */
.cell-text {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-align: center;
    overflow: hidden;
    pointer-events: none;
    font-family: var(--font-ui);
    color: var(--ink);
}

.cell-title-block {
    font-weight: 600;
    line-height: 1.15;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
    text-overflow: ellipsis;
}

.cell-title-block.mono {
    font-family: var(--font-mono);
    font-weight: 500;
}

.cell-subtitle-block {
    color: var(--ink-2);
    line-height: 1.15;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cell-subtitle-block .mono {
    font-variant-numeric: tabular-nums;
}

.cell:hover .cell-shape,
.cell:focus-visible .cell-shape {
    stroke: var(--accent);
}

.cell:focus-visible {
    outline: none;
}

/* Fill = support-maturity level (заплатка 04). For the NF export every cell
   with works is .cell-manual (grey) — the honest colour when there are no
   confirmed support cards. The reserved observed/candidate/confirmed fills
   are kept distinct so a future support level reads as a real change, not a
   shade of grey. */
.cell-manual .cell-shape { fill: var(--cell-manual); stroke: var(--ink-2); }
.cell-observed .cell-shape { fill: var(--cell-observed); stroke: #5A82B0; }
.cell-candidate .cell-shape { fill: var(--cell-candidate); stroke: var(--warn); }
.cell-confirmed .cell-shape { fill: var(--cell-confirmed); stroke: var(--ok); }

.cell-unknown .cell-shape { fill: var(--panel); stroke: var(--ink-2); stroke-dasharray: 4 3; }
.cell-more .cell-shape { fill: var(--panel); stroke: var(--line); stroke-dasharray: 3 3; }

/* Obstacle-filter state: the matching cells stay full-strength, everything
   else fades via opacity — the one channel the design system allows for
   this kind of transient emphasis. */
.cell-dimmed {
    opacity: 0.32;
}

.cell-match .cell-shape {
    stroke-width: 3px;
}

.field-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px 32px;
    text-align: center;
    max-width: 420px;
}

.field-status p {
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
}

.field-status-error p {
    color: var(--critical);
}

.field-status-empty p {
    color: var(--ink-2);
}

#field-retry-btn {
    margin-top: 14px;
    background: var(--ink);
    color: var(--panel);
    border: none;
    border-radius: var(--radius);
    padding: 8px 22px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

:root[data-theme="dark"] #field-retry-btn {
    background: var(--accent);
    color: var(--ground);
}

/* --- Right: equipment card ----------------------------------------------- */
/* A flex sibling, not an overlay: when it appears the field shrinks to make
   room instead of being covered (per spec — "поле сжимается, а не
   прячется под панелью"). */

#equipment-card {
    flex: 0 0 408px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-left: 1px solid var(--line);
}

#equipment-card[hidden] {
    display: none;
}

.card-header {
    flex: 0 0 auto;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
}

.card-close {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--ink-2);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 8px;
    transition: color var(--transition), border-color var(--transition);
}

.card-close:hover {
    color: var(--critical);
    border-color: var(--line);
}

.card-body {
    flex: 1 1 auto;
    padding: 4px 18px 18px;
    overflow-y: auto;
}

.card-section {
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}

.card-section:last-child {
    border-bottom: none;
}

.card-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-2);
    margin-bottom: 10px;
    font-weight: 600;
}

.card-loading, .card-empty {
    color: var(--ink-2);
    font-size: 13px;
}

.card-error {
    color: var(--critical);
    font-size: 13px;
    margin-bottom: 12px;
}

.retry-btn {
    background: var(--ink);
    color: var(--panel);
    border: none;
    border-radius: var(--radius);
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    font-size: 13px;
}

.info-grid dt {
    color: var(--ink-2);
}

.info-grid dd {
    color: var(--ink);
    text-align: right;
}

.readiness-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.axis-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    margin: 8px 0;
}

.axis-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    border-bottom: 1px solid var(--line);
    padding-bottom: 4px;
}

.axis-title {
    color: var(--ink-2);
    flex: 0 0 auto;
}

.axis-value {
    color: var(--ink);
    text-align: right;
    display: flex;
    align-items: center;
}

.coverage-line {
    font-size: 13px;
    color: var(--ink);
    margin-bottom: 4px;
}

.gap-kind-tag {
    display: inline-block;
    font-size: 11px;
    color: var(--ink-2);
    background: var(--ground);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1px 6px;
    margin-right: 8px;
    flex: 0 0 auto;
}

.gap-label {
    color: var(--ink);
    font-size: 13px;
}

.reason-list, .work-list, .norm-list, .doc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

.reason-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
    flex-wrap: wrap;
}

.work-list li, .norm-list li {
    background: var(--ground);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 9px 11px;
}

.work-kind, .norm-group {
    font-weight: 600;
    margin-bottom: 4px;
}

.work-dates, .work-meta, .norm-values {
    color: var(--ink-2);
    font-size: 12px;
}

.doc-list li {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--ground);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 11px;
}

.doc-kind {
    font-weight: 600;
    margin-right: auto;
}

.doc-badge {
    font-size: 11px;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: var(--radius);
    border: 1px solid transparent;
}

.doc-badge-ready {
    color: var(--ok);
    border-color: var(--ok);
}

.doc-badge-missing {
    color: var(--critical);
    border-color: var(--critical);
}

.doc-meta {
    color: var(--ink-2);
    font-size: 12px;
    width: 100%;
}

/* --- Small screens: card and panel give up dedicated columns. ----------- */

@media (max-width: 900px) {
    #left-panels {
        flex-basis: 200px;
    }

    #equipment-card {
        flex-basis: 100%;
        position: absolute;
        inset: 0;
        z-index: 20;
    }

    #layout {
        position: relative;
    }
}

@media (max-width: 640px) {
    #context-bar {
        padding: 8px 12px;
    }

    #left-panels {
        display: none;
    }
}

/* Пометка выведенного значения: тише основного текста, но читаемо —
   пользователь должен отличать вывод системы от факта из выгрузки. */
.recovered-note {
    font-size: 11px;
    color: var(--ink-2);
    font-style: italic;
}

/* Текущая роль в шапке (ТЗ №14): пользователь всегда видит, от чьего имени
   смотрит на данные. Непроверенный контекст помечается отдельно — молчаливая
   пустота неотличима от «данных нет», а это та подмена, против которой
   построены оси статусов. */
.role-badge {
    font-size: 12px;
    color: var(--ink-2);
    border: 1px solid var(--line, currentColor);
    border-radius: 10px;
    padding: 2px 8px;
    white-space: nowrap;
}

.role-badge-anonymous {
    color: var(--bad, #b3261e);
    font-style: italic;
}

/* Акты подтверждения роли в карточке объекта. */
.confirm-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 8px 0;
}

.scheme-tag-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.scheme-tag-input {
    flex: 1;
    font: inherit;
    padding: 4px 8px;
    border: 1px solid var(--line, currentColor);
    border-radius: 6px;
    background: transparent;
    color: inherit;
}

/* --- Временное окно в строке контекста (ТЗ №18) ---------------------------
   Третий раскрываемый элемент контракта §4. Панель абсолютная: строка
   контекста не должна менять высоту при раскрытии — иначе поле сот
   прыгает под курсором. */
.tw {
    position: relative;
}

.tw-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    white-space: nowrap;
}

.tw-toggle:hover {
    border-color: var(--accent);
}

.tw-panel {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    z-index: 40;
    min-width: 22rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
}

.tw-modes {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.6rem;
}

.tw-mode {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}

.tw-mode-active {
    border-color: var(--accent);
    background: var(--accent-soft, rgb(120 160 255 / 18%));
}

.tw-presets {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.6rem;
}

.tw-preset {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.3rem 0.45rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.tw-preset:hover:not(:disabled) {
    border-color: var(--border);
}

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

.tw-bounds {
    color: var(--text-muted);
    font-size: 0.85em;
}

.tw-custom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.tw-custom-label {
    width: 100%;
    color: var(--text-muted);
    font-size: 0.85em;
}

.tw-date {
    padding: 0.2rem 0.3rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.tw-apply {
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}

.tw-error {
    width: 100%;
    margin: 0.3rem 0 0;
    color: var(--danger, #d66);
    font-size: 0.85em;
}

/* Класс работы относительно окна. Намеренно без красного: «исполнение не
   наблюдается» — это отсутствие данных, а не нарушение. */
.work-window-class {
    display: inline-block;
    margin-top: 0.2rem;
    padding: 0.05rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.82em;
}

/* --- Тестовые данные ремонтного контура (ТЗ №19) ---------------------------
   Цветовую грамматику здесь не изобретаем (предмет ТЗ №20): текстовая метка
   и штриховка. Штриховка — диагональные полосы поверх обычного фона, чтобы
   пометка «тестовые данные» читалась на снимке экрана без наведения. */

#synthetic-toggle {
    position: relative;
}

.synth-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}

.synth-toggle-on {
    border-style: solid;
    border-color: var(--accent);
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 6px,
        color-mix(in srgb, var(--accent) 14%, transparent) 6px,
        color-mix(in srgb, var(--accent) 14%, transparent) 12px
    );
}

/* Постоянная плашка в шапке: видна на любом экране, пока включён показ
   тестовых данных. Скриншот с ней не спутаешь с заводским. */
.synthetic-banner {
    padding: 0.4rem 1rem;
    border-bottom: 2px solid var(--accent);
    background: repeating-linear-gradient(
        -45deg,
        color-mix(in srgb, var(--accent) 10%, var(--bg)),
        color-mix(in srgb, var(--accent) 10%, var(--bg)) 10px,
        var(--bg) 10px,
        var(--bg) 20px
    );
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
}

/* Метка у самой строки: попадает на снимок экрана вместе со значением. */
.synthetic-badge {
    display: inline-block;
    margin-right: 0.3rem;
    padding: 0.05rem 0.4rem;
    border: 1px dashed var(--accent);
    border-radius: 4px;
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 4px,
        color-mix(in srgb, var(--accent) 12%, transparent) 4px,
        color-mix(in srgb, var(--accent) 12%, transparent) 8px
    );
    color: var(--text);
    font-size: 0.78em;
    font-weight: 600;
    white-space: nowrap;
}

.synthetic-section {
    border: 1px dashed var(--accent);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
}

.synthetic-note {
    margin: 0.2rem 0;
}

.execution-fact-list {
    margin: 0.25rem 0 0;
    padding-left: 1rem;
    list-style: disc;
}

.execution-fact {
    margin-top: 0.15rem;
    font-size: 0.9em;
}

/* Селектор с двумя классами намеренно: строка факта живёт внутри .work-list,
   а `.work-list li` задаёт сплошную заливку и по специфичности (0,1,1) бьёт
   одиночный класс — штриховка тогда не появляется вовсе, и тестовая строка
   отличается от заводской только меткой. */
li.execution-fact.execution-fact-synthetic {
    /* штриховка всей строки факта: строка неотличима от заводской недопустимо */
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 8px,
        color-mix(in srgb, var(--accent) 6%, transparent) 8px,
        color-mix(in srgb, var(--accent) 6%, transparent) 16px
    );
}

.execution-fact-result {
    font-weight: 600;
}

/* --- Совмещённая грамматика цвета (ТЗ №20, контракт §6) --------------------
   Независимые каналы соты: кольцо сегментов (светофор контура), пять
   ступеней высоты (Action Volume), пурпурный пиксель маркера достоверности,
   штриховка пробела данных. Цвет — никогда не единственный канал: у каждого
   состояния есть форма обводки, а подписи приходят из словаря сервера. */

:root {
    --seg-not-observable: #98A6B0;
    /* Один фиксированный пурпурный цвет маркера (ODP-2026-07-20), от темы
       не зависит: маркер обязан читаться одинаково всегда. */
    --seg-marker: #8E44AD;
}

@media (prefers-color-scheme: dark) {
    :root { --seg-not-observable: #5E7080; }
}

:root[data-theme="light"] { --seg-not-observable: #98A6B0; }
:root[data-theme="dark"] { --seg-not-observable: #5E7080; }

.cell-ring .seg {
    fill: none;
    stroke-linecap: butt;
}

.seg-no_open_issue { stroke: var(--ok); }
.seg-attention_required { stroke: var(--warn); }
.seg-critical { stroke: var(--critical); }
.seg-not_observable { stroke: var(--seg-not-observable); }

/* Форма состояния — второй канал после цвета (читаемость без цвета и на
   монохромной печати): пунктир, насечка, двойная линия. */
.seg-shape-dashed { stroke-dasharray: 5 4; }
.seg-shape-notched { stroke-dasharray: 1.5 3.5; }
.seg-shape-echo { opacity: 0.9; }

.seg-marker {
    fill: var(--seg-marker);
    stroke: none;
}

/* Ступени высоты под сотой: заполнено столько, каков уровень Action Volume. */
.vol-bar { fill: var(--line); }
.vol-filled { fill: var(--ink-2); }

/* Штриховка поля, затронутого пробелом данных (детальный масштаб). */
.cell-hatch { pointer-events: none; }
.hatch-line { fill: var(--ink-2); opacity: 0.22; }

/* Строка «почему всё серое»: объяснение серости поля числами, поверх поля,
   не перекрывая соты целиком. */
.grey-note {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    padding: 8px 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    color: var(--ink-2);
}

.grey-note-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
}

.grey-note-reason::before {
    content: "·";
    margin-right: 6px;
    color: var(--accent);
}

.grey-note-foot {
    margin-top: 4px;
    font-size: 12px;
    opacity: 0.85;
}

/* Легенда грамматики цвета: кнопка в строке контекста и панель со словарём. */
.legend {
    position: relative;
}

.legend-toggle {
    font: inherit;
    font-size: 12.5px;
    padding: 4px 10px;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
}

.legend-toggle:hover { border-color: var(--accent); }

.legend-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    width: 360px;
    max-height: 70vh;
    overflow: auto;
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--ink);
}

.legend-block + .legend-block {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.legend-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.legend-meaning { color: var(--ink-2); }

.legend-disclaimer {
    font-size: 12px;
    color: var(--ink-2);
    margin-top: 2px;
}

.legend-state {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.legend-swatch {
    width: 28px;
    height: 14px;
    flex: 0 0 auto;
}

.legend-swatch .seg { fill: none; }

.legend-marker-swatch {
    display: inline-block;
    width: 6px;
    height: 6px;
    flex: 0 0 auto;
}

.legend-volume {
    display: inline-flex;
    gap: 1px;
    align-items: flex-end;
}

.legend-volume .vol-bar {
    display: inline-block;
    width: 14px;
    height: 3px;
    fill: none;
    background: var(--line);
}

.legend-volume .vol-filled {
    background: var(--ink-2);
}

/* Блок «Контуры» карточки объекта. */
.contour-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.contour-swatch {
    display: inline-block;
    width: 18px;
    height: 0;
    border-top: 4px solid;
    vertical-align: middle;
    margin-right: 6px;
}

/* Цвет и форма образца берутся из тех же классов, что сегмент на поле. */
.contour-swatch.seg-no_open_issue { border-color: var(--ok); }
.contour-swatch.seg-attention_required { border-color: var(--warn); border-top-style: double; border-top-width: 5px; }
.contour-swatch.seg-critical { border-color: var(--critical); border-top-style: dotted; }
.contour-swatch.seg-not_observable { border-color: var(--seg-not-observable); border-top-style: dashed; }

.contour-marker-note {
    font-size: 12px;
    color: var(--seg-marker);
    margin-top: 2px;
}

/* Блок варок карточки (ТЗ №22). Пометка кандидатной метрики выделена
   пунктиром: число варок — прочтение данных, пока технолог не подтвердил
   смысл стадий, и выглядеть подтверждённым фактом оно не должно. */
.boiling-list {
    list-style: none;
    margin: 0.3rem 0 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

.boiling-row {
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--ground);
}

.boiling-candidate {
    margin: 8px 0 0;
    padding: 6px 8px;
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
    font-size: 0.88em;
    color: var(--muted);
}

/* Пометка записи тестового набора актов (ТЗ №31). Пунктир — тот же приём, что
   у кандидатной метрики варок: выдуманное подтверждение не должно выглядеть
   как заводское, даже когда его показали по явному запросу. */
.synthetic-mark {
    padding: 2px 6px;
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
    font-size: 0.82em;
    color: var(--muted);
    white-space: nowrap;
}

.synthetic-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    font-size: 0.85em;
    color: var(--muted);
    cursor: pointer;
}

/* Экран процессов (ТЗ №33). Отраслевых слов в разметке нет: тот же экран
   показывает варку сахара и плавку стекла — разница только в данных. */
.page { padding: 12px 16px; overflow-y: auto; }
.process-item {
    margin-bottom: 14px;
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.process-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.condition-block {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
}
.condition-header { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.term-list { margin: 4px 0 0; padding-left: 16px; }
.term-row { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.condition-actions { display: flex; gap: 6px; margin-top: 6px; }

/* Реестр верифицированных данных (ТЗ №35). */
.check-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.check-form input { min-width: 260px; }
.registry-facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
    margin: 6px 0 0;
    font-size: 12px;
}
.registry-facts dt { color: var(--ink-2); }
.registry-facts dd { margin: 0; }
