/*
   Бизнес-аналитика: эффективность использования персонала.

   Отдельный файл, чтобы не конфликтовать с основной витриной: все классы
   с префиксом .an- , переменные визуализации объявлены локально на .an-viz.
   */

.an-viz {
    color-scheme: light;

    /* Категориальные слоты: работа / дорога / ожидание / простой.
       Порядок и значения — из проверенной палитры (проходит CVD-контроль). */
    --an-series-work: #00693a;
    --an-series-travel: #1b75bc;
    --an-series-wait: #bf1f2f;
    --an-series-idle: #eda100;

    /* Спрос/доступно — свои цвета, независимые от палитры структуры смены. */
    --an-pair-demand: #1b75bc;
    --an-pair-supply: #bf1f2f;

    --an-surface: var(--bg-surface, #ffffff);
    --an-surface-subtle: var(--bg-surface-subtle, #f8f9f8);
    --an-ink: var(--text-primary, #181a1b);
    --an-ink-soft: var(--text-secondary, #697077);
    --an-ink-muted: var(--text-muted, #8d959e);
    --an-line: var(--border-color, #e4e6e3);
    --an-good: var(--status-success-text, #15803d);
    --an-warn: var(--status-warning-text, #b45309);
    --an-bad: var(--status-danger-text, #dc2626);
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .an-viz {
        color-scheme: dark;
        --an-series-work: #1a8f56;
        --an-series-travel: #1b75bc;
        --an-series-wait: #bf1f2f;
        --an-series-idle: #b87500;
    }
}

:root[data-theme="dark"] .an-viz {
    color-scheme: dark;
    --an-series-work: #1a8f56;
    --an-series-travel: #1b75bc;
    --an-series-wait: #bf1f2f;
    --an-series-idle: #b87500;
}

/* оболочка */

/* Общий класс для «Эффект» (an-modal) и «Смена» (op-modal, см. operations.js) —
   то же матовое стекло, что у шапки/.floating-panel: только оболочка,
   внутренние блоки (.an-header, .an-tabs и т.п.) остаются на var(--an-surface),
   как и у .floating-panel-section. */
.an-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(1020px, 94vw);
    max-height: 92vh;
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--font-sans, 'Manrope', sans-serif);
}

.an-modal.hidden,
.an-backdrop.hidden {
    display: none;
}

/* Начинается под шапкой, не inset:0 — см. тот же комментарий у
   .drawer-backdrop/.modal-backdrop в styles.css: шапка не должна
   перекрываться невидимым fullscreen-слоем. */
.an-backdrop {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(12, 14, 16, 0.42);
    z-index: 1190;
}

.an-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--an-line);
    cursor: grab;
}

.an-header:active {
    cursor: grabbing;
}

/* Перетаскивание за .an-header — см. window.makeModalDraggable в theme.js,
   подключается из analytics.js/operations.js сразу после создания модалки. */
.an-modal.is-dragging {
    transition: none;
    user-select: none;
}

.an-title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--an-ink);
    letter-spacing: -0.01em;
}

.an-subtitle {
    margin: 4px 0 0;
    font-size: 12.5px;
    color: var(--an-ink-soft);
    line-height: 1.45;
}

.an-close {
    border: none;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    color: var(--an-ink-muted);
    cursor: pointer;
    padding: 2px 6px;
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm, 6px);
}

.an-close:hover {
    background: var(--bg-surface-hover, #f0f2ef);
    color: var(--an-ink);
}

.an-body {
    padding: 18px 22px 24px;
    overflow-y: auto;
}

/* плитки цифр */

.an-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));   /* квадраты растягиваются на всю ширину окна */
    gap: 10px;
    margin-bottom: 22px;
}

/* Карточки-показатели — тот же дизайн, что у карточек в «Рейтинге бригад»:
   квадрат, обводка 1.5px по состоянию, подпись сверху, цифра по центру, пояснение снизу. */
