:root {
  --green: #2e7d32; --blue: #1565c0; --orange: #ef6c00;
  --purple: #6a1b9a; --red: #c62828; --gray: #607d8b;
  --bg: #f5f6f8; --card: rgba(255,255,255,.78); --line: #e6e0ee; --text: #1c2430; --muted: #8a95a3;
}
* { box-sizing: border-box; }
/* вкладка «Чистая прибыль»: группировка 1шт+партия одной позиции */
#profit-table tr.profit-unit td { border-top: 2px solid var(--line); }
#profit-table tr.profit-batch td { color: #55606e; background: rgba(106,27,154,.03); }
#profit-table .sale-cell { background: #fffbe6; cursor: text; min-width: 70px; }
#profit-table .sale-cell:focus { outline: 2px solid var(--blue); background: #fff; }
#profit-table .sale-date { border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; font-size: 13px; }
#profit-table td.pos { color: var(--green); font-weight: 700; }
#profit-table td.neg { color: var(--red); font-weight: 700; }
#profit-table .deliv-src { font-size: 10px; color: var(--muted); font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; margin-left: auto; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text); font-size: 14px;
  /* анимешный пастельный фон: сакура → небо → лаванда + лёгкие лепестки */
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'><g fill='%23ff9ec4' fill-opacity='0.13'><path d='M30 20c4 0 7 3 7 7 0-4 3-7 7-7-4 0-7-3-7-7 0 4-3 7-7 7z'/><path d='M95 75c4 0 7 3 7 7 0-4 3-7 7-7-4 0-7-3-7-7 0 4-3 7-7 7z'/></g><g fill='%237ec8ff' fill-opacity='0.12'><circle cx='80' cy='25' r='3'/><circle cx='20' cy='90' r='3'/></g></svg>"),
    radial-gradient(circle at 18% 12%, rgba(255,183,213,.55), transparent 55%),
    radial-gradient(circle at 86% 18%, rgba(168,216,255,.5), transparent 55%),
    radial-gradient(circle at 50% 100%, rgba(206,181,255,.45), transparent 60%),
    linear-gradient(135deg, #fdeef7 0%, #eaf5ff 48%, #f3ecff 100%);
  min-height: 100vh;
}
/* переключатель «кто я» (авторство правок) */
.me-picker { position: fixed; right: 12px; bottom: 12px; z-index: 60;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 9px; font-size: 12px; color: var(--muted);
  box-shadow: 0 4px 14px rgba(120,110,170,.18); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.me-picker select { font-size: 12px; padding: 2px 4px; border: 1px solid var(--line); border-radius: 6px; }
body.demo .me-picker { display: none !important; }

/* ── Демо-режим: плашка + скрытие всех кнопок правки/записи ── */
.demo-bar { position: sticky; top: 0; z-index: 50; text-align: center;
  background: #6a1b9a; color: #fff; font-size: 13px; font-weight: 600;
  padding: 7px 12px; letter-spacing: .2px; }
/* в демо прячем ВСЕ кнопки действий/выгрузки/правки (Excel, Для Сани,
   добавить, сохранить, удалить, ✎, ✖ и т.п.). Остаются: вкладки и просмотр. */
body.demo .btn,
body.demo a.btn,
body.demo .icon-btn,
body.demo .row-del,
body.demo .toolbar a,
body.demo .link { display: none !important; }
/* фильтры тоже не нужны в витрине */
body.demo .toolbar select,
body.demo .toolbar input { display: none !important; }
/* редактирование ячеек и выпадающих статусов — заблокировано */
body.demo [contenteditable] { cursor: default; }
body.demo #orders-table select { pointer-events: none; opacity: .85; }

/* ── Баннер-шапка (картинка header.png 1419×299), наложения по % ── */
header {
  position: relative; width: 100%; aspect-ratio: 1419 / 299;
  background: url("/static/header.jpg") center/100% 100% no-repeat;
  padding: 0; border: 0; overflow: hidden;
}
/* гифка — в левый чёрный квадрат (портрет), кадрируем на девушку */
.head-gif {
  position: absolute; left: 0.35%; top: 3.7%; width: 12.9%; height: 92.6%;
  object-fit: cover; object-position: center 28%; border-radius: 0; display: block;
}
.head-gif-m { display: none; }  /* короткий ролик — только на телефоне */
header video { background: #0d0718; }  /* пока кадр не пришёл — не белая дыра */
/* логотип из презентации поверх шапки: «парение» + блик ПО БУКВАМ (по маске) */
.brand {
  position: absolute; left: 13.5%; top: 30%; width: 26%; height: 40%; z-index: 3;
  pointer-events: none; animation: logo-float 3.4s ease-in-out infinite;
}
.brand img {
  width: 100%; height: 100%; object-fit: contain; object-position: left center;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.35));  /* только мягкая тень, без свечения */
}
.brand::after {  /* блик скользит по форме самих букв логотипа */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 43%, rgba(255,255,255,.9) 50%, transparent 57%);
  background-size: 220% 100%; background-repeat: no-repeat;
  -webkit-mask: url("/static/logo.png?v=1") left center/contain no-repeat;
          mask: url("/static/logo.png?v=1") left center/contain no-repeat;
  animation: logo-glint 3.6s ease-in-out infinite;
}
@keyframes logo-float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-5px) scale(1.02); }
}
@keyframes logo-glint { 0% { background-position: 210% 0; } 55%, 100% { background-position: -70% 0; } }
/* три метрики поверх правых чёрных квадратов */
.balances {
  position: absolute; left: 61.0%; width: 37.5%; top: 29.8%; height: 34.1%;
  display: flex; justify-content: space-between; gap: 0; margin: 0; padding: 0;
}
.bal {
  flex: 0 0 31.8%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.bal:nth-child(n+4) { display: none; }   /* в баннере только 3 метрики */
.bal .label { font-size: clamp(7px, .82vw, 12px); color: #d9dde6;
  text-transform: uppercase; line-height: 1.05; letter-spacing: .2px; }
.bal .val { font-size: clamp(13px, 1.9vw, 30px); font-weight: 700; color: #fff;
  font-variant-numeric: tabular-nums; line-height: 1.1; }
.bal .val.neg { color: #ff5a5f; }

.tabs { display: flex; gap: 4px; padding: 10px 22px 0; }
.tab {
  border: none; background: transparent; padding: 8px 16px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--blue); font-weight: 600; }

.panel { display: none; padding: 16px 22px; }
.panel.active { display: block; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
select, input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px; background: var(--card); }
input[type=search] { min-width: 220px; }
.btn { padding: 7px 14px; background: var(--blue); color: #fff; border-radius: 7px;
  text-decoration: none; font-size: 13px; }
.btn:hover { opacity: .9; }

.legend { display: flex; gap: 14px; margin-bottom: 10px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

table { width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  box-shadow: 0 6px 20px rgba(140,120,190,.12); }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; color: var(--muted); background: rgba(250,248,253,.7); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { border-left: 4px solid transparent; }
.t-Exchange { border-left-color: var(--green); }
.t-Purchase { border-left-color: var(--blue); }
.t-DeliveryExpense { border-left-color: var(--orange); }
.t-Transfer { border-left-color: var(--purple); }
.t-Expense { border-left-color: var(--red); }
.t-Deposit, .t-Checkpoint, .t-CostEntry { border-left-color: var(--gray); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; color: #fff; white-space: nowrap; }
.tag.Exchange { background: var(--green); } .tag.Purchase { background: var(--blue); }
.tag.DeliveryExpense { background: var(--orange); } .tag.Transfer { background: var(--purple); }
.tag.Expense { background: var(--red); }
.tag.Deposit, .tag.Checkpoint, .tag.CostEntry { background: var(--gray); }
.muted { color: var(--muted); font-size: 12px; margin-top: 10px; }

.btn.ghost { background: #fff; color: var(--blue); border: 1px solid var(--blue); }
.btn.sanya { background: #8e24aa; }
.badge { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.editor textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; resize: vertical; }
.act-изменено td { background: #fff8e1; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; color: var(--muted); }
#orders-table td[contenteditable] { min-width: 60px; }
#orders-table td[contenteditable]:focus { outline: 2px solid var(--blue); border-radius: 4px; }
.prod-icon { width: 30px; height: 30px; border-radius: 7px; background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; }
button.btn { cursor: pointer; border: none; }
.link { background: none; border: none; color: var(--blue); cursor: pointer; font-size: 12px; padding: 0; }
.row-daily td { background: #eef1f4; font-weight: 600; color: var(--gray); }
.icon-btn { background: none; border: none; cursor: pointer; opacity: .5; font-size: 14px; }
.icon-btn:hover { opacity: 1; }

.overlay { position: fixed; inset: 0; background: rgba(20,28,40,.45);
  display: flex; align-items: flex-start; justify-content: center; padding-top: 6vh; z-index: 50; }
.overlay.hidden { display: none; }
.editor { background: #fff; border-radius: 12px; padding: 22px; width: 460px;
  max-height: 86vh; overflow: auto; box-shadow: 0 18px 50px rgba(0,0,0,.3); }
.editor h3 { margin: 0 0 14px; }
.editor label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.editor label input, .editor label select, .editor select { width: 100%; margin-top: 4px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; }
.field-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.field-row input { flex: 1; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; }
.field-row .k { max-width: 160px; }
.field-row .del { color: var(--red); }
.editor-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.hint { color: var(--orange); font-size: 12px; min-height: 16px; }
.hist { background: #f5f6f8; border-radius: 8px; padding: 10px; font-size: 11px; max-height: 200px; overflow: auto; }
.hidden { display: none; }

.num.pos { color: #2E7D32; }
.num.neg { color: #C62828; }

.ord-no{font-weight:700;color:#555;text-align:center;font-size:13px}

/* ───────── Адаптив: планшет и телефон ───────── */
@media (max-width: 900px) {
  .panel { padding: 12px 10px; overflow-x: auto; }
  table { font-size: 13px; }
  .toolbar { flex-wrap: wrap; gap: 8px; }
  input[type=search] { min-width: 140px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; }
}
/* Компактная шапка вместо баннера на узких экранах */
@media (max-width: 760px) {
  header {
    position: static; aspect-ratio: auto; height: auto; overflow: visible;
    display: flex; flex-direction: column; gap: 8px; padding: 10px 12px;
    background: linear-gradient(135deg, #fdeef7 0%, #eaf5ff 50%, #f3ecff 100%);
  }
  .head-gif, .logo-shine { display: none; }
  /* короткая гифка (как в боте) баннером сверху на телефоне */
  .head-gif-m { display: block; width: 100%; height: 180px; object-fit: cover;
    object-position: center 28%; border-radius: 10px;
    box-shadow: 0 3px 12px rgba(120,110,170,.25); }
  .brand { position: static; width: auto; height: 34px; animation: none; }
  .brand img { width: auto; height: 34px; object-position: left center; }
  .brand::after { display: none; }
  .balances {
    position: static; width: 100%; height: auto; display: flex; gap: 6px;
  }
  .bal {
    flex: 1; background: #1b1030; border-radius: 8px; padding: 6px 4px;
  }
  .bal .label { font-size: 8px; }
  .bal .val { font-size: 14px; }
  .me-picker { right: 8px; bottom: 8px; }
  .head-gif { display: none; }
  /* таблицы прокручиваются по горизонтали внутри своей вкладки */
  #events, #orders-table, #catalog-table, #activity-table { min-width: 640px; }
  #profit-table { min-width: 880px; }
  /* «Закупка+прибыль»: липкие первые 2 колонки (эмодзи+товар) при скролле */
  #profit-table th:nth-child(2), #profit-table td:nth-child(2) {
    position: sticky; left: 0; background: #fff; z-index: 1;
    box-shadow: 2px 0 4px rgba(0,0,0,.05); max-width: 120px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #profit-table tr.profit-batch td:nth-child(2) { background: #f7f3fb; }
  /* поля ввода продажи/даты — крупнее под палец */
  #profit-table .sale-cell { min-width: 60px; padding: 8px 6px; }
  #profit-table .sale-date { padding: 6px 4px; font-size: 13px; }
  #profit-table .deliv-src { max-width: 100px; }
}
@media (max-width: 420px) {
  .tab { padding: 8px 10px; font-size: 13px; }
  .bal .val { font-size: 12px; }
  table { font-size: 12px; }
}

/* подсветка строки с возможной ошибкой данных (проверка целостности) */
#events tr.row-flag td { background: #ffe0e0 !important; }
#events tr.row-flag td:first-child { box-shadow: inset 3px 0 0 #c62828; }

.restore-btn{border:1px solid #2e7d32;background:#e8f5e9;color:#2e7d32;border-radius:7px;padding:2px 8px;font-size:12px;cursor:pointer;margin-left:8px}
.restore-btn:hover{background:#2e7d32;color:#fff}
body.demo .restore-btn{display:none}
