/* ============ design tokens ============ */
:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8ef;
    --text: #1e293b;
    --text-soft: #64748b;
    --text-mute: #94a3b8;
    --primary: #3a8ae8;
    --primary-soft: #eaf3fe;
    --primary-strong: #2569c6;
    --success: #1aa86b;
    --warn: #d98a1a;
    --danger: #d04b4b;
    --danger-soft: #fdecec;
    --warn-soft: #fdf4e2;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 18px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 8px 32px rgba(15, 23, 42, 0.18);
    --font: "Inter", "Segoe UI", "Avenir Next", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

/* ============ темна тема ============ */
html[data-theme="dark"] {
    --bg: #0e1420;
    --surface: #182030;
    --surface-2: #131a27;
    --border: #28324a;
    --text: #e8eef8;
    --text-soft: #a3b2c9;
    --text-mute: #6f7f99;
    --primary: #4f9bf2;
    --primary-soft: #15294a;
    --primary-strong: #7fb6ff;
    --success: #2bbd7e;
    --warn: #e3ab3e;
    --danger: #e76d6d;
    --danger-soft: #3a1f24;
    --warn-soft: #382c14;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

/* Плавна зміна теми та інтерактивних станів */
body, .panel, .sidebar, .topbar, .card, .stat-card, .btn,
.branch-link, .nav-link, input, select, textarea, table, th, td {
    transition: background-color .25s ease, color .2s ease,
                border-color .2s ease, box-shadow .2s ease;
}
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ shell ============ */
.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, #2f7fe0 0%, #1f5cba 100%);
    color: #eaf1fc;
    padding: 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;          /* прокрутка, якщо пунктів більше, ніж висота екрана */
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.35) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.3); border-radius: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
/* щоб блок «Платформа» завжди лишався внизу, але не «прилипав» при прокрутці */
.sidebar .nav { flex: 1 0 auto; }

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mark {
    width: 38px; height: 38px;
    background: #ffffff;
    border-radius: 10px;
    display: grid; place-items: center;
    font-weight: 700; font-size: 14px; letter-spacing: .02em;
    color: var(--primary-strong);
    box-shadow: 0 4px 14px rgba(15,40,90,0.25);
}
.brand-title { font-weight: 700; font-size: 16px; color: #fff; }
.brand-sub { font-size: 11px; color: #d2e2f7; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    color: #e8effb;
    border-radius: 10px;
    font-size: 14px;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,0.14); text-decoration: none; color: #fff; }
.nav-link.is-active { background: #ffffff; color: var(--primary-strong); font-weight: 600; box-shadow: 0 4px 14px rgba(15,40,90,0.25); }
.nav-link.is-active .nav-icon { opacity: 1; }
.nav-icon { width: 22px; display: inline-block; text-align: center; opacity: .85; }

/* Червоний бейдж із кількістю — напр. кількість партій, що спливають */
.nav-badge {
    margin-left: auto;
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 11px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    line-height: 1.4;
    box-shadow: 0 2px 6px rgba(208, 75, 75, 0.4);
}

.scanner-hint {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 12px;
    font-size: 12px;
    color: #cbd5e1;
}
.scanner-hint-title { font-weight: 600; color: #fff; margin-bottom: 6px; }

.sidebar-credit {
    font-size: 10px;
    color: rgba(203, 213, 225, 0.55);
    text-align: center;
    letter-spacing: .03em;
    padding-top: 4px;
}
.sidebar-version {
    font-size: 9px;
    color: rgba(203, 213, 225, 0.40);
    margin-top: 2px;
}
kbd {
    display: inline-block;
    padding: 1px 6px;
    background: rgba(255,255,255,0.12);
    border-radius: 4px;
    font-family: "SF Mono", "Menlo", monospace;
    font-size: 11px;
}

/* ============ main ============ */
.main {
    display: flex; flex-direction: column;
    min-width: 0;
}
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar-title { font-size: 22px; font-weight: 700; }
.topbar-sub { font-size: 13px; color: var(--text-soft); margin-top: 2px; }
.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: nowrap;
}
.now-clock {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}
.content { padding: 14px 16px 22px; }

/* ============ stats ============ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}
/* без min-width:0 елемент сітки не стискається — довгі суми вилазили за край */
.stat-grid > * { min-width: 0; }
.stat-grid.compact { margin-bottom: 10px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.stat-card.primary { background: linear-gradient(135deg, #2f7ad9 0%, #1f5fb0 100%); color: #fff; border: none; }
.stat-card.warn { background: linear-gradient(135deg, #f4b860 0%, #d98a1a 100%); color: #fff; border: none; }
.stat-card.danger { background: linear-gradient(135deg, #ee7474 0%, #c33b3b 100%); color: #fff; border: none; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; opacity: .85; }
/* Розмір числа підлаштовується під ширину картки: «5 714 748,00» більше
   не перекриває сусідню плитку на вузьких екранах. */
.stat-value {
    font-size: clamp(19px, 1.9vw, 28px);
    font-weight: 700;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    overflow-wrap: anywhere;
}
.stat-label { min-height: 26px; }

/* ---- економіка: графік при наведенні на KPI ---- */
#ecoKpi .stat-card { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
#ecoKpi .stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.eco-chart {
    margin-top: 6px;
    padding: 14px 18px 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    animation: ecoChartIn .16s ease;
}
.eco-chart-title { font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 10px; }
@keyframes ecoChartIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- сторінка «База даних» ---- */
.panel-text {
    margin: 12px 20px 0;
    color: var(--text-soft);
    font-size: 13px;
    line-height: 1.55;
}
.tpl-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 20px 20px;
}
.import-result {
    margin: 4px 20px 20px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.5;
}
.import-result.ok  { background: #e1f4ec; color: #176b4a; }
.import-result.err { background: var(--danger-soft); color: var(--danger); }
.import-errors { margin-top: 8px; }
.import-errors ul { margin: 6px 0 0; padding-left: 20px; }
.danger-zone .panel-head h2 { color: var(--danger); }
.backups-section { margin: 8px 20px 20px; }
.backups-title {
    font-size: 11px; font-weight: 600; color: var(--text-soft);
    text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px;
}
.backups-list {
    font-size: 13px; max-height: 220px; overflow-y: auto;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 8px 12px; background: var(--surface-2);
    font-variant-numeric: tabular-nums;
}
.backups-list .empty { color: var(--text-mute); }
.backup-item { padding: 3px 0; line-height: 1.5; }
.backup-item a { color: var(--primary); text-decoration: none; }
.backup-item a:hover { text-decoration: underline; }

/* компактні рядки дій на сторінці «База даних» */
.db-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 20px 18px;
}
.db-row-gap { flex: 1 1 24px; min-width: 0; }
.db-row .db-file {
    flex: 1 1 200px;
    min-width: 0;
    font-size: 13px;
}
.db-row .btn { white-space: nowrap; }

.backups-details { margin: 0 20px 20px; font-size: 13px; }
.backups-details summary {
    cursor: pointer;
    padding: 6px 12px;
    color: var(--text-soft);
    user-select: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.backups-details summary:hover { color: var(--text); }
.backups-details[open] summary { margin-bottom: 8px; }

/* ---- сторінки входу та налаштування ---- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 20px;
    font-family: var(--font);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 30px;
}
.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}
.auth-title { font-size: 20px; font-weight: 700; margin: 0 0 14px; }
.auth-hint {
    color: var(--text-soft);
    font-size: 13px;
    line-height: 1.5;
    margin: 0 0 16px;
}
.auth-error {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 13px;
}
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-submit { margin-top: 8px; }
.user-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: -4px 0 0;
}
.user-chip {
    font: inherit;
    font-size: 12px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 999px;
    cursor: pointer;
    color: var(--text-soft);
}
.user-chip:hover {
    background: var(--primary-soft);
    color: var(--primary-strong);
    border-color: var(--primary-soft);
}
.online-now {
    color: var(--success);
    font-weight: 600;
    font-size: 13px;
}

/* ---- топбар: інформація про користувача ---- */
.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-right: 14px;
    border-right: 1px solid var(--border);
}
.user-info { text-align: right; line-height: 1.25; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-role {
    font-size: 10px; color: var(--text-soft);
    text-transform: uppercase; letter-spacing: .05em;
}

/* ============ panels ============ */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 14px;
}
.panel-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    gap: 12px;
    flex-wrap: wrap;
}
.panel-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* Панель фільтрів у один рядок (журнал рухів) */
.head-actions.filters-row { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.head-actions.filters-row .inline-label,
.head-actions.filters-row .btn { flex: 0 0 auto; white-space: nowrap; }
.head-actions.filters-row #reasonFilter { max-width: 190px; }

/* Компактний заголовок: пошук + кнопки в один рядок */
.head-actions-row {
    flex: 1;
    flex-wrap: nowrap;
}
.head-actions-row .search-input {
    flex: 1;
    min-width: 160px;
}
.head-actions-row .btn { white-space: nowrap; }

.two-col {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}
@media (max-width: 1180px) {
    .two-col { grid-template-columns: 1fr; }
}

/* Сторінка приходу: форма та журнал — обидва на всю ширину */
.receive-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.receive-layout .panel { margin-bottom: 0; width: 100%; }

/* Сторінка продажу: зліва набір позицій, справа — чек */
.sale-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    gap: 20px;
    align-items: start;
}
.sale-layout .panel { margin-bottom: 0; }
@media (max-width: 1100px) {
    .sale-layout { grid-template-columns: 1fr; }
}

/* ============ tables ============ */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th, .table td {
    padding: 6px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table thead th {
    background: var(--surface-2);
    color: var(--text-soft);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .03em;
}
.table tbody tr:hover { background: #f9fbff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .empty { text-align: center; color: var(--text-mute); padding: 14px; }
.update-box { margin: 8px 14px 4px; padding-top: 10px; border-top: 1px solid var(--border); }
.update-banner {
    background: #e1f4ec; color: #176b4a; border: 1px solid #b9e3d2;
    border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 10px;
}
.update-banner a { color: #176b4a; text-decoration: underline; }

/* ── Мінімалістична панель «Версія та оновлення» ── */
.ver-body { padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.ver-headline { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ver-app { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: .01em; }
.ver-meta { font-size: 12px; color: var(--text-soft); }
.ver-update-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ver-flex { flex: 1 1 auto; }
.ana-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.ana-toggle input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.ver-source {
    flex: 1 1 auto; min-width: 0;
    font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    padding: 7px 11px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface-2); color: var(--text);
}
.ver-source:focus { border-color: var(--primary); outline: none; background: var(--surface); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.ver-status:empty { display: none; }
.ver-status { font-size: 12px; color: var(--text-soft); }
.ver-hint { font-size: 11px; color: var(--text-mute); }
.ver-history { font-size: 12px; }
.ver-history summary { cursor: pointer; color: var(--text-soft); list-style: none; }
.ver-history summary::-webkit-details-marker { display: none; }
.ver-history summary::before { content: "▸ "; }
.ver-history[open] summary::before { content: "▾ "; }
.ver-history .backup-item { padding: 4px 0; }

/* ── Компактний вигляд сторінки «База даних» ── */
.db-compact .panel { margin-bottom: 6px; }
/* згортні панелі */
.collapsible-head { cursor: pointer; user-select: none; }
.collapse-chevron { color: var(--text-soft); font-size: 12px; transition: transform .15s ease; margin-left: auto; }
.panel.is-collapsed .collapse-chevron { transform: rotate(-90deg); }
.db-compact .panel.is-collapsed > :not(.panel-head) { display: none; }
.db-compact .panel.is-collapsed .panel-head { border-bottom: none; }
.db-compact .panel-head { padding: 8px 14px; }
.db-compact .panel-head h2 { font-size: 14px; }
.db-compact .panel-text { margin: 8px 14px 0; font-size: 12px; line-height: 1.45; }
.db-compact .db-row { gap: 8px; padding: 8px 14px 12px; }
.db-compact .btn { padding: 5px 11px; font-size: 12px; }
.db-compact .db-file { font-size: 12px; }
.db-compact .version-grid { gap: 16px; padding: 8px 14px 2px; }
.db-compact .version-cell .version-value { font-size: 15px; }
.db-compact .backup-dir-box { margin: 8px 14px 4px; padding-top: 8px; }
.db-compact .backups-details { margin: 0 14px 12px; font-size: 12px; }
.db-compact #backupDirHint { font-size: 11px; }

.version-grid { display: flex; flex-wrap: wrap; gap: 22px; padding: 12px 20px 4px; }
.version-cell .version-value { font-size: 18px; font-weight: 700; color: var(--text); margin-top: 2px; }
.backup-dir-box { margin: 14px 0 6px; padding-top: 12px; border-top: 1px solid var(--border); }
.backup-dir-box .field-label { display: block; margin-bottom: 6px; font-size: 12px; color: var(--text-soft); }
/* Поле шляху — на весь рядок (широке), кнопки переносяться під нього.
   Специфічність двома класами — щоб перебити .search-input (max-width:320px). */
.backup-dir-row { flex-wrap: wrap; }
.backup-dir-row .backup-dir-input {
    flex: 1 1 100%; width: 100%; min-width: 0; max-width: none;
    font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.backup-dir-row .btn { flex: 0 0 auto; white-space: nowrap; }
.table tfoot td { font-weight: 600; background: var(--surface-2); }

/* sortable headers */
.sortable-th {
    position: relative;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: background .12s, color .12s;
}
.sortable-th:hover { background: #eef2f7; color: var(--text); }
.sortable-th .sort-ind {
    display: inline-block;
    width: 12px;
    text-align: center;
    color: var(--text-mute);
    font-size: 10px;
    margin-left: 2px;
}
.sortable-th.sort-asc  { color: var(--primary-strong); background: var(--primary-soft); }
.sortable-th.sort-desc { color: var(--primary-strong); background: var(--primary-soft); }
.sortable-th.sort-asc  .sort-ind::after { content: '▲'; color: var(--primary); }
.sortable-th.sort-desc .sort-ind::after { content: '▼'; color: var(--primary); }

/* filter bar */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: #fbfcfe;
    border-bottom: 1px solid var(--border);
}
.filters-bar .inline-label select {
    min-width: 130px;
}
.filter-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.badge.in { background: #e1f4ec; color: var(--success); }
.badge.out { background: var(--primary-soft); color: var(--primary-strong); }
.badge.wo { background: var(--warn-soft); color: var(--warn); }
.badge.ret { background: #fff3e0; color: #b25e00; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: #e1f4ec; color: var(--success); }

/* ============ forms ============ */
.form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 20px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: span 2; }
.form > .full { grid-column: span 2; }

/* Stacked form variant — кожна секція займає всю ширину панелі,
   усередині секцій своя внутрішня сітка. */
.form.stacked {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.form.stacked > * { width: 100%; }
.form.stacked .actions { justify-content: flex-end; }

/* перемикач-чекбокс (напр. «друкувати чек») */
.check-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    user-select: none;
}
.check-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    margin: 0;
    flex: none;
}
.field-label { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
input[type="text"], input[type="number"], input[type="date"], input[type="time"], input[type="search"], input[type="email"], input[type="password"], select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}
input[type="time"]::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; }
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(47,122,217,0.18);
}
.scan-input {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: .04em;
    padding: 14px 16px;
    background: #f5f9ff;
    border: 2px dashed #b8d4f3;
}
.scan-input:focus { background: #fff; border-style: solid; }

/* Підсвічування незаповнених обов'язкових полів */
input.input-error,
.input-error input {
    border-color: var(--danger) !important;
    background: var(--danger-soft);
    box-shadow: 0 0 0 3px rgba(208, 75, 75, 0.16);
}

/* Близький термін придатності (≤30 днів) — жовте попередження.
   Прострочені партії підсвічуються червоним через .input-error. */
input.input-warn,
.input-warn input {
    border-color: var(--warn) !important;
    background: var(--warn-soft);
    box-shadow: 0 0 0 3px rgba(217, 138, 26, 0.16);
}

/* Сторінка «Схеми» — компактно, дрібний шрифт, рівні відступи */
.form-hint { font-size: 12px; margin: 8px 2px 0; }
.plan-when { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-mute); }
.plan-sel { padding: 4px 8px; font: inherit; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.schemes-page .table-compact th,
.schemes-page .table-compact td { font-size: 12px; }
/* Щільніші рядки таблиці схем (менші відступи по вертикалі) */
#schemesTable td, #schemesTable th { padding-top: 2px; padding-bottom: 2px; }
#schemesTable .btn-icon { padding-top: 2px; padding-bottom: 2px; }
#orderTable .row-urgent td { background: var(--danger-soft); }
#orderTable .row-need td { background: rgba(26, 168, 107, .15); }
.order-tools { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.order-tools #orderSearch {
    flex: 1; min-width: 160px; padding: 6px 10px; font: inherit; font-size: 13px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
#toggleUnused.is-active { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* Колонка «№» + перетягування рядків схем */
.seq-col { width: 1%; white-space: nowrap; color: var(--text-mute); }
#schemesTable tbody tr[data-id] { cursor: default; }
#schemesTable .drag-handle {
    cursor: grab; color: var(--text-mute); margin-right: 6px;
    user-select: none; letter-spacing: -1px;
}
#schemesTable .drag-handle:active { cursor: grabbing; }
#schemesTable tr.dragging { opacity: .55; background: var(--surface-2); }

.modal-wide { max-width: min(1080px, 94vw); width: 94vw; }
.btn-sm { padding: 3px 10px; font-size: 12px; }

.scheme-lines { margin: 4px 0 6px; }
.scheme-lines th, .scheme-lines td { font-size: 12px; padding: 4px 6px; vertical-align: middle; }
.scheme-lines select,
.scheme-lines input {
    width: 100%;
    padding: 4px 6px;
    font: inherit;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.scheme-lines .ln-dose,
.scheme-lines .ln-times { text-align: right; }
.scheme-lines .ln-unit { white-space: nowrap; }

.need-blocks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}
.need-block { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; }
.need-block-title { font-weight: 600; font-size: 12px; margin-bottom: 4px; }
.need-block .table-compact td { font-size: 12px; padding: 3px 4px; }

/* Управління стада — сітка групи × місяці */
.herd-page .head-actions { gap: 10px; align-items: center; }
.year-nav { display: inline-flex; align-items: center; gap: 6px; }
.year-label { font-weight: 600; min-width: 48px; text-align: center; }
.herd-grid th, .herd-grid td { font-size: 12px; padding: 4px 6px; vertical-align: middle; }
.herd-grid .herd-group-col { min-width: 150px; }
.herd-grid input {
    width: 100%;
    padding: 4px 6px;
    font: inherit;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.herd-grid .hd-month { width: 54px; text-align: right; }
.herd-grid td.num { text-align: right; }
.herd-grid tfoot td { border-top: 2px solid var(--border); padding-top: 7px; }


.actions {
    display: flex; gap: 10px; justify-content: flex-end;
}
.actions.full { grid-column: span 2; }
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, transform .05s, border-color .15s;
}
.btn:hover { background: #ebf0f7; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #158a57; }
.btn-icon {
    padding: 6px 8px;
    background: transparent;
    color: var(--text-soft);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

.search-input { min-width: 220px; max-width: 320px; flex: 0 1 auto; }
.search-narrow { min-width: 160px; max-width: 220px; }

/* Конструктор колонок: кнопка з випадним меню галочок */
.col-picker { position: relative; display: inline-block; }
.col-picker-btn { white-space: nowrap; }
.col-picker-menu {
    /* Меню — position: fixed, щоб не обрізалося overflow:hidden панелі.
       Координати top/left виставляються в JS на льоту. */
    position: fixed;
    z-index: 1000;
    min-width: 220px;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 10px 12px;
}
.col-picker-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-soft);
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: .04em;
}
.col-picker-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}
.col-picker-item input { accent-color: var(--primary); width: 16px; height: 16px; }
.col-picker-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.col-picker-actions .btn { padding: 4px 10px; font-size: 12px; }
.inline-label {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--text-soft);
}
.inline-label select, .inline-label input { width: auto; }

/* ============ form sections (receive) ============ */
.form-section {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px 14px;
    background: var(--surface-2);
}
.form-section-title {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: .06em;
    color: var(--primary-strong);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.form-section-title .hint {
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-mute);
    font-size: 11px;
}
.form-section-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.form-section-grid.four {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.form-section-grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 980px) {
    .form-section-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .form-section-grid,
    .form-section-grid.four { grid-template-columns: 1fr; }
}

/* Дві form-section поруч у формі приходу (Партія | Закупка) */
.form-row-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}
@media (max-width: 1100px) {
    .form-row-2col { grid-template-columns: 1fr; }
}

/* Прихід: 2-колонковий макет.
   Зліва — компактний блок «Пошук препарату» (sticky, тримається на видноті
   при прокручуванні правої колонки). Справа — вертикальний стек усіх форм
   внесення приходу: Накладна, Партія, Закупка, Продаж, Примітка, Submit. */
.receive-2col {
    display: flex;
    gap: 0;
    align-items: flex-start;
}
.receive-2col > .receive-search-col {
    flex: 0 0 var(--recv-left, 42%);
    position: sticky;
    top: 0;
    min-width: 0;
}
.receive-2col > .receive-fields-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
}
@media (max-width: 1100px) {
    .receive-2col { flex-direction: column; }
    .receive-2col > .receive-search-col { flex: none; width: 100%; position: static; }
    .receive-2col > .col-splitter { display: none; }
}

/* В стек-формі прибираємо подвійні відступи зовнішніх label-полів */
.form.stacked > .field {
    padding: 0;
}

/* ===== Компактний варіант форми приходу =====
   Стискає вертикальні відступи в усіх секціях накладної, щоб уся форма
   поміщалась без зайвого скролу. Застосовується тільки до панелі з класом
   .form-panel — інші форми лишаються у звичному розмірі. */
.form-panel .form.stacked     { padding: 14px; gap: 9px; }
.form-panel .form-section     { padding: 9px 12px 10px; }
.form-panel .form-section-title { margin-bottom: 6px; }
.form-panel .form-section-grid { gap: 9px; }
.form-panel .field            { gap: 3px; }
.form-panel .field-label      { font-size: 10px; }
.form-panel input[type="text"],
.form-panel input[type="number"],
.form-panel input[type="date"],
.form-panel input[type="search"],
.form-panel select            { padding: 6px 10px; }
.form-panel .scan-input       { padding: 9px 14px; font-size: 15px; }
.form-panel .vat-summary      { margin-top: 6px; padding: 5px 10px; font-size: 11px; }
.form-panel .margin-hint .hint-value { padding: 6px 10px; }
.form-panel .product-preview  { padding: 8px 12px; }
.form-panel .actions          { margin-top: 2px; }
.form-panel .panel-head       { padding: 10px 14px; }
input[readonly] {
    background: #eef2f7 !important;
    color: var(--text-soft);
    cursor: not-allowed;
}
.vat-summary {
    margin-top: 10px;
    padding: 8px 12px;
    background: var(--primary-soft);
    color: var(--primary-strong);
    border-radius: var(--radius-sm);
    font-size: 12px;
}
.vat-summary strong { font-size: 13px; }

/* Режим «без ПДВ» — приховуємо поля з ПДВ, грид з 4 → 2 колонки */
.form-section[data-vat="without"] .vat-only { display: none !important; }
.form-section[data-vat="without"] .form-section-grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.vat-toggle .seg-btn { font-size: 11px; padding: 4px 12px; }
.margin-hint .hint-value {
    padding: 9px 12px;
    background: #eef2f7;
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--success);
    font-variant-numeric: tabular-nums;
}
.margin-hint .hint-value.negative { color: var(--danger); }

/* ============ розумний автокомпліт ============ */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 60;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 300px;
    overflow-y: auto;
}
.autocomplete-item {
    padding: 9px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover,
.autocomplete-item.is-active { background: var(--primary-soft); }

/* Годівля: панель набору не обрізає випадаючий список (щоб був вищий) */
.panel-add.of-visible { overflow: visible; }
/* Годівля: список кормів вищий (у 2.5×) і щільніший по вертикалі */
.autocomplete-list.ac-dense { max-height: 750px; }
.autocomplete-list.ac-dense .autocomplete-item { padding: 3px 14px; }
.autocomplete-list.ac-dense .autocomplete-item .ac-name { font-size: 14px; line-height: 1.15; }
.autocomplete-list.ac-dense .autocomplete-item .ac-meta { margin-top: 0; line-height: 1.1; }
.autocomplete-list.ac-dense .autocomplete-item .ac-stock small { margin-top: -1px; }
.autocomplete-item .ac-name { font-weight: 600; font-size: 13px; }
.autocomplete-item .ac-meta {
    font-size: 11px;
    color: var(--text-soft);
    margin-top: 2px;
}
.autocomplete-item mark {
    background: #fde9a8;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}
.autocomplete-item .ac-stock {
    flex-shrink: 0;
    text-align: right;
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}
.autocomplete-item .ac-stock.low { color: var(--danger); }
.autocomplete-item .ac-stock small {
    display: block;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-mute);
    text-transform: uppercase;
}
.autocomplete-empty {
    padding: 12px 14px;
    color: var(--text-mute);
    font-style: italic;
    font-size: 12px;
}

/* ============ product preview ============ */
.product-preview {
    grid-column: span 2;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    min-height: 76px;
    display: flex; align-items: center; gap: 18px;
}
.preview-empty { color: var(--text-mute); font-style: italic; }
.preview-name { font-weight: 700; font-size: 16px; }
.preview-meta { color: var(--text-soft); font-size: 12px; margin-top: 4px; }
.preview-stock {
    margin-left: auto;
    text-align: right;
}
.preview-stock-value { font-size: 22px; font-weight: 700; color: var(--primary); }
.preview-stock-label { font-size: 11px; color: var(--text-soft); text-transform: uppercase; }
.preview-stock.low .preview-stock-value { color: var(--danger); }

/* ============ розкладка сторінки продажу ============ */
.sale-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 20px;
    padding: 20px;
    align-items: start;
}
.sale-col {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}
@media (max-width: 1100px) {
    .sale-layout { grid-template-columns: 1fr; }
}

/* ============ розкривні партії у складі ============ */
.batch-toggle {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 10px;
    color: var(--text-soft);
    width: 18px;
    padding: 2px;
    margin-right: 4px;
    border-radius: 4px;
    vertical-align: middle;
}
.batch-toggle:hover { background: var(--primary-soft); color: var(--primary); }
.batch-detail > td { padding: 0 !important; background: #f6f8fb; }
.batch-box { padding: 10px 16px 14px 40px; }
.batch-box-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--primary-strong);
    font-weight: 700;
    margin-bottom: 8px;
}
.batch-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.batch-table th {
    text-align: left;
    color: var(--text-mute);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    padding: 4px 8px;
}
.batch-table th.num, .batch-table td.num { text-align: right; }
.batch-table td {
    padding: 6px 8px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.batch-empty { color: var(--text-mute); font-style: italic; font-size: 12px; }
.batch-exp-edit {
    padding: 3px 6px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
}

/* зміна ширини колонок таблиці — невидима ручка на правій межі заголовка.
   Підсвічується лише при наведенні, щоб не заважати очам зайвою сіткою.
   Контейнер (th) має бути positioned; це гарантує makeColumnsResizable у app.js. */
.col-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 5;
    background: transparent;
    transition: background .12s;
}
.col-resizer:hover {
    background: linear-gradient(to right,
        transparent 0,
        transparent 2px,
        rgba(47, 122, 217, 0.55) 2px,
        rgba(47, 122, 217, 0.55) 6px,
        transparent 6px,
        transparent 100%);
}

/* ============ чек продажу ============ */
.cart-input {
    width: 92px;
    padding: 5px 8px;
    font-size: 13px;
    text-align: right;
}
tr.cart-over { background: var(--danger-soft); }
tr.cart-over .cart-input.cart-qty {
    border-color: var(--danger);
    color: var(--danger);
    font-weight: 600;
}
.cart-stock-note {
    font-size: 11px;
    color: var(--text-mute);
}
.cart-stock-note.over { color: var(--danger); font-weight: 600; }

/* ============ segmented ============ */
.segmented {
    display: inline-flex;
    background: var(--surface-2);
    border-radius: 999px;
    padding: 3px;
    border: 1px solid var(--border);
}
.seg-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    color: var(--text-soft);
}
.seg-btn.is-active { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(47,122,217,0.3); }

/* ============ modal ============ */
.modal {
    position: fixed; inset: 0;
    z-index: 100;
    display: grid; place-items: center;
}
.modal[hidden] { display: none; }
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}
.modal-card {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: min(560px, 92vw);
    max-height: 90vh;
    overflow: auto;
}
.modal-card h2 {
    padding: 20px 20px 0;
    margin: 0;
    font-size: 18px;
}
.modal-card.modal-wide { width: min(1080px, 94vw); max-width: min(1080px, 94vw); }

/* ---- генерація штрихкоду в модалі «Новий товар» ---- */
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; min-width: 0; }
.input-with-btn .btn { white-space: nowrap; }
.field-hint { font-size: 11px; color: var(--text-mute); }
.barcode-label-box {
    gap: 8px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}
.barcode-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.barcode-label svg { max-width: 100%; height: auto; }
.bc-label-name {
    font-size: 13px;
    font-weight: 700;
    color: #000000;
    text-align: center;
    word-break: break-word;
}

.edit-product-line {
    margin: 14px 20px 0;
    padding: 10px 14px;
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 15px;
    color: var(--primary-strong);
}
.edit-warning {
    margin: 10px 20px 0;
    padding: 8px 14px;
    background: var(--warn-soft);
    color: var(--warn);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

/* ============ toast ============ */
.toast-root {
    position: fixed;
    bottom: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 10px;
    z-index: 1200;
}
.toast {
    background: #1e293b;
    color: #fff;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    min-width: 240px;
    max-width: 360px;
    animation: toast-in .25s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ misc ============ */
/* Контейнер кнопок дій — завжди всередині <td>, не на самому <td>,
   інакше display:inline-flex ламає верстку таблиці. */
.row-actions {
    display: inline-flex;
    gap: 4px;
    white-space: nowrap;
}
.table td.col-actions { white-space: nowrap; width: 1%; }
.btn-icon-danger:hover { background: var(--danger-soft); color: var(--danger); }

/* Горизонтальна прокрутка для широких таблиць — захист від обрізання */
.table-scroll { overflow-x: auto; }

/* Компактна таблиця — менші відступи, щоб уміщувалося більше колонок */
.table-compact th,
.table-compact td { padding: 4px 10px; }
.table .nowrap { white-space: nowrap; }
.text-mute { color: var(--text-mute); }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.text-success { color: var(--success); }

/* Рядок довідника: випадаючий список + кнопка «+» (видача на блок/отримувача) */
.ref-row { display: flex; gap: 6px; align-items: stretch; }
.ref-row .ref-select { flex: 1; min-width: 0; }
.ref-row .btn-icon { flex: 0 0 auto; width: 38px; }

/* Видача: блок/отримувач у рядках списку; колонки ховаються у режимі списання */
/* Селекти блоку/відповідального — текст ЗЛІВА. Без цього успадкований від
   .cart-input text-align:right ламає нативний <select> у Windows Chrome
   (текст і випадний список з'їжджають праворуч). */
#cartTable .cart-block, #cartTable .cart-recipient {
    min-width: 130px; width: 100%; text-align: left;
}
/* На всяк випадок — будь-який select із класом cart-input не вирівнюємо вправо */
select.cart-input { text-align: left; }
#cartTable.hide-issue .issue-col { display: none; }

/* Сторінка «Довідники» */
.catalogs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.ref-add { display: flex; gap: 8px; margin-bottom: 12px; }
.ref-add .ref-add-input { flex: 1; min-width: 0; }
.ref-add .btn { flex: 0 0 auto; }
.ref-list { list-style: none; margin: 0; padding: 0; }
.ref-list .empty { color: var(--text-mute); padding: 8px 0; }
.ref-item { display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.ref-item:last-child { border-bottom: none; }
.ref-item-name { overflow: hidden; text-overflow: ellipsis; }
.ref-item-noname { color: var(--text-muted, #9aa1a9); font-style: italic; }
.block-none-hint { margin: 4px 10px 8px; font-size: 12px; color: var(--text-muted, #7a828c); }
.block-none-actions { padding: 0 10px 8px; }

/* Поле ставки ПДВ біля перемикача (зʼявляється лише в режимі «З ПДВ») */
.vat-controls { display: inline-flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.vat-controls input.vat-pct-input {
    width: 56px;
    flex: 0 0 auto;
    text-align: center;
    border-radius: 999px;
    padding: 6px 8px;
    font-size: 11px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}
.vat-controls input.vat-pct-input:focus {
    border-color: var(--primary);
    outline: none;
}

/* Розсувний роздільник між лівою та правою панелями видачі */
.sale-layout {
    display: flex;
    gap: 0;
    align-items: flex-start;
    padding: 0;
}
.sale-layout > .panel { margin-bottom: 0; min-width: 0; }
.sale-layout > .panel:first-child { flex: 0 0 var(--sale-left, 44%); }
.sale-layout > .panel:last-child  { flex: 1 1 0; }
.col-splitter {
    flex: 0 0 18px;
    align-self: stretch;
    cursor: col-resize;
    position: relative;
}
.col-splitter::before {
    content: "";
    position: absolute; top: 0; bottom: 0; left: 50%;
    width: 2px; transform: translateX(-50%);
    background: var(--border);
    border-radius: 2px;
    transition: background .15s, width .15s;
}
.col-splitter:hover::before,
.col-splitter.dragging::before { background: var(--primary); width: 4px; }
@media (max-width: 1100px) {
    .sale-layout { flex-direction: column; }
    .sale-layout > .panel:first-child { flex: none; width: 100%; }
    .col-splitter { display: none; }
}

/* ============ Платформа: перемикач гілок виробництва ============ */
.branch-switcher {
    display: flex; flex-direction: column; gap: 2px;
    padding: 8px 10px; margin: 4px 8px 6px;
    border-radius: var(--radius-sm, 8px);
    background: var(--surface-2);
}
.branch-link {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 10px; border-radius: 8px;
    color: var(--text-soft); text-decoration: none;
    font-size: 13px; line-height: 1.1;
}
/* Показчик доступного оновлення на пункті «База даних» */
.update-badge {
    margin-left: auto;
    background: #28c76f; color: #fff;
    font-size: 10px; font-weight: 700; letter-spacing: .02em;
    padding: 2px 7px; border-radius: 999px; white-space: nowrap;
    animation: updatePulse 1.8s ease-in-out infinite;
}
@keyframes updatePulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(40,199,111,0.55); }
    50%     { box-shadow: 0 0 0 6px rgba(40,199,111,0); }
}
/* Підсвічування рядка «База даних», коли доступне оновлення */
.branch-link.has-update {
    background: rgba(40,199,111,0.12);
    box-shadow: inset 3px 0 0 #28c76f;
    animation: rowGlow 1.8s ease-in-out infinite;
}
.branch-link.has-update.is-active { animation: none; }
@keyframes rowGlow { 0%,100% { background: rgba(40,199,111,0.12); } 50% { background: rgba(40,199,111,0.22); } }
.branch-link:hover { background: rgba(0,0,0,0.04); color: var(--text); }
.branch-link.is-active { background: var(--primary); color: #fff; font-weight: 600; }
.branch-link .branch-icon { font-size: 16px; width: 20px; text-align: center; }
.branch-link .branch-label { flex: 1; }
.branch-link .branch-tag {
    font-size: 9px; text-transform: uppercase; letter-spacing: .04em;
    padding: 1px 6px; border-radius: 999px;
    background: var(--surface); color: var(--text-mute);
}
.branch-link.is-active .branch-tag { background: rgba(255,255,255,0.25); color: #fff; }
.nav-soon-note { padding: 8px 14px; font-size: 12px; color: var(--text-mute); }

/* Хаб: плитки гілок */
.branch-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.branch-card {
    display: flex; gap: 14px; align-items: flex-start;
    padding: 18px; border: 1px solid var(--border);
    border-radius: var(--radius-sm, 10px); background: var(--surface);
    text-decoration: none; color: inherit;
    transition: box-shadow .15s, transform .15s, border-color .15s;
}
.branch-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: var(--primary); }
.branch-card.is-soon { opacity: .85; }
.branch-card-icon { font-size: 30px; line-height: 1; }
.branch-card-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.branch-card-desc { color: var(--text-mute); font-size: 13px; margin-top: 4px; }

/* Заготовка гілки */
.branch-placeholder { padding: 24px; }
.branch-placeholder .plan-list { margin: 10px 0 0; padding-left: 20px; line-height: 1.8; }

/* Платформний блок (Користувачі) над гілками */
.admin-switcher { margin-top: 0; }
.switcher-title {
    font-size: 9px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-mute); padding: 2px 10px 4px;
}
/* Галочки дозволу по блоках у картці користувача */
.blocks-check-list {
    display: flex; flex-direction: column; gap: 6px;
    max-height: 200px; overflow-y: auto;
    border: 1px solid var(--border); border-radius: var(--radius-sm, 8px);
    padding: 10px 12px; background: var(--surface-2);
}
.blocks-check-list label { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.blocks-check-list .empty { color: var(--text-mute); font-size: 12px; }
.blocks-check-hint { font-size: 11px; color: var(--text-soft); margin-top: 4px; }

/* Компактний вигляд сторінки «Довідники» */
.catalogs-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.catalogs-grid .panel { margin-bottom: 0; }
.catalogs-grid .panel-head { padding: 9px 14px; }
.catalogs-grid .panel-head h2 { font-size: 14px; }
.catalogs-grid .ref-add { padding: 12px 14px 8px; gap: 6px; margin-bottom: 0; }
.catalogs-grid .ref-add .ref-add-input { padding: 7px 10px; font-size: 13px; }
.catalogs-grid .ref-add .btn { padding: 7px 12px; font-size: 13px; }
.catalogs-grid .ref-list { padding: 0 8px 8px; }
.catalogs-grid .ref-item { padding: 5px 8px; font-size: 13px; }
.catalogs-grid .ref-item .btn-icon { padding: 3px 6px; }

/* Компактна шапка/фільтри сторінки «Склад» */
.products-compact .panel-head { padding: 9px 16px; }
.products-compact .panel-head h2 { font-size: 14px; }
.products-compact .filters-bar { padding: 8px 16px; gap: 10px; }
.products-compact .filters-bar .inline-label { font-size: 13px; }
.products-compact .filters-bar .inline-label select { min-width: 108px; padding: 5px 8px; font-size: 13px; }
.products-compact .head-actions .btn,
.products-compact .filters-bar .btn { padding: 6px 12px; font-size: 13px; }
.products-compact .search-input { padding: 7px 11px; font-size: 13px; }

/* ===== Згортання бічної панелі ===== */
.topbar-left { display: flex; align-items: center; gap: 12px; }

/* Банер стану ліцензії */
.lic-banner { padding: 9px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; line-height: 1.4; }
.lic-banner a { font-weight: 600; text-decoration: underline; margin-left: 6px; }
.lic-banner.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(195,59,59,.3); }
.lic-banner.danger a { color: var(--danger); }
.lic-banner.warn { background: #fff4e0; color: #9a6a00; border: 1px solid #f0d8a8; }
.lic-banner.warn a { color: #9a6a00; }
.lic-banner.info { background: #eef4ff; color: #2f5fb0; border: 1px solid #cfe0ff; }
.lic-banner.info a { color: #2f5fb0; }

/* Присутність онлайн у топбарі */
.presence { display: flex; align-items: center; gap: 4px; margin-right: 6px; }
.presence-label { font-size: 11px; color: var(--text-soft); text-transform: uppercase;
    letter-spacing: .04em; margin-right: 4px; }
.presence-dot {
    width: 28px; height: 28px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px #28c76f;  /* зелений ободок = онлайн */
    cursor: default; user-select: none;
}
.presence-dot.is-me { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary); }
.presence-more { font-size: 11px; color: var(--text-soft); font-weight: 600; padding: 0 4px; }
@media (max-width: 640px) { .presence-label { display: none; } }

.sidebar-toggle {
    width: 36px; height: 36px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 9px;
    font-size: 16px; line-height: 1;
    cursor: pointer; color: var(--text-soft);
    flex: 0 0 auto;
}
.sidebar-toggle:hover { background: var(--primary-soft); color: var(--primary-strong); }

/* Згорнутий стан: вузька панель лише з іконками */
.app-shell.is-collapsed { grid-template-columns: 66px 1fr; }
.app-shell.is-collapsed .sidebar { padding: 18px 8px; gap: 14px; }
.app-shell.is-collapsed .brand { justify-content: center; gap: 0; }
.app-shell.is-collapsed .brand > div:last-child,
.app-shell.is-collapsed .branch-label,
.app-shell.is-collapsed .branch-tag,
.app-shell.is-collapsed .switcher-title,
.app-shell.is-collapsed .scanner-hint,
.app-shell.is-collapsed .sidebar-credit,
.app-shell.is-collapsed .nav-soon-note { display: none; }
.app-shell.is-collapsed .branch-switcher { padding: 6px 4px; margin: 0; }
.app-shell.is-collapsed .branch-link { justify-content: center; padding: 8px 0; }
.app-shell.is-collapsed .branch-icon { width: auto; }
/* nav: лишаємо лише іконку (текст — голий вузол, ховаємо через font-size) */
.app-shell.is-collapsed .nav-link { justify-content: center; font-size: 0; padding: 10px 0; gap: 0; }
.app-shell.is-collapsed .nav-icon { font-size: 16px; width: auto; }
.app-shell.is-collapsed .nav-badge { display: none; }

/* ===== Згортання вибору гілок по вертикалі ===== */
.switcher-head {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; border: none; background: transparent; cursor: pointer;
    padding: 4px 8px 6px; margin: 0;
    font-size: 9px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-mute);
}
.switcher-head:hover { color: var(--text-soft); }
.switcher-chev { transition: transform .15s; font-size: 10px; }
.branch-switcher.collapsed .switcher-chev { transform: rotate(-90deg); }
/* У згорнутому стані лишаємо лише активну гілку */
.branch-switcher.collapsed .branch-link:not(.is-active) { display: none; }
/* У вузькій (горизонтально згорнутій) панелі заголовок ховаємо */
.app-shell.is-collapsed .switcher-head { display: none; }

/* Ручка зміни ширини стовпців усередині накладної */
.inv-detail-table th { position: relative; overflow: hidden; }
.dcol-resizer {
    position: absolute; top: 0; right: 0;
    width: 7px; height: 100%;
    cursor: col-resize; user-select: none; z-index: 5;
    background: transparent; transition: background .12s;
}
.dcol-resizer:hover { background: var(--primary); }
.inv-detail-table td { overflow: hidden; text-overflow: ellipsis; }

/* Перетягування позицій усередині накладної */
.inv-pos { cursor: default; }
.inv-pos .pos-grip { cursor: grab; color: var(--text-mute); margin-right: 4px; user-select: none; }
.inv-pos.dragging { opacity: .5; }
.inv-pos.drag-over td { box-shadow: inset 0 2px 0 var(--primary); }

/* Поля рядкового введення накладної — на всю ширину клітинки */
#invoiceTable .cart-input { width: 100%; box-sizing: border-box; }
#invoiceTable td { vertical-align: middle; }

/* Шапка накладної — компактний рядок */
.invoice-head {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end;
    padding: 6px 14px 4px;
}
.invoice-head .field { flex: 1; min-width: 150px; margin: 0; }
.invoice-head .field-label { font-size: 10px; }
.invoice-head input { padding: 7px 10px; font-size: 13px; }

/* Приховування ПДВ-стовпців у режимі «Без ПДВ» */
#invoiceTable.no-vat .vatcol { display: none; }

/* Бренд на сторінці входу/першого запуску — темний текст на світлому фоні */
.auth-brand .brand-title { color: var(--text); }
.auth-brand .brand-sub { color: var(--text-mute); }

/* Редагування операції: для списання ховаємо стовпці блок/отримувач */
#editSaleTable.hide-dest .es-dest { display: none; }

/* Відступи тіла модалів, де контент не загорнутий у .form */
.modal-card .modal-pad { padding: 14px 20px 20px; }

/* Гілки, недоступні за ліцензією — сірі (знебарвлені), з позначкою-замком */
.branch-card.is-locked { filter: grayscale(100%); opacity: .7; }
.branch-card.is-locked .branch-card-icon,
.branch-card.is-locked .branch-card-title,
.branch-card.is-locked .branch-card-desc { color: var(--text-mute); }
.branch-card.is-locked:hover { opacity: .85; }
.branch-link.is-locked { filter: grayscale(100%); opacity: .7; }
.branch-link.is-locked .branch-icon,
.branch-link.is-locked .branch-label { color: var(--text-mute); }
.branch-link.is-locked:hover { opacity: .9; }

/* ============ Перемикач теми ============ */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-soft);
    width: 36px; height: 36px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--primary);
    transform: translateY(-1px);
}
.theme-toggle:active { transform: translateY(0); }

/* ============ Преміум-мікроанімації ============ */
.btn { transition: transform .12s ease, box-shadow .18s ease,
                   background-color .18s ease, border-color .18s ease, color .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { box-shadow: 0 2px 8px -2px var(--primary); }
.btn-primary:hover { box-shadow: 0 6px 16px -4px var(--primary); }

.panel, .card, .stat-card {
    transition: transform .18s ease, box-shadow .22s ease,
                background-color .25s ease, border-color .2s ease;
}
.stat-card:hover, .card.is-hoverable:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Акуратні фокус-кільця */
.btn:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .theme-toggle:focus-visible, a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* М'яка поява контенту */
@keyframes farmFadeUp { from { opacity: 0; transform: translateY(6px); }
                        to   { opacity: 1; transform: translateY(0); } }
.content > .panel, .content > .stat-grid, .content > .card,
.content > .branch-grid { animation: farmFadeUp .35s ease both; }
@media (prefers-reduced-motion: reduce) {
    .content > * { animation: none !important; }
}

/* =================================================================
   МОБІЛЬНИЙ ВИГЛЯД (телефон ≤ 720px): компактно, меню — шторка
   ================================================================= */
.nav-backdrop { display: none; }
@media (max-width: 720px) {
    .app-shell { grid-template-columns: 1fr; }

    /* бічне меню — висувна шторка зліва */
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; width: 264px;
        z-index: 200; transform: translateX(-100%);
        transition: transform .25s ease; box-shadow: 0 0 40px rgba(0,0,0,.45);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    .nav-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45);
        z-index: 150; opacity: 0; pointer-events: none; transition: opacity .25s ease;
    }
    body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

    /* топбар компактний і «липкий» */
    .topbar { padding: 8px 12px; position: sticky; top: 0; z-index: 100; }
    .topbar-title { font-size: 17px; }
    .topbar-sub { display: none; }
    .topbar-right { gap: 8px; }
    .topbar-user .user-info { display: none; }
    .topbar-user .btn { padding: 7px 10px; font-size: 13px; }
    .now-clock { display: none; }
    .presence { display: none; }
    #pwaInstallBtn { display: none !important; }
    .sidebar-toggle { font-size: 22px; }

    /* контент щільніший */
    .content { padding: 10px 10px 18px; }
    .panel { margin-bottom: 12px; border-radius: 12px; }
    .panel-head { padding: 11px 13px; }
    .panel-head h2 { font-size: 15px; }

    /* сітки — в один стовпець */
    .stat-grid, .two-col { grid-template-columns: 1fr; }

    /* широкі таблиці — горизонтальна прокрутка */
    .content table.table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* зручніші пальцем поля та кнопки */
    input, select, textarea { font-size: 16px; }   /* 16px — щоб iOS не зумив */
    .btn { padding: 9px 14px; }
}

/* ===================== Оверлей сканера камерою ===================== */
.camscan-overlay { position: fixed; inset: 0; z-index: 500; background: #000;
    display: flex; flex-direction: column; }
.camscan-top { display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; color: #fff; }
.camscan-title { font-size: 14px; opacity: .9; }
.camscan-close { background: rgba(255,255,255,.16); color: #fff; border: 0;
    padding: 9px 16px; border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer; }
.camscan-stage { position: relative; flex: 1; overflow: hidden; }
.camscan-video { width: 100%; height: 100%; object-fit: cover; }
.camscan-frame { position: absolute; inset: 16% 12%; border: 3px solid rgba(255,255,255,.92);
    border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.camscan-laser { position: absolute; left: 6%; right: 6%; height: 2px; background: #4f9bf2;
    box-shadow: 0 0 10px 2px #4f9bf2; animation: camscanLaser 2s ease-in-out infinite; }
@keyframes camscanLaser { 0%,100% { top: 6%; } 50% { top: 92%; } }
.camscan-status { color: #cfe0f5; font-size: 13px; text-align: center; padding: 12px; min-height: 18px; }
.camscan-frame.flash { border-color: #2bbd7e; box-shadow: 0 0 0 100vmax rgba(0,0,0,.25), 0 0 24px 6px #2bbd7e; }

/* ===== Форма приходу на телефоні ===== */
@media (max-width: 720px) {
    .invoice-head { padding: 8px 10px; gap: 8px; }
    .invoice-head .field { flex: 1 1 calc(50% - 8px); min-width: 0; }
    .invoice-head .field[style] { flex: 1 1 100% !important; }  /* широкі поля — на всю ширину */
    .invoice-head input { font-size: 16px; }                    /* без зуму на iOS */
    .head-actions { width: 100%; }
    .head-actions .btn { flex: 1; }
    .invoice-foot { flex-wrap: wrap; gap: 8px; }
    .invoice-foot .btn { flex: 1 1 auto; }
    #invoiceTable input { font-size: 15px; }
}

/* ===== Компактніші таблиці: Склад, Терміни, Останні надходження/операції ===== */
#productsTable, #expiryTable, #recentInTable, #recentSalesTable { font-size: 12px; }
#productsTable th, #productsTable td,
#expiryTable th, #expiryTable td,
#recentInTable th, #recentInTable td,
#recentSalesTable th, #recentSalesTable td {
    padding-top: 3px;
    padding-bottom: 3px;
    line-height: 1.25;
}
#productsTable thead th, #expiryTable thead th,
#recentInTable thead th, #recentSalesTable thead th { font-size: 10px; }

/* ===== Менші вертикальні відступи: таблиці Видачі та Приходу ===== */
#cartTable th, #cartTable td,
#invoiceTable th, #invoiceTable td {
    padding-top: 3px;
    padding-bottom: 3px;
}
#cartTable td input, #invoiceTable td input { padding-top: 4px; padding-bottom: 4px; }

/* ===== Видача: різні тони панелей «Додати позицію» та «До видачі» ===== */
.panel-add  { background: #eef4fd; }   /* синюватий — набір позицій */
.panel-cart { background: #edf8f1; }   /* зеленуватий — список до видачі */
.panel-add  .panel-head { background: #e3edfb; }
.panel-cart .panel-head { background: #e0f3e8; }
html[data-theme="dark"] .panel-add  { background: #15233a; }
html[data-theme="dark"] .panel-cart { background: #15291e; }
html[data-theme="dark"] .panel-add  .panel-head { background: #1a2c46; }
html[data-theme="dark"] .panel-cart .panel-head { background: #1a3326; }

/* ===== Налаштування: компактний список гілок ===== */
.branch-toggle-list { display: flex; flex-direction: column; gap: 2px; margin: 6px 0 12px; }
.branch-toggle-list .check-toggle {
    display: flex; align-items: center; gap: 9px;
    font-size: 13px; color: var(--text);
    padding: 5px 8px; border-radius: 8px; margin: 0; cursor: pointer;
}
.branch-toggle-list .check-toggle:hover { background: var(--surface-2); }
.branch-toggle-list .check-toggle input[type="checkbox"] {
    width: 15px; height: 15px; margin: 0; flex: 0 0 auto;
    accent-color: var(--primary); cursor: pointer;
}
.branch-toggle-list .check-toggle span { line-height: 1.2; }

/* ===== Сторінка налаштувань: чистий «повітряний» вигляд + розкривні блоки ===== */
.settings-airy { max-width: 600px; }

/* Картка — тонка світла рамка, скруглення; заголовок усередині, клікабельний */
.settings-airy .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    margin: 0 0 10px;
    max-width: none;
}
.settings-airy .panel-head {
    background: transparent; border: none;
    padding: 10px 14px; gap: 8px; flex-wrap: nowrap;
    cursor: pointer; user-select: none;
}
.settings-airy .panel-head h2 {
    font-size: 13px; font-weight: 500; color: var(--text-soft); letter-spacing: .01em;
    flex: 1;
}
.settings-airy .sec-ico {
    width: 16px; height: 16px; flex: 0 0 auto;
    color: #9fc3ef; stroke-width: 1.7;
}
.settings-airy .sec-chev {
    width: 16px; height: 16px; flex: 0 0 auto;
    color: var(--text-mute); transition: transform .18s ease;
}
.settings-airy .panel.is-collapsed .sec-chev { transform: rotate(-90deg); }

/* Тіло картки */
.settings-airy .form.stacked {
    background: transparent; border: none; box-shadow: none;
    border-radius: 0;
    padding: 0 14px 12px !important;
    gap: 8px;
}
.settings-airy .panel.is-collapsed .form.stacked { display: none; }
.settings-airy .form.stacked > .text-mute:first-child { margin-top: 0; }

/* Рядки-перемикачі — щільні, з м'яким наведенням, світла галочка */
.settings-airy .check-toggle {
    padding: 2px 8px; border-radius: 7px; margin: 0;
    gap: 10px; font-size: 13px; color: var(--text); cursor: pointer;
    transition: background .12s ease;
}
.settings-airy .check-toggle:hover { background: var(--surface-2); }
.settings-airy .check-toggle input[type="checkbox"] {
    width: 15px; height: 15px; margin: 0; flex: 0 0 auto; accent-color: #7fb5f0;
}
.settings-airy .branch-toggle-list { gap: 0; margin: 0; }
.settings-airy .branch-toggle-list .check-toggle { padding: 2px 8px; accent-color: #7fb5f0; }
.settings-airy .branch-toggle-list .check-toggle input[type="checkbox"] { accent-color: #7fb5f0; }

/* Згруповані секції всередині картки — розділювач зверху замість рамки-коробки */
.settings-airy .form-section {
    border: none; background: transparent;
    border-top: 1px solid var(--border);
    border-radius: 0; padding: 12px 0 0; margin-top: 4px;
}
.settings-airy .form-section-title {
    color: var(--text-mute); font-weight: 600; margin-bottom: 6px;
}

/* Поля вводу */
.settings-airy .field-label { color: var(--text-soft); }
.settings-airy .form-section-grid { gap: 12px; }

/* Кнопки дій — світла блакитна схема */
.settings-airy .actions {
    display: flex; align-items: center; gap: 10px;
    margin-top: 4px; padding-top: 10px;
    border-top: 1px solid var(--border);
}
.settings-airy .btn { font-size: 13px; padding: 6px 16px; }
.settings-airy .btn-primary {
    background: #eaf3fe; color: #2569c6; border: 1px solid #cfe3fb; box-shadow: none;
}
.settings-airy .btn-primary:hover { background: #dceafb; box-shadow: none; }
.settings-airy .btn-ghost {
    background: var(--surface); color: var(--text-soft); border: 1px solid var(--border);
}
html[data-theme="dark"] .settings-airy .btn-primary {
    background: #15294a; color: #7fb6ff; border-color: #28324a;
}
html[data-theme="dark"] .settings-airy .btn-primary:hover { background: #1a325c; }
html[data-theme="dark"] .settings-airy .sec-ico { color: #4f7bb5; }

@media (max-width: 720px) {
    .settings-airy .form.stacked { padding: 0 12px 12px !important; }
}

/* Футер: доступ з інших ПК за іменем цього ПК */
.net-footer {
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
    padding: 8px 18px; margin-top: auto;
    border-top: 1px solid var(--border);
    background: var(--panel);
    font-size: 12px; color: var(--text-mute);
}
.net-footer-label { font-weight: 600; }
.net-footer .net-link { color: var(--accent); text-decoration: none; font-variant-numeric: tabular-nums; }
.net-footer .net-link:hover { text-decoration: underline; }
.net-footer .net-hint { font-size: 11px; opacity: .8; }
.net-footer .net-sep { opacity: .5; }
.net-footer .net-copy {
    border: 1px solid var(--border); background: var(--bg); color: var(--text-mute);
    border-radius: 6px; padding: 1px 7px; font-size: 12px; cursor: pointer; line-height: 1.4;
}
.net-footer .net-copy:hover { color: var(--text); }
@media (max-width: 720px) {
    .net-footer { padding: 8px 12px; }
}

/* Футер: кнопки показу QR-кодів */
.net-footer .net-qrs { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: 4px; }
.net-footer .net-qr {
    border: 1px solid var(--accent); background: var(--accent-soft, #eaf3fe); color: var(--accent);
    border-radius: 6px; padding: 2px 9px; font-size: 12px; cursor: pointer; line-height: 1.5; white-space: nowrap;
}
.net-footer .net-qr:hover { background: var(--accent); color: #fff; }

/* ===== Виробництво комбікормів ===== */

/* Шапка документа виробництва — один рядок, як у накладній:
   комбікорм, дата, випуск і підсумки. Склад згортається кнопкою зліва. */
.doc-head {
    display: flex;
    align-items: flex-end;
    /* Один рядок без переносів: примітка завжди лишається праворуч і не
       з'їжджає вниз. На вузьких екранах рядок горизонтально прокручується,
       а не ламається. */
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 12px 16px;
    padding: 14px 20px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.doc-f { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.doc-cap {
    font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-soft); font-weight: 600; white-space: nowrap;
}
.doc-head input, .doc-head select {
    padding: 5px 9px; font-size: 13px;
}
/* Межі ширини для кожного поля шапки: користувач може тягнути повзунок,
   але поле не звузиться до нечитабельного і не розтягнеться на пів екрана.
   min-/max-width сильніші за inline width, тож обмеження діють і після
   перетягування, і при автоматичному стисканні рядка. */
.doc-f-kk    { min-width: 130px; max-width: 240px; }
.doc-f-date  { min-width: 128px; max-width: 170px; }
.doc-f-qty   { min-width: 100px; max-width: 160px; }
.doc-f-price { min-width: 88px;  max-width: 150px; }
.doc-f-sum   { min-width: 130px; max-width: 210px; }

.doc-f-kk select { font-weight: 700; }
.doc-head input[type="date"] { width: 100%; }
.doc-f-qty input { width: 100%; text-align: right; }
/* Примітка — остання, притиснута до правого краю. Займає вільне місце,
   але не безмежно: від 140 до 380 px. */
.doc-f-note {
    flex: 1 1 180px;
    min-width: 140px;
    max-width: 380px;
    margin-left: auto;
}
.doc-f-note input { width: 100%; min-width: 0; }

/* Обчислені підсумки — не поля вводу, тому вирівнюємо по нижньому краю */
.doc-val b {
    font-size: 15px; font-variant-numeric: tabular-nums;
    padding: 5px 0; white-space: nowrap;
}
.doc-val-main b { font-size: 17px; color: var(--primary-strong); }

/* Кнопка згортання складу */
.doc-toggle {
    align-self: center;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text-soft); cursor: pointer;
    width: 26px; height: 26px; border-radius: var(--radius-sm);
    font-size: 11px; line-height: 1;
    transition: transform .15s ease;
}
.doc-toggle:hover { color: var(--text); }
.doc-toggle.is-collapsed { transform: rotate(-90deg); }

@media (max-width: 720px) {
    .doc-head { padding: 12px 14px; gap: 10px 12px; }
}

/* Номер документа праворуч у шапці панелі */
.prod-doc {
    font-size: 12px;
    color: var(--text-mute);
    font-variant-numeric: tabular-nums;
}

.prod-hint {
    margin: 0;
    padding: 0 20px 14px;
    font-size: 12px;
    color: var(--text-soft);
    line-height: 1.5;
}

/* Таблиця компонентів — той самий ритм, що й у розкритому складі рецепта
   («Склад на заміс»): дрібніший шрифт і щільні рядки, щоб увесь заміс
   було видно без прокрутки. */
.prod-table { font-size: 12px; }
/* У комірках є поле вводу (22px проти 17px у звичайного тексту), тому
   вертикальний відступ менший — щоб підсумкова висота рядка збіглася
   з еталонною таблицею «Склад на заміс». */
.prod-table th { padding: 6px 8px; }
.prod-table td { padding: 4px 8px; }
.prod-table .prod-c-act { width: 40px; }
.prod-table td .c-qty {
    width: 92px;
    text-align: right;
    padding: 2px 7px;
    font-size: 12px;
}
.prod-table .btn-icon { padding: 2px 6px; }
/* Червоним — коли треба більше, ніж є на складі */
.prod-table .is-short { color: var(--danger); font-weight: 600; }
.prod-table tfoot td { font-weight: 600; background: var(--surface-2); }
.prod-table tfoot .prod-total td {
    font-size: 14px;
    color: var(--primary-strong);
    border-bottom: none;
}

.prod-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}
.prod-spacer { flex: 1 1 auto; }

@media (max-width: 720px) {
    .prod-form { padding: 16px 14px 12px; gap: 12px; }
    .prod-hint { padding: 0 14px 12px; }
    .prod-actions { padding: 12px 14px; flex-wrap: wrap; }
    .prod-form .field,
    .prod-f-note { flex: 1 1 100%; }
    .prod-form input[type="date"],
    .prod-form input[type="number"],
    .prod-f-kk select { width: 100%; }
}

/* Довідник рецептів: рядок-заголовок + розкриття структури */
.rec-c-tog { width: 42px; }
.rec-row { cursor: default; }
.rec-row td { padding-top: 8px; padding-bottom: 8px; }

/* Редактор рецепта комбікорму.
   Вікно — колонка фіксованої висоти: шапка й кнопки не рухаються, а список
   компонентів займає решту місця й прокручується. Так однаково зручно і з
   чотирма компонентами, і з двадцятьма. */
.rec-modal {
    width: min(560px, 94vw);
    display: flex;
    flex-direction: column;
    max-height: 88vh;
    overflow: hidden;                 /* прокручується лише список */
}
.rec-modal > h2 { padding: 18px 20px 0; flex: none; }
.rec-body {
    display: flex;
    flex-direction: column;
    min-height: 0;                    /* без цього flex не дає списку стискатись */
    padding: 14px 20px 18px;
    gap: 12px;
}

.rec-head { display: flex; flex-wrap: wrap; gap: 12px; }
.rec-f-name { flex: 1 1 190px; }
.rec-f-sample { flex: 1 1 160px; }
.rec-f-note { flex: 1 1 100%; }
.rec-head input, .rec-head select { width: 100%; }
/* [hidden] сам по собі не працює на .field — його перебиває display:flex */
.rec-head .field[hidden] { display: none; }

.rec-modal .prod-hint { padding: 0; font-size: 12px; }

.rec-edit-wrap {
    flex: 1 1 auto;
    min-height: 120px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.rec-edit-table { font-size: 13px; }
.rec-edit-table th, .rec-edit-table td { padding: 3px 12px; }
.rec-edit-table thead th { position: sticky; top: 0; z-index: 1; }
.rec-edit-table .r-qty {
    width: 88px; text-align: right;
    padding: 3px 8px; font-size: 13px;
}
.rec-edit-table .r-share { color: var(--text-soft); }
.rec-edit-table .rec-c-del { width: 36px; text-align: center; }
.rec-edit-table tfoot td {
    font-weight: 600; background: var(--surface-2);
    position: sticky; bottom: 0;
    border-top: 1px solid var(--border);
}

.rec-modal-actions {
    flex: none;
    display: flex; align-items: center; gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
@media (max-width: 620px) {
    .rec-body { padding: 12px 14px 16px; }
    .rec-head .field { flex: 1 1 100%; }
    .rec-modal-actions { flex-wrap: wrap; }
}

/* Точність виготовлення комбікорму */
.acc-ok   { color: var(--success); font-weight: 600; }
.acc-warn { color: var(--warn); font-weight: 600; }
.acc-bad  { color: var(--danger); font-weight: 600; }

/* Дії над партією виробництва — тримаємо кнопки в одному рядку */
.prod-row-act { white-space: nowrap; }
.prod-row-act .btn-icon { padding: 4px 6px; }
.prod-row-act .p-del:hover { color: var(--danger); }



/* Панель нового замісу — зелений відтінок, щоб робочий документ одразу
   відрізнявся від довідкових панелей нижче. Зелений узгоджений із
   --success, тільки сильно розбілений. */
.panel-prod { border-color: #bfe3d2; }
.panel-prod > .panel-head {
    background: #e8f5ef;
    border-bottom-color: #bfe3d2;
}
.panel-prod > .panel-head h2 { color: #14764c; }
.panel-prod .doc-head {
    background: #f2faf6;
    border-bottom-color: #d8ede3;
}
.panel-prod .doc-val-main b { color: #14764c; }
.panel-prod .prod-actions {
    background: #f2faf6;
    border-top-color: #d8ede3;
}
.panel-prod .prod-table tfoot td { background: #f2faf6; }

/* Ручка зміни ширини колонки — трохи помітніша в цих таблицях */
.prod-table th, #recipesTable th { user-select: none; }

/* Ручка зміни ширини поля в рядку-шапці документа. Поля мають менші
   відступи, ніж комірки таблиці, тому ручку трохи звужуємо. */
.field-resizer { width: 6px; right: -8px; }
.doc-head { position: relative; }

/* Виробництво КК: таблиці за вмістом, не на всю ширину вікна; колонки
   тягнуться мишкою. Так само, як на сторінках Виробництва молока. */
#prodTable, #recipesTable, #prodLogTbl { width: auto; }
.prod-tblwrap { overflow-x: auto; }
#prodLogTbl th { position: relative; user-select: none; white-space: nowrap; }

/* Модал імпорту з Profeed */
.pf-modal { width: min(760px, 94vw); display: flex; flex-direction: column;
            max-height: 88vh; overflow: hidden; }
.pf-modal > h2 { padding: 18px 20px 0; flex: none; }
.pf-body { display: flex; flex-direction: column; min-height: 0;
           padding: 14px 20px 0; gap: 10px; }
.pf-dir-row { display: flex; gap: 8px; }
.pf-dir-row input { flex: 1 1 auto; }
.pf-modal .prod-hint { padding: 0; }
.pf-list-wrap { flex: 1 1 auto; min-height: 120px; overflow-y: auto;
                border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pf-table { width: 100%; font-size: 13px; }
.pf-table th, .pf-table td { padding: 5px 10px; }
.pf-table thead th { position: sticky; top: 0; z-index: 1; }
.pf-c-chk { width: 34px; text-align: center; }
.pf-modal .rec-modal-actions { padding: 12px 20px; }
.pf-status { font-size: 12px; color: var(--text-soft); }

/* Кнопка імпорту з Profeed — зелена, у тон панелі виробництва */
.btn-profeed { background: #14764c; border-color: #14764c; }
.btn-profeed:hover { background: #0f5c3b; border-color: #0f5c3b; }

/* «Останні операції» (видача) та «Останні надходження» (прихід):
   дрібніший шрифт і БЕЗ переносу — кожна операція в один рядок.
   Задовгі значення обрізаються трикрапкою, ширину колонок можна тягнути. */
#recentSalesTable, #recentInTable { font-size: 11.5px; }
#recentSalesTable th, #recentSalesTable td,
#recentInTable th, #recentInTable td {
    padding: 3px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

/* Заміси з Profeed у журналі «Останні виробництва» — сірі рядки
   «чернетки»: підтягнуті, але ще не проведені. Провести можна кнопкою. */
/* Шапка «Останні виробництва» — усе в один рядок: статус, поле теки, кнопка.
   Поле стискається й обрізає довгий шлях замість переносу. */
.pf-head { flex-wrap: nowrap; min-width: 0; }
.pf-head .pf-dir-inp {
    flex: 1 1 auto; min-width: 120px; max-width: 340px;
    text-overflow: ellipsis;
}
.pf-head .pf-status { flex: 0 0 auto; white-space: nowrap; }
.pf-head .btn { flex: 0 0 auto; white-space: nowrap; }
/* Панель фільтрів «Останні виробництва» — як у надходженнях */
.rcp-filterbar { padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 12px;
    border-bottom: 1px solid var(--border); }
.rcp-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.rcp-presets .btn.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.rcp-fields { display: flex; gap: 12px; row-gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.rcp-f { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--text-soft); }
.rcp-f > span { padding-left: 2px; }
.rcp-f input { font-size: 13px; height: 34px; }
.rcp-f input[type="date"] { min-width: 140px; }
.rcp-f-grow { flex: 1; min-width: 220px; }
.rcp-f-grow input { width: 100%; }

/* Модал посилання на звіти Profeed */
.pf-dir-modal { max-width: 540px; }
/* .modal-card має відступи лише в h2 — решту вирівнюємо самі */
.pf-dir-modal > p,
.pf-dir-modal > .pf-dir-field,
.pf-dir-modal > .pf-pick-btn,
.pf-dir-modal > .modal-actions { margin-left: 20px; margin-right: 20px; }
.pf-dir-modal > p { margin-top: 6px; }
.pf-dir-field { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; margin-bottom: 8px; }
.pf-dir-inp-full { width: 100%; box-sizing: border-box; font-size: 13px;
    padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); }
.pf-dir-inp-full:focus { outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft); }
.pf-pick-btn { align-self: flex-start; }
.pf-dir-modal > .modal-actions { margin-top: 18px; margin-bottom: 20px;
    display: flex; gap: 8px; justify-content: flex-end; }
/* сірий фон і текст рядка — поки не проведено */
.pf-row td { color: var(--text-soft); background: #fafbfc; }
.pf-row strong { color: var(--text); }
.pf-badge { display: inline-block; font-size: 11px; color: var(--text-soft);
    background: #eef0f3; border: 1px solid #d9dde3; border-radius: 4px; padding: 1px 6px; }
.pf-detail > td { background: #fafbfc; }
.pf-c-act { width: 110px; text-align: right; }
.pf-edit-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
                color: var(--primary-strong); font-weight: 700; margin-bottom: 6px; }
.pf-edit-tbl .pf-comp { width: 100px; text-align: right; padding: 3px 7px; font-size: 12px; }
.pf-edit-tbl tfoot td { font-weight: 600; }

/* Перетягування широкої таблиці мишкою («рука») */
.table-scroll.can-pan, .prod-tblwrap.can-pan { cursor: grab; }
.table-scroll.is-grabbing, .prod-tblwrap.is-grabbing { cursor: grabbing; user-select: none; }

/* Ховаємо горизонтальні смуги прокрутки (як на macOS) — прокручуємо
   перетягуванням мишкою або Shift+колесом. Верхню смужку не показуємо. */
.top-scrollbar { display: none !important; }
.table-scroll::-webkit-scrollbar,
.prod-tblwrap::-webkit-scrollbar { width: 0; height: 0; }
.table-scroll, .prod-tblwrap { scrollbar-width: none; -ms-overflow-style: none; }
