/**
 * WMS — общие токены и кнопки для статических страниц frontend/*.html
 * Подключать первым в <head>, затем локальные <style> при необходимости.
 */
:root {
    --bg: #f6f8fc;
    --card: #ffffff;
    --line: #dfe6f3;
    --text: #17223b;
    --muted: #52607a;
    --primary: #2f6fed;
    --primary-hover: #245bd0;
    --ok: #0b7a0b;
    --danger: #b30000;
}

/* Запасной фокус для <button> без .btn — иначе перебивает .btn-primary:focus-visible */
button:focus-visible:not(:disabled):where(:not(.btn)) {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

.btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid var(--line);
    background: #fff;
    box-sizing: border-box;
}

.btn:not(.btn-primary):not(.btn-danger-solid):not(.btn-success):not(.btn-danger):hover:not(:disabled) {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

a.btn,
a.btn:visited,
a.btn:hover,
a.btn:active {
    text-decoration: none;
    display: inline-block;
    color: var(--text);
}

a.btn.btn-primary,
a.btn.btn-primary:visited,
a.btn.btn-primary:hover,
a.btn.btn-primary:active {
    color: #fff;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
    line-height: 1.1;
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.06);
}

.nav-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.nav-btn:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

.nav-btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
}

.nav-btn.primary:hover {
    background: var(--primary-hover);
}

.nav-btn.primary:focus-visible {
    outline: none;
    background: #5d8ef1;
    border-color: #5d8ef1;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.72),
        0 0 0 3px rgba(147, 197, 253, 0.34),
        0 2px 8px rgba(37, 91, 208, 0.14);
}

.nav-btn.secondary {
    background: #fff;
    border-color: var(--line);
    color: var(--text);
}

.nav-btn.secondary:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled,
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

/*
 * Фокус с клавиатуры: чуть мягче заливка (не темнее — ховер остаётся отдельным),
 * кольцо в тон кнопке.
 */
.btn-primary:focus-visible {
    outline: none;
    background: #5d8ef1;
    border-color: #5d8ef1;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.72),
        0 0 0 3px rgba(147, 197, 253, 0.34),
        0 2px 8px rgba(37, 91, 208, 0.14);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.82rem;
}

.btn-danger {
    color: var(--danger);
    border-color: #fca5a5;
    background: #fff5f5;
}

.btn-danger:hover:not(:disabled) {
    background: #fee2e2;
    border-color: #f87171;
    color: #b91c1c;
}

.btn-danger:focus-visible {
    outline: none;
    background: #fecaca;
    border-color: #ef4444;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.72),
        0 0 0 3px rgba(252, 165, 165, 0.45);
}

/* Как btn-primary по весу; яркий «алый» / скарлет */
.btn-danger-solid {
    background: #e92d2d;
    color: #fff;
    border-color: #c41a1a;
}

.btn-danger-solid:hover {
    background: #d11919;
    border-color: #a81414;
}

.btn-success {
    background: #16a34a;
    color: #fff;
    border-color: #15803d;
}

.btn-success:hover {
    background: #15803d;
    border-color: #166534;
}

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

.wms-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 16px;
}
.wms-page-header h1 {
    flex: 1 1 auto;
    margin: 0;
    min-width: 10rem;
    font-size: 1.2rem;
}
.wms-page-header .nav-links {
    flex: 1 1 100%;
    order: 10;
}
.wms-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}
.wms-header-actions .back-link,
.wms-header-actions .back-link:visited,
.wms-header-actions .back-link:hover,
.wms-header-actions .back-link:active {
    text-decoration: none;
    color: var(--primary);
    font-size: 0.92rem;
    white-space: nowrap;
}
.wms-header-actions .username {
    color: var(--muted);
    font-size: 0.88rem;
}
.wms-page-header .logout-btn {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    font-size: 0.88rem;
    padding: 6px 12px;
    cursor: pointer;
}
.wms-page-header .logout-btn:hover {
    background: #f1f3f5;
}

.nav-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.warehouse-nav-spacer {
    flex: 1 1 auto;
    min-width: 8px;
}
.nav-links a,
.nav-links a:visited,
.nav-links a:hover,
.nav-links a:active {
    text-decoration: none;
    color: var(--primary);
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-size: 0.9rem;
}
.nav-links a:hover {
    background: #edf2ff;
}

