*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #1f2328; background: #f6f8fa; }
a { color: #0969da; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex; align-items: center; gap: 24px;
    padding: 12px 24px; background: #24292f; color: #fff;
    box-shadow: 0 1px 0 rgba(0,0,0,.1);
}
.topbar .brand { color: #fff; font-weight: 600; font-size: 1.1rem; display: inline-flex; align-items: center; gap: 6px; }
.topbar .brand .brand-icon { font-size: 1.2rem; line-height: 1; }
.topbar nav a { color: #d0d7de; margin-right: 16px; }
.topbar nav a:hover { color: #fff; text-decoration: none; }

.page { width: 80%; max-width: none; margin: 16px auto; padding: 0; }

h1 { font-size: 1.6rem; margin: 0 0 12px; }
h2 { font-size: 1.2rem; margin: 24px 0 12px; }

.lead { color: #57606a; max-width: 720px; }

.card { background: #fff; border: 1px solid #d0d7de; border-radius: 6px; padding: 16px 20px; margin: 16px 0; }
.card.muted { background: #fafbfc; }

.events { columns: 2; column-gap: 32px; }
.events > li { break-inside: avoid; margin-bottom: 8px; }
.events ul { margin: 4px 0 0; padding-left: 18px; }

.filters {
    display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end;
    background: #fff; border: 1px solid #d0d7de; border-radius: 6px; padding: 10px 14px;
    margin-bottom: 12px;
}
.filters label { display: flex; flex-direction: column; font-size: 0.85rem; color: #57606a; gap: 4px; }
.filters select, .filters input { font-size: 0.95rem; padding: 4px 8px; border: 1px solid #d0d7de; border-radius: 4px; min-width: 160px; }
.filters select[multiple] { min-width: 280px; }
.filters small { color: #8c959f; font-size: 0.75rem; }
.filters button { padding: 6px 14px; background: #2da44e; color: #fff; border: 0; border-radius: 4px; cursor: pointer; font-size: 0.9rem; }
.filters button:hover { background: #2c974b; }
.filters .btn-link { padding: 6px 8px; }

/* Дашборд: упорядоченные фильтры в две строки */
.dash-filters { flex-direction: column; align-items: stretch; gap: 10px; }
.dash-filters .row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.dash-filters label { gap: 2px; flex: 1 1 180px; min-width: 0; }
.dash-filters label.grow { flex: 2 1 240px; }
.dash-filters label.grow-2 { flex: 3 1 320px; }
.dash-filters label.wide-grow { flex: 1 1 auto; min-width: 0; }
.dash-filters .supplier-row { display: flex; align-items: end; gap: 8px 12px; }
.dash-filters label > span { font-weight: 500; color: #57606a; font-size: 0.8rem; }
.dash-filters label > span em { font-style: normal; color: #8c959f; font-weight: 400; font-size: 0.75rem; }
.dash-filters select, .dash-filters input { width: 100%; min-width: 0; }
.dash-filters .actions { display: flex; gap: 8px; align-items: center; padding-bottom: 1px; }
.dash-filters .hint { margin: 4px 2px 0; font-size: 0.78rem; color: #8c959f; }
.dash-filters .hint strong { color: #57606a; font-weight: 600; }

.dash-filters .row.tight { gap: 8px; align-items: center; }
.dash-filters .toggle-pill {
    flex: 0 0 auto;
    flex-direction: row; align-items: center; gap: 6px;
    background: #f6f8fa; border: 1px solid #d0d7de; border-radius: 999px;
    padding: 4px 12px 4px 8px; cursor: pointer;
    font-size: 0.85rem;
}
.dash-filters .toggle-pill:has(input:checked) { background: #ddf4e0; border-color: #2da44e; color: #1a7f37; }
.dash-filters .toggle-pill input { width: auto; min-width: 0; margin: 0; }
.dash-filters .toggle-pill span { font-weight: 500; color: inherit; font-size: inherit; }
.dash-filters .toggle-pill.mini { padding: 6px 10px 6px 8px; font-size: 0.78rem; align-self: flex-end; margin-bottom: 1px; }

.dash-filters .anchor-cluster {
    display: flex; align-items: end; gap: 6px;
    padding: 4px 8px;
    background: #fff8c5; border: 1px solid #d4a72c33; border-radius: 6px;
    flex: 0 1 auto;
}
.dash-filters .anchor-cluster .anchor-field { flex: 0 0 auto; }
.dash-filters .anchor-cluster .anchor-field input { min-width: 130px; }
.dash-filters .advanced {
    flex: 1 1 auto; min-width: 240px;
    background: #fafbfc; border: 1px solid #d0d7de; border-radius: 6px; padding: 4px 12px;
    font-size: 0.8rem;
}
.dash-filters .advanced summary {
    cursor: pointer; user-select: none; color: #57606a; padding: 2px 0;
    font-weight: 500;
}
.dash-filters .advanced summary .muted { color: #8c959f; font-weight: 400; margin-left: 6px; }
.dash-filters .advanced[open] summary { border-bottom: 1px solid #eaeef2; padding-bottom: 6px; margin-bottom: 8px; }
.dash-filters .advanced .advanced-grid {
    display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end;
}
.dash-filters .advanced .advanced-grid label { flex: 1 1 140px; }
.dash-filters .advanced .hint { margin: 6px 0 2px; }

/* Orders page: одна flex-лента, без вложенных строк */
.orders-filters { gap: 8px 12px; align-items: end; }
.orders-filters label { flex: 0 1 auto; min-width: 0; gap: 2px; }
.orders-filters label.grow { flex: 1 1 240px; max-width: 380px; }
.orders-filters label.narrow { flex: 0 0 auto; width: 130px; }
.orders-filters label > span { font-size: 0.78rem; color: #57606a; font-weight: 500; white-space: nowrap; }
.orders-filters label > span em { font-style: normal; color: #8c959f; font-weight: 400; font-size: 0.75rem; }
.orders-filters select, .orders-filters input { width: 100%; min-width: 0; }
.orders-filters .actions { display: flex; gap: 8px; align-items: center; padding-bottom: 1px; margin-left: auto; }

/* Tom Select compact — chips в одну строку, без переноса. Это держит высоту
   поля константной (~32px) независимо от количества выбранных и не ломает
   align-items:end в соседних полях. При большом числе chips — горизонтальный
   скролл. Длинные названия chip обрезаются ellipsis-ом. */
.ts-wrapper.multi .ts-control {
    padding: 3px 6px !important;
    min-height: 32px !important;
    height: 32px !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}
.ts-wrapper.multi .ts-control > .item {
    padding: 1px 6px !important;
    margin: 0 4px 0 0 !important;
    font-size: 0.82rem !important;
    line-height: 1.3 !important;
    flex-shrink: 0 !important;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ts-wrapper.multi .ts-control > input {
    flex: 0 0 60px !important;
    min-width: 60px !important;
    width: 60px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 1px 4px !important;
    font-size: 0.85rem !important;
}
.ts-wrapper.multi .ts-control > input::placeholder {
    color: #8c959f;
    opacity: 1;
}
.ts-wrapper { line-height: 1.2; }

.meta { color: #57606a; font-size: 0.9rem; }

.grid { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #d0d7de; border-radius: 6px; overflow: hidden; }
.grid th, .grid td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #eaeef2; font-size: 0.9rem; vertical-align: top; }
.grid th { background: #f6f8fa; font-weight: 600; color: #1f2328; position: sticky; top: 0; }
.grid tr:last-child td { border-bottom: 0; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid th.num, .grid td.num { width: 1%; white-space: nowrap; padding-right: 14px; }
.grid th.num { padding-right: 14px; }
.grid th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 18px; }
.grid th.sortable::after { content: ' ↕'; color: #b1bac4; font-weight: 400; font-size: 0.85em; }
.grid th.sort-asc::after { content: ' ↑'; color: #1f2328; }
.grid th.sort-desc::after { content: ' ↓'; color: #1f2328; }
.grid th.sortable.num { padding-right: 22px; }
.grid .empty { text-align: center; padding: 24px; color: #8c959f; }

.drift-late { color: #b35900; font-weight: 600; }
.drift-early { color: #1a7f37; font-weight: 600; }

table .filter-row th { padding: 4px; background: #fafbfc; }
table .filter-row input {
    width: 100%; padding: 3px 6px; font-size: 0.8rem;
    border: 1px solid #d0d7de; border-radius: 3px;
}
table .filter-row input:focus { outline: 2px solid #0969da; outline-offset: -1px; }

.factory-stats {
    margin: 16px 0;
    background: #fff; border: 1px solid #d0d7de; border-radius: 6px; padding: 8px 16px;
}
.factory-stats summary { cursor: pointer; padding: 4px 0; font-size: 0.95rem; color: #57606a; }
.factory-stats summary strong { color: #1f2328; }
.factory-stats[open] summary { border-bottom: 1px solid #eaeef2; padding-bottom: 8px; margin-bottom: 8px; }
.factory-stats table.grid { font-size: 0.85rem; }
.factory-stats small { color: #8c959f; font-weight: 400; }

.hint { font-size: 0.82rem; color: #8c959f; margin: 6px 0 4px; }
.hint.inline { display: inline; margin-left: 8px; }
.hint code { background: #f0f3f6; padding: 1px 5px; border-radius: 3px; font-size: 0.8rem; }

.table-toolbar { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.table-toolbar .btn-link { padding: 4px 10px; border: 1px solid #d0d7de; border-radius: 4px; background: #f6f8fa; }
.table-toolbar .btn-link:hover { background: #eaeef2; text-decoration: none; }
.table-toolbar .btn-link.active { background: #ddf4e0; border-color: #2da44e; color: #1a7f37; }

/* Col-picker dropdown в сводной по фабрикам */
.col-picker { display: inline-block; position: relative; }
.col-picker > summary {
    cursor: pointer; user-select: none;
    padding: 4px 10px; border: 1px solid #d0d7de; border-radius: 4px;
    background: #f6f8fa; font-size: 0.85rem; list-style: none;
}
.col-picker > summary::-webkit-details-marker { display: none; }
.col-picker > summary::marker { content: ''; }
.col-picker > summary:hover { background: #eaeef2; }
.col-picker[open] > summary { background: #ddf4e0; border-color: #2da44e; color: #1a7f37; }
.col-picker-menu {
    position: absolute; z-index: 20;
    top: calc(100% + 4px); left: 0;
    background: #fff; border: 1px solid #d0d7de; border-radius: 6px;
    padding: 8px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
    white-space: nowrap; min-width: 220px;
}
.col-picker-menu label {
    display: flex; align-items: center; gap: 8px;
    padding: 3px 0; font-size: 0.88rem; cursor: pointer;
}
.col-picker-menu label:hover { color: #0969da; }
.col-picker-menu input[type=checkbox] { margin: 0; }

/* Главный чарт дашборда: заголовок + переключатель режима */
.dash-row-full > .chart-main-card { flex: 1 1 100%; }
.chart-main-card { width: 100%; }
.chart-main-card #chart-main { min-height: 360px; }
.chart-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 8px; flex-wrap: wrap;
}
.chart-header .card-title { margin: 0; }
.chart-header .card-title .muted { color: #8c959f; font-weight: 400; font-size: 0.85em; }
.chart-mode-toggle { display: flex; gap: 6px; }

.header-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 24px; background: #fff; border: 1px solid #d0d7de; border-radius: 6px; padding: 16px; margin-bottom: 16px; }
.note { background: #fff8c5; border: 1px solid #d4a72c; border-radius: 4px; padding: 8px 12px; display: inline-block; }

#chart { background: #fff; border: 1px solid #d0d7de; border-radius: 6px; padding: 12px; margin-bottom: 16px; min-height: 320px; }

.topbar .user { margin-left: auto; color: #d0d7de; font-size: 0.85rem; }
.topbar .user a { color: #d0d7de; }
.topbar .user a:hover { color: #fff; }

.dash-row { display: grid; gap: 16px; margin-bottom: 16px; grid-template-columns: 1fr 1fr; }
.dash-row.pivot-row { grid-template-columns: 3fr 1fr; }
.card-title { font-size: 0.95rem; font-weight: 600; text-align: center; color: #57606a; margin: 0 0 8px; }
.chart-card { padding: 12px 16px 4px; }
.chart-card > div[id^="chart-"] { min-height: 240px; }

.pivot-card, .orders-card { padding: 8px; }
.pivot-scroll, .orders-scroll { max-height: 600px; overflow: auto; }

table.pivot { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
table.pivot th, table.pivot td { padding: 4px 8px; border-bottom: 1px solid #eaeef2; white-space: nowrap; }
table.pivot th { position: sticky; top: 0; background: #f6f8fa; z-index: 2; font-weight: 600; }
table.pivot th.row-header { text-align: left; min-width: 240px; }
table.pivot td.row-header { font-weight: 500; }
table.pivot td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.pivot td.total-col, table.pivot th.total-col { background: #f0f3f6; font-weight: 600; }
table.pivot tr.lvl-supplier > td { background: #fff; font-weight: 700; }
table.pivot tr.lvl-article > td { background: #fafbfc; }
table.pivot tr.lvl-article td.row-header { padding-left: 18px; font-weight: 500; }
table.pivot tr.lvl-color > td { background: #fff; }
table.pivot tr.lvl-color td.row-header { padding-left: 36px; color: #57606a; }
table.pivot tr.lvl-color td.cell-color { background: #d4f5d4; }
table.pivot tr.lvl-color td.cell-color:empty { background: #fff; }
table.pivot tr.lvl-total > td { background: #e6ebef; font-weight: 700; border-top: 2px solid #d0d7de; }
table.pivot .caret {
    display: inline-block; width: 14px; cursor: pointer; user-select: none;
    color: #8c959f; font-size: 0.7rem; text-align: center; margin-right: 4px;
}
table.pivot .caret:hover { color: #1f2328; }
table.pivot .lbl { vertical-align: middle; }
table.pivot .muted { color: #8c959f; font-weight: 400; font-size: 0.78rem; }
table.pivot tr.hidden-row { display: none; }
table.pivot td.hidden-col, table.pivot th.hidden-col { display: none; }
table.orders tr.hidden-row { display: none; }

.month-bar {
    background: #fff8c5; border: 1px solid #d4a72c; border-radius: 6px;
    padding: 6px 12px; margin-bottom: 12px;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.85rem;
}
.month-bar .chip {
    background: #d4a72c; color: #fff; padding: 2px 8px; border-radius: 999px;
    cursor: pointer; user-select: none; font-size: 0.78rem;
}
.month-bar .chip:hover { background: #b08220; }
.month-bar .hint-inline { margin-left: auto; color: #8c959f; font-size: 0.78rem; }
.month-bar .btn-link { color: #57606a; }

/* Floating feedback button + modal */
.feedback-fab {
    position: fixed; right: 24px; bottom: 24px;
    background: #24292f; color: #fff; border: 0; border-radius: 999px;
    padding: 10px 18px; font-size: 0.9rem; font-weight: 500;
    cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.18);
    z-index: 1000;
}
.feedback-fab:hover { background: #1f2328; }
.feedback-modal {
    position: fixed; inset: 0;
    background: rgba(15, 17, 21, .55);
    display: flex; align-items: center; justify-content: center;
    z-index: 1001;
}
.feedback-card {
    background: #fff; width: min(520px, 92vw); border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0,0,0,.25);
    overflow: hidden;
}
.feedback-card header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid #eaeef2;
}
.feedback-card header h3 { margin: 0; font-size: 1.05rem; }
.feedback-close {
    background: transparent; border: 0; cursor: pointer;
    font-size: 1.1rem; color: #57606a; padding: 4px 8px;
}
.feedback-close:hover { color: #1f2328; }
.feedback-card form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.feedback-kind { display: flex; gap: 16px; }
.feedback-kind label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.feedback-card textarea {
    width: 100%; resize: vertical; font: inherit; padding: 8px 10px;
    border: 1px solid #d0d7de; border-radius: 4px;
}
.feedback-card textarea:focus { outline: 2px solid #0969da; outline-offset: -1px; }
.feedback-hint { margin: 0; font-size: 0.78rem; color: #8c959f; }
.feedback-actions { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.feedback-actions button {
    padding: 6px 16px; background: #2da44e; color: #fff; border: 0;
    border-radius: 4px; cursor: pointer; font-size: 0.9rem;
}
.feedback-actions button:hover { background: #2c974b; }
.feedback-status { margin-right: auto; font-size: 0.85rem; color: #57606a; }

/* Убираем браузерный focus-outline на SVG-барах ApexCharts */
.apexcharts-bar-area, .apexcharts-bar-area:focus, .apexcharts-bar-area:active,
.apexcharts-xaxis-texts-g text:focus { outline: none !important; }
.apexcharts-bar-area { transition: opacity 150ms; }

table.orders { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
table.orders th, table.orders td { padding: 4px 8px; border-bottom: 1px solid #eaeef2; }
table.orders th { position: sticky; top: 0; background: #f6f8fa; font-weight: 600; }
table.orders td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.orders td.heat { font-weight: 600; }