.an-tile {
    background: var(--an-surface-subtle);
    border: 1.5px solid #0ea5e9;
    background: rgba(14, 165, 233, 0.24);
    border-radius: var(--radius-md, 8px);
    padding: 12px 10px;
    aspect-ratio: 1 / 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    text-align: center;
}
:root[data-theme="dark"] .an-tile { background: rgba(14, 165, 233, 0.14); }
.an-tile.is-good { border-color: #22c55e; background: rgba(34, 197, 94, 0.24); }
.an-tile.is-warn { border-color: #ca8a04; background: rgba(234, 179, 8, 0.26); }
.an-tile.is-bad  { border-color: #ef4444; background: rgba(239, 68, 68, 0.22); }
:root[data-theme="dark"] .an-tile.is-good { background: rgba(34, 197, 94, 0.14); }
:root[data-theme="dark"] .an-tile.is-warn { border-color: #ca8a04; background: rgba(202, 138, 4, 0.14); }
:root[data-theme="dark"] .an-tile.is-bad  { background: rgba(239, 68, 68, 0.14); }

.an-tile-label {
    font-size: 11px;
    color: var(--an-ink-soft);
    font-weight: 600;
    display: block;
    overflow-wrap: anywhere;
}

.an-tile-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--an-ink);
    line-height: 1.1;
    letter-spacing: -0.02em;
    display: block;
}

.an-tile-unit {
    font-size: 12px;
    font-weight: 700;
    color: var(--an-ink-soft);
    margin-left: 4px;
}

.an-tile-note {
    display: block;
    font-size: 10.5px;
    color: var(--an-ink-muted);
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.an-tile-note.is-good { color: var(--an-good); font-weight: 600; }
.an-tile-note.is-warn { color: var(--an-warn); font-weight: 600; }
.an-tile-note.is-bad  { color: var(--an-bad);  font-weight: 600; }
.an-tile-note.is-flat { color: var(--an-ink-muted); font-weight: 600; }

/* секции */

.an-section {
    margin-bottom: 26px;
}

.an-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 4px;
}

.an-section-title {
    margin: 0;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--an-ink);
}

.an-section-desc {
    margin: 0 0 12px;
    font-size: 12px;
    color: var(--an-ink-soft);
    line-height: 1.5;
    max-width: 78ch;
}

.an-resource-navigation {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 8px;
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid var(--an-line);
    border-radius: 8px;
    background: var(--an-surface);
}
.an-resource-navigation label { display: grid; gap: 4px; flex: 1 1 210px; font-size: 12px; }
.an-resource-navigation select {
    width: min(100%, 360px);
    min-height: 40px;
    padding: 6px 9px;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm, 6px);
    background: var(--an-surface);
    color: var(--an-ink);
    font: inherit;
    font-size: 14px;
}
.an-resource-navigation [data-resource-current],
.an-resource-navigation [data-resource-progress] { color: var(--an-ink-soft); font-size: 12px; }
.an-resource-navigation button:disabled { opacity: .55; cursor: not-allowed; }
.an-resource-row.is-active { outline: 2px solid var(--beeline-yellow); outline-offset: -2px; background: var(--an-surface-subtle); }
#op-modal input:not([type="checkbox"]):not([type="range"]):not([type="hidden"]),
#op-modal select {
    max-width: 100%;
    min-height: 40px;
    padding: 7px 10px;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    background: var(--an-surface);
    color: var(--an-ink);
    font: inherit;
    font-size: 14px;
}
#op-modal input:not([type="checkbox"]):not([type="range"]):hover,
#op-modal select:hover { border-color: var(--text-secondary); }
#op-modal input:not([type="checkbox"]):not([type="range"]):focus,
#op-modal select:focus { border-color: var(--border-focus); }
#op-modal input[aria-invalid="true"],
#op-modal select[aria-invalid="true"] { border-color: var(--status-danger); }
#op-modal input::placeholder { color: var(--an-ink-soft); opacity: 1; }
#op-modal .an-inventory-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 96px;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--an-line);
}
#op-modal .an-inventory-field span { min-width: 0; }
#op-modal .an-inventory-field input {
    width: 96px;
    text-align: right;
}
.an-resource-summary {
    padding: 10px 12px;
    border: 1px solid var(--an-line);
    border-radius: 8px;
    background: var(--an-surface-subtle);
    color: var(--an-ink-soft);
    font-size: 12px;
}

.an-link-btn {
    border: 1px solid var(--an-line);
    background: var(--an-surface);
    color: var(--beeline-link);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 10px;
    min-height: 40px;
    border-radius: var(--radius-full, 9999px);
    cursor: pointer;
    white-space: nowrap;
}

.an-link-btn:hover {
    background: var(--bg-surface-hover, #f0f2ef);
    color: var(--an-ink);
}

/* Разделы «Сопровождения смены» (Ведомость оборудования/Выдача/План и факт) —
   тот же дизайн плоских вкладок с подчёркиванием, что и "Бригады (N)/
   Заявки (N)" в конструкторе (см. .modal-tabs/.modal-tab в styles.css),
   а не круглые кнопки-пилюли (.an-link-btn), с которыми их путали. */
.an-tabs {
    display: flex;
    gap: 8px;
    padding: 0 22px;
    border-bottom: 1px solid var(--an-line);
}

.an-tab {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 6px;
    min-height: 40px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--an-ink-soft);
    cursor: pointer;
}

.an-tab[aria-selected="true"] {
    color: var(--an-ink);
    border-bottom-color: var(--beeline-yellow);
}

