:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #142033;
    --muted: #667085;
    --border: #dce3ed;
    --primary: #1668dc;
    --primary-dark: #0f52b5;
    --success: #087443;
    --warning: #9a6700;
    --quiet: #596579;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); }
.shell { width: min(1180px, calc(100% - 32px)); margin-inline: auto; }
.site-header { background: #10233f; color: #fff; box-shadow: 0 2px 12px rgb(20 32 51 / 14%); }
.header-inner { min-height: 64px; display: flex; align-items: center; gap: 28px; }
.brand { color: #fff; font-size: 1.2rem; font-weight: 800; text-decoration: none; }
.site-header nav { display: flex; gap: 20px; flex: 1; }
.site-header nav a, .account a { color: #dce9fb; text-decoration: none; }
.site-header nav a:hover, .account a:hover { color: #fff; }
.account { color: #dce9fb; font-size: .9rem; }
.page-content { padding-block: 36px 64px; }
.hero { max-width: 760px; padding: clamp(28px, 6vw, 72px) 0; }
.hero h1, .page-heading h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.08; }
.hero > p:not(.eyebrow) { color: var(--muted); font-size: 1.18rem; }
.eyebrow { margin: 0 0 8px; color: var(--primary); font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; padding: 9px 16px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
.button:hover { border-color: #aab8ca; }
.button-primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button-primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.button-warning { border-color: #d99a16; background: #f6b936; color: #3b2a00; }
.button-warning:hover { border-color: #bd7e00; background: #e8a91d; }
.button-quiet { background: transparent; color: var(--quiet); }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.heading-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; }
.heading-actions .button { flex: 0 0 auto; white-space: nowrap; }
.result-count { color: var(--muted); font-weight: 700; }
.messages { display: grid; gap: 8px; margin-bottom: 20px; }
.message { padding: 12px 14px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.message-success { border-color: #8ed2ae; background: #e8f8ef; color: var(--success); }
.message-error { border-color: #e5a3a3; background: #fff0f0; color: #9f2525; }
.message-warning { border-color: #e5c267; background: #fff8df; color: #765600; }
.filter-panel { display: grid; grid-template-columns: minmax(260px, 2fr) minmax(150px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr) auto auto; align-items: end; gap: 12px; margin-bottom: 22px; padding: 18px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.filter-panel label { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.filter-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-bottom: 22px; padding: 18px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.filter-form label { display: grid; flex: 1 1 240px; gap: 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
input, select { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #bac6d5; border-radius: 8px; background: #fff; color: var(--text); font: inherit; }
input:focus, select:focus { outline: 3px solid rgb(22 104 220 / 18%); border-color: var(--primary); }
.table-wrap { overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: #f7f9fc; color: var(--muted); font-size: .76rem; letter-spacing: .045em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fbff; }
.product-link { color: var(--text); font-weight: 750; text-decoration: none; }
.product-link:hover { color: var(--primary); }
.status { display: inline-flex; padding: 4px 9px; border-radius: 999px; background: #edf1f6; color: var(--quiet); font-size: .78rem; font-weight: 800; white-space: nowrap; }
.status-active { background: #dcf7e9; color: var(--success); }
.status-draft { background: #fff2c7; color: var(--warning); }
.status-archived { background: #e8ebef; color: #515967; }
.status-pending { background: #fff2c7; color: var(--warning); }
.status-approved { background: #dcf7e9; color: var(--success); }
.status-rejected { background: #fff0f0; color: #9f2525; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 18px; margin-top: 22px; }
.pagination a { font-weight: 700; }
.empty-state { padding: 54px 24px; border: 1px dashed #b9c6d6; border-radius: 14px; background: var(--surface); text-align: center; }
.empty-state h2 { margin-top: 0; }
.empty-state p, .muted { color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 18px; text-decoration: none; font-weight: 700; }
.product-heading { align-items: center; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.card { padding: 22px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.card-wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 18px; font-size: 1.05rem; }
.definition-list { margin: 0; }
.definition-list div { display: grid; grid-template-columns: minmax(130px, .7fr) 1.3fr; gap: 16px; padding: 9px 0; border-bottom: 1px solid #edf1f5; }
.definition-list div:last-child { border-bottom: 0; }
.definition-list dt { color: var(--muted); }
.definition-list dd { margin: 0; font-weight: 650; }
.record-list { margin: 0; padding: 0; list-style: none; }
.record-list li { display: flex; justify-content: space-between; gap: 18px; padding: 10px 0; border-bottom: 1px solid #edf1f5; }
.record-list li:last-child { border-bottom: 0; }
.record-list span { color: var(--muted); text-align: right; }
.base-unit-note { margin-top: 0; padding: 10px 12px; border-radius: 8px; background: #f1f5fa; }
.conversion-list li { align-items: center; }
.notes { margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }
.image-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.product-image { position: relative; margin: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 11px; background: #f6f8fb; }
.product-image-primary { border: 2px solid var(--primary); }
.product-image img { width: 100%; aspect-ratio: 1; display: block; object-fit: cover; }
.product-image figcaption { padding: 8px 10px; color: var(--muted); font-size: .8rem; }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 16px; }
.catalog-card { overflow: hidden; display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 0 1px 2px rgb(20 32 51 / 4%); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.catalog-card:hover { border-color: #b7c9e2; box-shadow: 0 9px 24px rgb(20 32 51 / 10%); transform: translateY(-2px); }
.catalog-card-photo { display: block; aspect-ratio: 1 / .82; overflow: hidden; background: #eef3f9; }
.catalog-card-photo img { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform .25s ease; }
.catalog-card:hover .catalog-card-photo img { transform: scale(1.035); }
.catalog-card-photo-empty { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); background: linear-gradient(135deg, #f1f5fa, #e5ebf3); font-size: .86rem; font-weight: 700; }
.catalog-card-content { display: grid; align-content: start; gap: 9px; padding: 14px; }
.catalog-card-topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.catalog-card-unit { color: var(--muted); font-size: .8rem; font-weight: 700; }
.catalog-card-title { display: -webkit-box; min-height: 3em; overflow: hidden; font-size: .98rem; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.catalog-card-category { margin: 0; overflow: hidden; color: var(--muted); font-size: .83rem; text-overflow: ellipsis; white-space: nowrap; }
.catalog-load-sentinel { display: grid; place-items: center; min-height: 72px; }
.catalog-load-sentinel.is-loading::after { content: "Загружаем ещё товары…"; color: var(--muted); font-size: .88rem; }
.catalog-load-sentinel.catalog-load-error::after { content: "Не удалось загрузить товары. Используйте кнопку «Далее»."; color: var(--warning); font-size: .88rem; }
.inline-form { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.inline-form summary { color: var(--primary); font-weight: 750; cursor: pointer; }
.inline-form form, .edit-form { display: grid; gap: 16px; }
.inline-form form { margin-top: 16px; }
.inline-form form > div, .edit-form > div:not(.actions):not(.form-errors) { display: grid; gap: 6px; }
.inline-form label, .edit-form label { font-weight: 700; }
.inline-form textarea, .edit-form textarea { width: 100%; padding: 9px 11px; border: 1px solid #bac6d5; border-radius: 8px; font: inherit; resize: vertical; }
.inline-form input[type="checkbox"] { width: auto; min-height: auto; }
.edit-form { max-width: 760px; }
.edit-form .helptext { color: var(--muted); font-size: .82rem; }
.edit-form .errorlist, .form-errors .errorlist { margin: 0; padding: 10px 14px 10px 32px; border-radius: 8px; background: #fff0f0; color: #9f2525; }
.duplicate-warning { padding: 16px; border: 1px solid #e5c267; border-radius: 10px; background: #fff8df; }
.duplicate-warning h2 { margin: 0 0 6px; font-size: 1.05rem; }
.duplicate-warning p { margin: 0 0 12px; color: #765600; }
.duplicate-warning ul { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.duplicate-warning li { display: flex; justify-content: space-between; gap: 14px; padding-top: 8px; border-top: 1px solid #efd990; }
.duplicate-warning li span { color: var(--muted); text-align: right; }
.component-rows { display: grid; gap: 10px; }
.component-row { display: grid; grid-template-columns: 3fr 1fr; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: #f8fafc; }
.component-row > div { display: grid; gap: 5px; }
.version-heading { display: flex; justify-content: space-between; gap: 18px; align-items: center; }
.version-heading > div { display: flex; align-items: center; gap: 12px; }
.version-heading h2 { margin: 0; }
.carton-version-current { border-color: #6ba6ef; box-shadow: 0 0 0 2px rgb(22 104 220 / 8%); }
.compact-table th, .compact-table td { padding-block: 10px; }
.balance-filter { grid-template-columns: minmax(210px, 1fr) minmax(260px, 1.4fr) minmax(180px, 1fr) auto auto; }
.document-filter { grid-template-columns: minmax(230px, 1.5fr) minmax(180px, 1fr) minmax(210px, 1fr) auto auto; }
.audit-filter { grid-template-columns: minmax(260px, 2fr) minmax(220px, 1fr) auto auto; }
.negative-row { background: #fff4f4; }
.negative-row:hover { background: #ffeaea; }
.recent-documents { margin-top: 22px; }
.inline-edit-form { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--border); }
.batch-document-form { display: grid; gap: 18px; }
.batch-header-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.batch-header-grid > div { display: grid; gap: 6px; }
.batch-header-grid label, .batch-line label { font-weight: 700; }
.batch-header-grid textarea { width: 100%; padding: 9px 11px; border: 1px solid #bac6d5; border-radius: 8px; font: inherit; resize: vertical; }
.batch-line-list { display: grid; gap: 12px; }
.batch-line { position: relative; display: grid; grid-template-columns: minmax(240px, 2fr) minmax(100px, .7fr) minmax(150px, 1fr) minmax(150px, 1fr); gap: 12px; padding: 16px 16px 12px 42px; border: 1px solid var(--border); border-radius: 11px; background: #f8fafc; }
.batch-line > div { display: grid; gap: 5px; align-content: start; }
.batch-line [data-product-search] { min-height: 34px; }
.line-remove { justify-self: start; grid-column: 1 / -1; padding: 0; border: 0; background: transparent; color: #b42318; font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer; }
.batch-line > .line-cost[hidden] { display: none; }
.line-number { position: absolute; top: 24px; left: 15px; color: var(--muted); font-weight: 800; }
.line-formula { grid-column: 1 / -1; margin: 0; }
.negative-text { color: #b42318; }
.positive-text { color: var(--success); }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 22px; }
.summary-card { display: grid; gap: 5px; padding: 16px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); }
.summary-card span, .summary-card small { color: var(--muted); }
.summary-card strong { font-size: 1.35rem; }
.summary-card-warning { border-color: #e5a3a3; background: #fff4f4; }
.command-card { margin-top: 22px; }
.command-card code { display: block; overflow-x: auto; padding: 12px; border-radius: 8px; background: #10233f; color: #e8f1ff; }
.packaging-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.packaging-card { align-self: start; }

@media (max-width: 860px) {
    .page-heading { align-items: start; flex-direction: column; }
    .heading-actions { width: 100%; justify-content: flex-start; }
    .filter-panel { grid-template-columns: 1fr 1fr; }
    .search-field { grid-column: 1 / -1; }
    .detail-grid { grid-template-columns: 1fr; }
    .batch-line { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
    .shell { width: min(100% - 22px, 1180px); }
    .header-inner { min-height: auto; padding-block: 14px; flex-wrap: wrap; gap: 10px 18px; }
    .site-header nav { order: 3; width: 100%; flex-wrap: wrap; gap: 8px 14px; }
    .site-header nav a { white-space: nowrap; }
    .account { margin-left: auto; }
    .page-content { padding-top: 26px; }
    .page-heading { align-items: start; flex-direction: column; }
    .heading-actions { width: 100%; justify-content: space-between; }
    .filter-panel { grid-template-columns: 1fr; }
    .filter-form { display: grid; grid-template-columns: 1fr; }
    .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .catalog-card { border-radius: 11px; }
    .catalog-card-content { gap: 7px; padding: 10px; }
    .catalog-card-title { min-height: 3.15em; font-size: .86rem; line-height: 1.55; }
    .catalog-card-category { font-size: .74rem; }
    .catalog-card-unit { font-size: .73rem; }
    .catalog-card .status { padding: 3px 7px; font-size: .68rem; }
    .balance-filter { grid-template-columns: 1fr; }
    .search-field { grid-column: auto; }
    .table-wrap { border: 0; overflow: visible; background: transparent; }
    table, thead, tbody, tr, th, td { display: block; }
    thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    tbody { display: grid; gap: 12px; }
    tr { padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
    td { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 6px 0; border: 0; }
    td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; font-weight: 700; }
    .definition-list div { grid-template-columns: 1fr; gap: 2px; }
    .component-row { grid-template-columns: 1fr; }
    .version-heading { align-items: start; flex-direction: column; }
    .batch-header-grid, .batch-line { grid-template-columns: 1fr; }
    .line-formula { grid-column: auto; }
}