/* Страницы с локальным классом nav (ОН, ОВО, завод) */
a.nav,
a.nav:visited,
a.nav:hover,
a.nav:active {
    color: var(--primary);
    text-decoration: none;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-size: 0.9rem;
}
a.nav:hover {
    background: #edf2ff;
}

/* Текстовые ссылки в песочнице и подсказках (CEO / бух) */
.wms-inline-link,
.wms-inline-link:visited,
.wms-inline-link:hover,
.wms-inline-link:active {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}
.wms-inline-link:hover {
    text-decoration: underline;
}

/* Песочница / ОН / ОВО в таблице заказов */
.import-actions a.btn,
.import-actions a.btn:visited,
.import-actions a.btn:hover,
.import-actions a.btn:active {
    color: var(--primary);
}
.nav-links .here {
    padding: 6px 10px;
    border-radius: 8px;
    background: #dbeafe;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    border: 1px solid #b6c6f6;
}

.btn-danger-solid:focus-visible {
    outline: none;
    background: #ec5a5a;
    border-color: #ec5a5a;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.72),
        0 0 0 3px rgba(254, 202, 202, 0.48),
        0 2px 8px rgba(168, 20, 20, 0.14);
}

/* Overlay toasts for transient notifications (non-blocking layout). */
.toast-host {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(92vw, 42rem);
    z-index: 2500;
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #cfe0ff;
    color: #173059;
    background: rgba(239, 246, 255, 0.86);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 8px 22px rgba(17, 24, 39, 0.14);
    line-height: 1.35;
}

.toast-item.toast-ok {
    border-color: #86efac;
    color: #14532d;
    background: rgba(240, 253, 244, 0.86);
}

.toast-item.toast-warn {
    border-color: #fcd34d;
    color: #78350f;
    background: rgba(255, 251, 235, 0.9);
}

.toast-item .toast-msg {
    flex: 1 1 auto;
    word-break: break-word;
}

.toast-item .toast-close {
    flex: 0 0 auto;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    border-radius: 6px;
    width: 22px;
    height: 22px;
    line-height: 18px;
    font-size: 15px;
    cursor: pointer;
    opacity: 0.82;
}

.toast-item .toast-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.07);
}

/* Autocomplete dropdown (orders, finance documents) */
.search-wrap {
    position: relative;
    flex: 1 1 280px;
    min-width: 200px;
}

.search-dd {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: 280px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.12);
    z-index: 100;
}

.search-dd .search-dd-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1.35;
}

.search-dd .search-dd-item:hover {
    background: #edf2ff;
}

.search-dd .search-dd-item.search-dd-item-active {
    background: #dbeafe;
    outline: 1px solid #93c5fd;
}