/* легенда */

.an-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 12px;
}

.an-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--an-ink-soft);
    font-weight: 600;
}

.an-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex: none;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.an-swatch.work   { background: var(--an-series-work); }
.an-swatch.travel { background: var(--an-series-travel); }
.an-swatch.wait   { background: var(--an-series-wait); }
.an-swatch.idle   { background: var(--an-series-idle); }
.an-swatch.demand { background: var(--an-pair-demand); }
.an-swatch.supply { background: var(--an-pair-supply); }

/* стековая полоса смены */

.an-stack {
    display: flex;
    width: 100%;
    height: 22px;
    gap: 2px;                 /* зазор поверхности между сегментами */
    margin-bottom: 8px;
}

.an-seg {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11.5px;
    font-weight: 700;
    color: #181a1b;
    overflow: hidden;
    white-space: nowrap;
    cursor: default;
    transition: filter 120ms ease;
}

.an-seg:hover { filter: brightness(1.08); }

/* Скругление — только по краям всей полосы; стыки сегментов прямые. */
.an-seg { min-width: 4px; }
.an-stack .an-seg:first-child { border-radius: 999px 0 0 999px; }
.an-stack .an-seg:last-child  { border-radius: 0 999px 999px 0; }
.an-stack .an-seg:only-child  { border-radius: 999px; }

