:root {
  --bordo: #671C32;
  --bordo-soft: #8a3a50;
  --cream: #F1E7DB;
  --cream-2: #f8f2ea;
  --ink: #0F1822;
  --gray: #7A868E;
  --line: #e2d8cc;
  --mint: #ABE3E4;
  --green: #2e7d4f;
  --red: #b3261e;
  --radius: 6px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--cream-2); }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* верхня панель */
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; background: var(--bordo); color: var(--cream); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand a { display: flex; }
.logo { height: 38px; width: auto; display: block; }   /* овальний логотип; навколо лишається вільне поле */
.brand-sub { opacity: .75; font-size: 13px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tab { display: flex; align-items: center; padding: 0 16px; color: var(--cream); text-decoration: none; border-bottom: 3px solid transparent; }
.tab.active { border-bottom-color: var(--mint); font-weight: 600; }
.tab.disabled { opacity: .45; cursor: default; }
.data-info { margin-left: auto; font-size: 12px; opacity: .8; }

/* період і фільтри */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-start; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.period { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.btn-row { display: flex; }
.btn-row button { border: 1px solid var(--line); background: #fff; padding: 5px 12px; margin-left: -1px; color: var(--ink); }
.btn-row button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-row button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.btn-row button.on { background: var(--bordo); border-color: var(--bordo); color: #fff; position: relative; z-index: 1; }
.btn-row button.off { color: #b9b1a8; }
.months button { padding: 5px 9px; min-width: 42px; }
.period-hint { color: var(--gray); font-size: 12px; }
.range { display: flex; gap: 8px; align-items: center; color: var(--gray); }
.range input { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 6px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--cream); border: 1px solid #e0cfbd; border-radius: 16px; padding: 3px 6px 3px 10px; font-size: 13px; max-width: 360px; }
.chip b { font-weight: 600; }
.chip .val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: transparent; color: var(--bordo); padding: 0 4px; font-size: 15px; line-height: 1; }
.btn { background: var(--bordo); color: #fff; border: 0; border-radius: var(--radius); padding: 6px 14px; }
.btn:hover { background: var(--bordo-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; border: 1px dashed var(--bordo); color: var(--bordo); border-radius: var(--radius); padding: 4px 12px; }
.icon { border: 0; background: transparent; font-size: 18px; color: var(--gray); }

/* основна частина */
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; padding: 16px 20px; align-items: start; }
.dims-panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; position: sticky; top: 12px; max-height: calc(100vh - 170px); overflow: auto; }
.dims-panel h3 { margin: 0 0 8px; font-size: 14px; color: var(--bordo); }
.dims-panel input { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 8px; margin-bottom: 8px; }
.dim-group { margin-top: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--gray); }
.dim-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 5px 6px; border-bottom: 1px solid #f1ebe3; color: var(--ink); }
.dim-item:hover { background: var(--cream-2); }
.dim-item.used { color: #b9b1a8; cursor: default; }
/* ліве меню СВОДу: вкладки «Виміри / Показники»; показники — групи, що розгортаються, з галочками */
.panel-tabs { margin-bottom: 8px; }
.panel-tabs button { flex: 1; }
.panel-hint { font-size: 12px; color: var(--gray); margin-bottom: 8px; }
.measure-group { display: flex; align-items: center; gap: 6px; margin-top: 6px; padding: 5px 2px; border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 600; color: var(--bordo); }
.measure-group .arrow { width: 12px; color: var(--gray); font-size: 11px; }
.measure-group .count { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--gray); }
.measure-group input, .measure-item input { width: auto; margin: 0; }
.measure-item { display: flex; align-items: flex-start; gap: 6px; padding: 4px 2px 4px 20px; border-bottom: 1px solid #f1ebe3; cursor: pointer; line-height: 1.25; }
.measure-item:hover { background: var(--cream-2); }
.measure-item input { margin-top: 2px; flex: none; }

.content { min-width: 0; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; margin-bottom: 10px; }
.selected-dims { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 380px; min-height: 30px; align-items: center; }
.selected-dims .hint { color: var(--gray); }
.dchip { display: inline-flex; align-items: center; background: #fff; border: 1px solid var(--bordo); color: var(--bordo); border-radius: var(--radius); font-weight: 600; font-size: 13px; }
.dchip span { padding: 4px 8px; }
.dchip button { border: 0; border-left: 1px solid #e7d6dc; background: transparent; color: var(--bordo); padding: 4px 6px; }
.dchip .arrow { color: var(--bordo); opacity: .8; }
.measure-groups { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.measure-groups .label { font-weight: 600; color: var(--bordo); }
.measure-groups #groups { display: flex; gap: 12px; }
.measure-groups label, .toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
input[type=checkbox] { accent-color: var(--bordo); }
.actions { display: flex; gap: 12px; align-items: center; margin-left: auto; }
.status { font-size: 12px; color: var(--gray); }

/* зведена таблиця */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 230px); position: relative; }
.pivot { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
.pivot th { position: sticky; top: 0; z-index: 2; background: var(--bordo); color: #fff; font-weight: 600; font-size: 12.5px; padding: 8px 10px; text-align: right; vertical-align: bottom; border-right: 1px solid rgba(255,255,255,.15); }
.pivot th:first-child { text-align: left; left: 0; z-index: 3; min-width: 320px; }
.pivot th .sub { display: block; font-weight: 400; opacity: .75; font-size: 11px; }
.pivot td { padding: 6px 10px; border-bottom: 1px solid #f1ebe3; text-align: right; white-space: nowrap; }
.pivot td:first-child { text-align: left; position: sticky; left: 0; background: inherit; white-space: normal; min-width: 320px; }
.pivot tr { background: #fff; }
.pivot tr:hover { background: var(--cream-2); }
.pivot tr.total { background: var(--cream); font-weight: 700; }
.pivot tr.total td { border-bottom: 2px solid #e0cfbd; position: sticky; top: 38px; z-index: 1; }
.pivot tr.total td:first-child { z-index: 2; }
.pivot tr.parent { font-weight: 600; }
.pivot .toggle-btn { display: inline-flex; width: 18px; height: 18px; align-items: center; justify-content: center; border: 1px solid #d8c9b9; border-radius: 3px; background: #fff; color: var(--bordo); font-size: 13px; margin-right: 6px; padding: 0; line-height: 1; vertical-align: -3px; }
.pivot .leaf-pad { display: inline-block; width: 24px; }
.pivot td.py { color: var(--gray); }
.pivot td.up { color: var(--green); }
.pivot td.down { color: var(--red); }
.pivot tr.loading td { color: var(--gray); font-style: italic; }
.empty { padding: 40px; text-align: center; color: var(--gray); }
.hidden { display: none !important; }

/* поповер фільтра */
.popover { position: absolute; z-index: 20; width: 360px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(15,24,34,.18); padding: 10px; }
.pop-head { display: flex; gap: 8px; }
.pop-head select { flex: 1; border: 1px solid var(--line); border-radius: var(--radius); padding: 5px; }
.popover input[type=search] { width: 100%; margin: 8px 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 8px; }
.pop-values { max-height: 300px; overflow: auto; border-top: 1px solid #f1ebe3; }
.pop-values label { display: flex; gap: 8px; padding: 4px 2px; cursor: pointer; }
.pop-foot { display: flex; justify-content: space-between; margin-top: 8px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .dims-panel { position: static; max-height: 260px; }
}

/* Конструктор */
a.tab:hover { background: rgba(255,255,255,.08); }
.builder h3 { margin: 14px 0 6px; }
.builder h3:first-child { margin-top: 0; }
.builder select, .controls select { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 6px; background: #fff; }
.controls select { width: auto; }
.builder .toggle { display: flex; margin-top: 6px; }
.chart-types { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.chart-types button { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 5px 4px; color: var(--ink); font-size: 13px; }
.chart-types button.on { background: var(--bordo); border-color: var(--bordo); color: #fff; }
.measure-list { max-height: 240px; overflow: auto; border: 1px solid #f1ebe3; border-radius: var(--radius); padding: 4px 6px; }
.measure-list label { display: flex; gap: 6px; padding: 3px 0; cursor: pointer; align-items: flex-start; }
.title-input { flex: 1 1 280px; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; font-weight: 600; color: var(--bordo); }
.saved { display: flex; gap: 6px; align-items: center; }
.saved select { max-width: 220px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.chart-card { padding: 10px 12px; }
#chart { height: 460px; }
.note { font-size: 12px; color: var(--gray); margin: 6px 2px; min-height: 16px; }
.chart-table { max-height: 320px; }
.chart-table .pivot th:first-child, .chart-table .pivot td:first-child { min-width: 220px; }
.builder input[type=checkbox] { width: auto; margin: 2px 0 0; flex: none; }

/* Дашборд */
.dash { padding: 16px 20px; }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.dash-card { position: relative; padding: 8px 10px; min-width: 0; }
.dash-card.wide { grid-column: 1 / -1; }
.dash-chart { height: 360px; }
.dash-card.wide .dash-chart { height: 420px; }
.dash-card .note { margin: 2px 2px 0; }
.dash-card .failed { height: 360px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--red); padding: 0 40px; }
.dash-tools { position: absolute; top: 6px; right: 8px; z-index: 5; display: flex; gap: 2px; opacity: 0; transition: opacity .15s; background: rgba(255,255,255,.92); border-radius: var(--radius); }
.dash-card:hover .dash-tools, .dash-tools:focus-within { opacity: 1; }
.dash-tools button, .dash-tools a { border: 1px solid var(--line); background: #fff; border-radius: 4px; color: var(--bordo); width: 28px; height: 26px; padding: 0; line-height: 24px; text-align: center; text-decoration: none; font-size: 14px; }
.dash-tools button:hover, .dash-tools a:hover { background: var(--cream); }
.dash-tools button:disabled { opacity: .35; cursor: default; }
.print-head, .print-img { display: none; }
@media (max-width: 1000px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }

/* друк дашборду → PDF: без панелей, графіки — картинками (canvas не масштабується під сторінку) */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  .dash-page { background: #fff; }
  .dash-page .topbar, .dash-page .toolbar, .dash-page .controls, .dash-page .dash-tools, .dash-page .popover { display: none !important; }
  .dash-page .dash { padding: 0; }
  .dash-page .print-head { display: block; border-left: 6px solid var(--bordo); padding: 2px 0 2px 12px; margin-bottom: 10px; }
  .dash-page .print-head h1 { margin: 0; font-size: 20px; color: var(--bordo); }
  .dash-page .print-head div { color: var(--gray); font-size: 12px; }
  .dash-page .dash-grid { gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-page .dash-card { break-inside: avoid; padding: 4px 6px; }
  .dash-page .dash-chart { display: none; }
  .dash-page .print-img { display: block; width: 100%; }
}

/* СВОД: перемикач «Дерево / Таблиця» і плоска таблиця (кожен вимір — колонка) */
.btn-row.mode button { padding: 4px 12px; font-size: 13px; }
.pivot.flat th.dim, .pivot.flat td.dim { text-align: left; min-width: 0; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.pivot.flat th:first-child, .pivot.flat td:first-child { min-width: 0; }
.pivot.flat tr.total td.dim { white-space: nowrap; }

/* LFL */
.lfl-period { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.lfl-period label { color: var(--gray); display: inline-flex; gap: 6px; align-items: center; }
.lfl-period input[type=date], .lfl-bar select { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 6px; background: #fff; }
.lfl { padding: 16px 20px; }
.lfl-bar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 12px; }
.lfl-bar label { display: inline-flex; gap: 6px; align-items: center; color: var(--gray); }
.lfl-bar select { color: var(--ink); max-width: 320px; }
.lfl-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; min-width: 0; }
.kpi .cap { font-size: 12px; color: var(--gray); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .val { font-size: 22px; font-weight: 700; color: var(--bordo); font-variant-numeric: tabular-nums; }
.kpi .val.up { color: var(--green); }
.kpi .val.down { color: var(--red); }
.kpi .sub { font-size: 12px; color: var(--gray); }
.lfl-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.lfl-charts .card { padding: 8px 10px; min-width: 0; }
.lfl-chart { height: 340px; }
.lfl-table { max-height: 560px; }
.lfl-table .pivot th { cursor: pointer; user-select: none; }
.lfl-table .pivot th:first-child, .lfl-table .pivot td:first-child { min-width: 280px; }
.tag { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: 12px; }
.tag.both { background: var(--cream); color: var(--ink); }
.tag.new { background: #dff1e5; color: var(--green); }
.tag.lost { background: #f9dedc; color: var(--red); }
@media (max-width: 1000px) { .lfl-charts, .lfl-kpis { grid-template-columns: minmax(0, 1fr); } }
.lfl-custom { display: inline-flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.lfl-charts.single { grid-template-columns: minmax(0, 1fr); }
.kpi .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* вхід і користувач */
.user-box { font-size: 12px; opacity: .9; white-space: nowrap; }
.user-box a { color: var(--mint); margin-left: 8px; }
.chip.locked { background: #efe6ea; border-color: #d9c3cc; color: var(--bordo); padding-right: 10px; }
.login-page { min-height: 100vh; background: var(--bordo); position: relative; overflow: hidden; }
/* фірмовий елемент «Х» — великий, праворуч, обрізаний краєм екрана (як у логобуку) */
.login-x { position: absolute; top: 0; right: -18vh; height: 100vh; aspect-ratio: 1487 / 1080; opacity: .09; pointer-events: none;
  background: url(brand/x-cream.svg) center / contain no-repeat; }
.login-grid { position: relative; display: grid; grid-template-columns: 1.15fr 1fr; align-items: center; justify-items: center; min-height: 100vh; padding: 24px; gap: 24px; }
/* фото продукції без фону — ліворуч, майже на всю висоту екрана; змінюються самі */
.carousel { position: relative; width: 100%; height: calc(100vh - 80px); }
.carousel .slide { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transform: scale(.97); transition: opacity 1s ease, transform 1s ease; filter: drop-shadow(0 18px 28px rgba(0,0,0,.35)); }
.carousel .slide.on { opacity: 1; transform: none; }
.login-grid .login-card { position: relative; left: -80px; }
@media (max-width: 1100px) { .login-grid { grid-template-columns: minmax(0, 1fr); } .carousel { display: none; } .login-grid .login-card { left: 0; } }
@media (prefers-reduced-motion: reduce) { .carousel .slide { transition: none; } }
.login-card { background: #fff; border-radius: 10px; padding: 28px 30px; width: 340px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--gray); margin-bottom: 4px; }
.login-brand .logo { height: 72px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--gray); font-size: 13px; }
.login-card input[type=text], .login-card input[type=password] { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; font-size: 15px; }
.login-card .btn { padding: 9px 14px; font-size: 15px; }
.login-error { background: #f9dedc; color: var(--red); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; }

/* сторінки без даних: пароль, користувачі */
.plain-page { max-width: 1180px; margin: 0 auto; padding: 18px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; overflow-x: auto; }
.card.narrow { max-width: 420px; }
.card h2 { margin: 0 0 10px; font-size: 16px; color: var(--bordo); }
.card h2 .muted { font-size: 12px; font-weight: 400; margin-left: 8px; }
.muted { color: var(--gray); }
.nowrap { white-space: nowrap; }
.flash { border-radius: var(--radius); padding: 9px 12px; }
.flash.ok { background: #e2f1e7; color: var(--green); }
.flash.error { background: #f9dedc; color: var(--red); }
.form-col { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-col label, .form-row label { display: flex; flex-direction: column; gap: 4px; color: var(--gray); font-size: 13px; }
.plain-page input[type=text], .plain-page input[type=password], .plain-page select { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; color: var(--ink); background: #fff; }
.plain-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.plain-table th { text-align: left; color: var(--gray); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.plain-table td { padding: 6px 8px; border-bottom: 1px solid #f0e9df; vertical-align: middle; }
.plain-table tr.warn td { color: var(--red); }
.users-table form { margin: 0; }
.users-table input[type=text] { width: 100%; min-width: 150px; }
.btn-ghost.danger { border-color: var(--red); color: var(--red); }