/* Document tabs (shipment: main / marking) */
.doc-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
}
.doc-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.doc-tab:hover { color: var(--text); background: #f8fafc; }
.doc-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.line-status-none { }
.line-status-partial td { background: #fffbeb !important; }
.line-status-ok td { background: #f0fdf4 !important; }
.line-status-over td { background: #fff7ed !important; }

.line-status-legend {
    font-size: 0.82rem;
    color: var(--muted);
    margin: 0 0 10px;
}
.line-status-legend .lg-partial {
    padding: 1px 6px;
    border-radius: 4px;
    background: #fffbeb;
}
.line-status-legend .lg-ok {
    padding: 1px 6px;
    border-radius: 4px;
    background: #f0fdf4;
}
.line-status-legend .lg-over {
    padding: 1px 6px;
    border-radius: 4px;
    background: #fff7ed;
}

.marking-tree { margin-top: 10px; font-size: 0.88rem; }
.marking-tree details { margin: 4px 0 4px 12px; }
.marking-tree summary { cursor: pointer; padding: 4px 0; }

.marking-nested details { margin: 4px 0 4px 8px; }
.marking-nested summary { cursor: pointer; padding: 3px 0; font-size: 0.86rem; }
.marking-line-expand-placeholder { display: inline-block; width: 1.1rem; }
.marking-line-expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    color: var(--primary);
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    user-select: none;
}
.marking-line-expand-btn:hover { background: #e8eefc; }
.marking-sub-row td {
    background: #f8faff !important;
    padding: 6px 10px 6px 2.5rem !important;
    border-bottom: 1px solid #eef2ff;
}
.marking-assembly-banner {
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 0.88rem;
}
.marking-assembly-banner.done {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}
.assembly-footer-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.marking-dm-list {
    margin: 4px 0 8px 24px;
    font-family: ui-monospace, monospace;
    font-size: 0.82rem;
}

/* Assembly modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-assembly {
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--line);
    width: min(720px, 100%);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(17, 24, 39, 0.18);
}
.modal-assembly-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}
.modal-assembly-head h2 { margin: 0; font-size: 1.05rem; }
.modal-assembly-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 16px;
    min-height: 120px;
}
.modal-assembly-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f0f4fb;
}
.modal-assembly-input-row input.sscc-inp {
    flex: 1 1 auto;
    width: 75%;
    min-width: 0;
    max-width: 75%;
    box-sizing: border-box;
    font-family: ui-monospace, monospace;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    padding: 10px 12px;
}
.modal-assembly-check-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 2.5rem;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid #93c5fd;
    border-radius: 8px;
    background: #eff6ff;
    color: var(--primary);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
}
.modal-assembly-check-btn:hover:not(:disabled) {
    background: #dbeafe;
    border-color: #60a5fa;
}
.modal-assembly-check-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.modal-assembly-row-meta { flex: 1 1 auto; min-width: 0; }
.modal-assembly-row-qty {
    flex: 0 0 auto;
    font-weight: 700;
    white-space: nowrap;
}
.modal-assembly-row-err { color: var(--danger); font-size: 0.85rem; }
.assembled-pallet-sscc-preview {
    font-family: ui-monospace, monospace;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    word-break: break-all;
    padding: 10px 0 6px;
}
.assembled-prepare-line { margin-bottom: 4px; }
.sticky-modal-footer {
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}
.assembly-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }

.assembly-expand-btn {
    display: inline-block;
    width: 1.25rem;
    text-align: center;
    color: var(--primary);
    font-size: 0.75rem;
    user-select: none;
}
.assembly-expand-placeholder {
    display: inline-block;
    width: 1.25rem;
}
.assembly-attach-item td {
    background: #f8fafc !important;
    padding: 6px 10px 8px 10px !important;
    border-bottom: 1px solid #e8eef8;
}
.assembly-attach-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    padding-left: 0.5rem;
}
.assembly-attach-type {
    font-weight: 600;
    min-width: 4.5rem;
}
.assembly-attach-sscc {
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
}
.assembly-attach-sscc-wrap,
.marking-dm-code-wrap {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
}
.btn-copy-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    padding: 0;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1;
    cursor: pointer;
}
.btn-copy-code:hover {
    color: var(--primary);
    border-color: #c7d2fe;
    background: #f8faff;
}
.btn-copy-code.copied {
    color: #166534;
    border-color: #86efac;
    background: #f0fdf4;
}

/* Компактное снятие/удаление строки (вместо текста «Убрать» / «Снять») */
.btn-icon-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.55rem;
    height: 1.55rem;
    padding: 0;
    margin: 0;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    background: #fff5f5;
    color: var(--danger);
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
}
.btn-icon-remove:hover:not(:disabled) {
    background: #fee2e2;
    border-color: #f87171;
    color: #b91c1c;
}
.btn-icon-remove:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.marking-dm-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 6px;
}
.marking-dm-code {
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
    word-break: break-all;
}
.assembly-attach-qty {
    font-weight: 700;
    white-space: nowrap;
}
.assembly-attach-product {
    flex: 1 1 auto;
    min-width: 0;
}
.product-combined {
    white-space: normal;
    word-break: break-word;
}
.marking-attach-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.marking-attach-row {
    display: flex;
    align-items: flex-start;
    gap: 4px;
}
.marking-nest-expand-placeholder {
    display: inline-block;
    width: 1.35rem;
    flex-shrink: 0;
}
.marking-nest-expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    flex-shrink: 0;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    text-align: center;
    color: var(--primary);
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    user-select: none;
}
.marking-nest-expand-btn:hover { background: #e8eefc; }
.marking-nest-children {
    margin: 2px 0 6px 1.35rem;
}
.marking-attach-row .assembly-attach-inner {
    flex: 1 1 auto;
    min-width: 0;
}
.marking-foot-row td {
    background: #edf2ff !important;
    font-weight: 600;
    border-top: 2px solid var(--line);
}
.assembly-tablet.data-table th,
.assembly-tablet.data-table td,
.marking-tablet.data-table th,
.marking-tablet.data-table td {
    padding: 6px 8px;
    font-size: 0.84rem;
}
.assembly-tablet.data-table th:nth-child(2),
.marking-tablet.data-table th:nth-child(2) {
    width: 42%;
}