.an-seg.work   { background: var(--an-series-work); }
.an-seg.travel { background: var(--an-series-travel); }
.an-seg.wait   { background: var(--an-series-wait); }
.an-seg.idle   { background: var(--an-series-idle); }
.an-seg.work,
.an-seg.travel,
.an-seg.wait,
.an-seg.idle { color: #ffffff; }

/* построчные полосы бригад */

.an-rows {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.an-row {
    display: grid;
    grid-template-columns: 172px 1fr 116px;
    align-items: center;
    gap: 12px;
}

.an-row-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--an-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.an-row-name small {
    display: block;
    font-size: 10.5px;
    font-weight: 500;
    color: var(--an-ink-muted);
}

.an-row .an-stack {
    height: 20px;
    margin-bottom: 0;
}

.an-row .an-seg {
    font-size: 10px;
}

.an-row-tail {
    font-size: 11.5px;
    color: var(--an-ink-soft);
    text-align: right;
    font-weight: 600;
}

.an-zone {
    display: inline-block;
    padding: 1px 7px;
    border-radius: var(--radius-full, 9999px);
    font-size: 10.5px;
    font-weight: 700;
    margin-left: 6px;
}

/* Сплошные (не полупрозрачные) цвета: rgba(x, 0.14) поверх тёмного фона
   даёт мутный тёмный оттенок почти того же цвета, что и текст — плашка
   становится нечитаемой. В тёмной теме пара инвертируется: насыщенный
   фон + светлый текст, как у .jeopardy-pill/.unassigned-highlight. Граница —
   яркая (насыщенный тон того же цвета), заливка внутри — блёклая: тот же
   единый образ плашек-статусов, что и у .badge-tag/.jeopardy-pill в
   styles.css. */
.an-zone.OPTIMAL     { background: #DCFCE7; color: #14532D; font-weight: 700; border: 1.5px solid #22C55E; }
.an-zone.OVERLOADED  { background: #FEE2E2; color: #991B1B; font-weight: 700; border: 1.5px solid #EF4444; }
.an-zone.UNDERLOADED { background: #FEF3C7; color: #78350F; font-weight: 700; border: 1.5px solid var(--beeline-yellow, #FFC72C); }
.an-zone.IDLE        { background: #E2E8F0; color: #1E293B; font-weight: 700; border: 1.5px solid #64748B; }

:root[data-theme="dark"] .an-zone.OPTIMAL     { background: #14532D; color: #BBF7D0; border-color: #22C55E; }
:root[data-theme="dark"] .an-zone.OVERLOADED  { background: #7F1D1D; color: #FECACA; border-color: #EF4444; }
:root[data-theme="dark"] .an-zone.UNDERLOADED { background: #78350F; color: #FDE68A; border-color: var(--beeline-yellow, #FFC72C); }
:root[data-theme="dark"] .an-zone.IDLE        { background: #334155; color: #E2E8F0; border-color: #94A3B8; }

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .an-zone.OPTIMAL     { background: #14532D; color: #BBF7D0; border-color: #22C55E; }
    :root:where(:not([data-theme="light"])) .an-zone.OVERLOADED  { background: #7F1D1D; color: #FECACA; border-color: #EF4444; }
    :root:where(:not([data-theme="light"])) .an-zone.UNDERLOADED { background: #78350F; color: #FDE68A; border-color: var(--beeline-yellow, #FFC72C); }
    :root:where(:not([data-theme="light"])) .an-zone.IDLE        { background: #334155; color: #E2E8F0; border-color: #94A3B8; }
}

/* парные полосы (ёмкость) */

.an-pair-row {
    display: grid;
    grid-template-columns: 150px 1fr 150px;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.an-pair-bars {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.an-bar-track {
    height: 24px;
    position: relative;
    border-bottom: 1px dashed var(--an-line);
    margin-right: 8px;
}

/* «Леденец»: тонкая линия с кружком на конце, подпись — над линией. */
.an-bar-fill {
    --an-bar-color: var(--an-series-work);
    position: relative;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 0 10px 0 0;
    font-size: 10px;
    font-weight: 700;
    color: var(--an-ink-soft);
    white-space: nowrap;
}

.an-bar-fill::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 5px;
    height: 3px;
    border-radius: 999px;
    background: var(--an-bar-color);
}

.an-bar-fill::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--an-bar-color);
    box-shadow: 0 0 0 2px var(--an-surface);
}

.an-bar-fill.demand { --an-bar-color: var(--an-pair-demand); }
.an-bar-fill.supply { --an-bar-color: var(--an-pair-supply); }

/* таблица сравнения */

.an-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--an-line);
    border-radius: var(--radius-md, 8px);
}

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

.an-table th,
.an-table td {
    padding: 8px 12px;
    text-align: right;
    border-bottom: 1px solid var(--border-subtle, #eceeea);
    white-space: nowrap;
}

.an-table th:first-child,
.an-table td:first-child {
    text-align: left;
    white-space: normal;
}

.an-table thead th {
    background: var(--an-surface-subtle);
    color: var(--an-ink-soft);
    font-weight: 700;
    font-size: 11.5px;
    position: sticky;
    top: 0;
}

.an-table tbody tr:last-child td { border-bottom: none; }
.an-table tbody tr:hover { background: var(--bg-surface-hover, #f0f2ef); }

.an-delta.is-good { color: var(--an-good); font-weight: 700; }
.an-delta.is-bad  { color: var(--an-bad);  font-weight: 700; }
.an-delta.is-flat { color: var(--an-ink-muted); font-weight: 600; }

/* выводы */

.an-notes {
    margin: 0 0 22px;
    padding: 14px 16px;
    list-style: none;
    background: var(--an-surface-subtle);
    border: 1px solid var(--an-line);
    border-radius: var(--radius-md, 8px);
}

.an-notes li {
    font-size: 12.5px;
    color: var(--an-ink);
    line-height: 1.55;
    padding-left: 16px;
    position: relative;
    margin-bottom: 7px;
}

.an-notes li:last-child { margin-bottom: 0; }

.an-notes li::before {
    content: "—";
    position: absolute;
    left: 0;
    color: var(--an-ink-muted);
}

.an-pitch {
    margin-top: 12px;
    padding: 13px 16px;
    border-left: 3px solid var(--beeline-yellow, #ffc800);
    background: var(--an-surface-subtle);
    border-radius: 0 var(--radius-md, 8px) var(--radius-md, 8px) 0;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--an-ink);
}

/* подсказка */

.an-tooltip {
    position: fixed;
    z-index: 1300;
    pointer-events: none;
    background: #181a1b;
    color: #ffffff;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.5;
    padding: 7px 10px;
    border-radius: var(--radius-sm, 6px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    max-width: 260px;
    white-space: normal;
}

.an-tooltip.hidden { display: none; }

.an-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--an-ink-soft);
    font-size: 13px;
}
#op-modal .an-empty:empty { display: none; }

@media (max-width: 720px) {
    .an-resource-navigation label { flex-basis: 100%; }
    .an-resource-navigation [data-resource-progress] { flex-basis: 100%; }
    .an-row { grid-template-columns: 110px 1fr; }
    .an-row-tail { display: none; }
    .an-pair-row { grid-template-columns: 100px 1fr; }
    .an-pair-row > :last-child { display: none; }
}

/* Accessibility Focus & Motion (WCAG 2.4.7 & 2.3.3) */
.an-close:focus-visible,
.an-link-btn:focus-visible,
.an-tab:focus-visible,
.an-btn:focus-visible {
    outline: 2px solid var(--focus-ink) !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px var(--focus-ring) !important;
}

@media (prefers-reduced-motion: reduce) {
    .an-modal, .an-bar-fill, .an-progress-fill {
        transition-duration: 0.001ms !important;
        animation-duration: 0.001ms !important;
    }
}

/* «Смета»: плитки обычного размера — прямоугольные, а не огромные квадраты. */
#op-modal .an-tiles { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
#op-modal .an-tile { aspect-ratio: auto; min-height: 96px; gap: 6px; }
