/* Оформление в духе Айтиды: окна с синими заголовками, панели инструментов, таблицы-сетки */
:root {
  --bg: #dfe8f6;          /* рабочий стол за окнами */
  --panel: #f0f0f0;       /* фон окна и панелей */
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --line: #d0d0d0;        /* линии сетки */
  --frame: #99bbe8;       /* рамки окон */
  --title: #15428b;       /* текст заголовков */
  --title-bg: linear-gradient(#e4ecf7, #c6d6ee);
  --head-bg: linear-gradient(#fbfbfb, #e6e6e6);
  --pick: #d9ecd9;        /* выделенная строка — светло-зелёная, как в Айтиде */
  --hover: #eef5ee;
  --link: #0645ad;
  --accent: #8b1e1e;
  --accent-soft: #f6e7e5;
  --ok: #1f7a46;
  --ok-soft: #e5f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --bar: #9db6dc;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 Tahoma, "Segoe UI", Verdana, Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--link); }
h1 { font-size: 14px; margin: 0; font-weight: 700; color: var(--title); }
h1 small, h3 small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--title); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: #eef2f8; padding: 0 4px; border: 1px solid #d6e0ee; font-size: 12px; }

/* ---- окно программы ---- */
.appbar {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  background: linear-gradient(#3f6eb4, #1e4f96); color: #fff; font-size: 13px;
}
.appbar-sub { opacity: .85; }
.logo {
  width: 20px; height: 20px; border-radius: 4px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; border: 1px solid #fff6;
}
.appbar .logout { margin-left: auto; color: #fff; }
.demo-tag {
  margin-left: auto; padding: 1px 8px; border-radius: 3px; background: #ffd34d; color: #3a2c00;
  font-weight: 700; font-size: 12px; cursor: help;
}
.demo-tag + .logout { margin-left: 8px; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 3px 6px;
  background: linear-gradient(#f7f7f7, #e3e3e3); border-bottom: 1px solid #b8b8b8;
}
.toolbar:empty { display: none; }
.toolbar .sep { width: 1px; align-self: stretch; margin: 2px 4px; background: #b8b8b8; box-shadow: 1px 0 #fff; }
.main-tools a {
  display: flex; align-items: center; gap: 5px; padding: 3px 8px; color: var(--text); text-decoration: none;
  border: 1px solid transparent; border-radius: 2px;
}
.main-tools a i { font-style: normal; font-size: 16px; }
.main-tools a:hover { border-color: #a9bfd6; background: linear-gradient(#fdfeff, #dbe8f5); }

.desk { flex: 1; display: grid; grid-template-columns: 230px 1fr; gap: 6px; padding: 6px; min-height: 0; }

/* навигатор слева */
.tree { background: var(--card); border: 1px solid var(--frame); align-self: start; position: sticky; top: 6px; }
.tree > summary {
  background: var(--title-bg); color: var(--title); font-weight: 700; padding: 4px 8px;
  border-bottom: 1px solid var(--frame); cursor: pointer; list-style: none;
}
.tree > summary::-webkit-details-marker { display: none; }
.tree nav { padding: 4px 0 8px; display: flex; flex-direction: column; }
.tree .folder { padding: 5px 8px 1px; font-weight: 700; display: flex; gap: 5px; }
.tree nav a {
  color: var(--text); text-decoration: none; padding: 2px 8px 2px 26px; display: flex; gap: 5px; align-items: center;
  border: 1px dotted transparent;
}
.tree nav a span { width: 18px; text-align: center; }
.tree nav a:hover { background: var(--hover); }
.tree nav a.active { background: var(--pick); border-color: #7fae7f; }

/* окно документа */
.window { background: var(--panel); border: 1px solid var(--frame); min-width: 0; display: flex; flex-direction: column; }
.win-title {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--title-bg); border-bottom: 1px solid var(--frame); padding: 4px 6px 4px 10px;
}
.win-close {
  width: 22px; height: 18px; display: grid; place-items: center; text-decoration: none; color: #fff; font-size: 12px;
  background: linear-gradient(#e08a7a, #c0392b); border: 1px solid #8e2a1f; border-radius: 3px;
}
.win-close:hover { filter: brightness(1.1); }
.win-tools { gap: 4px; }
.win-body { padding: 8px; flex: 1; }

.statusbar {
  display: flex; gap: 0; background: linear-gradient(#f3f3f3, #dedede); border-top: 1px solid #b8b8b8;
  font-size: 12px; color: #333;
}
.statusbar span { padding: 2px 10px; border-right: 1px solid #b8b8b8; }
.statusbar span:last-child { margin-left: auto; border-right: 0; border-left: 1px solid #b8b8b8; }

/* ---- панели (группы полей) ---- */
.card {
  background: var(--card); border: 1px solid #b5c7e0; padding: 8px 10px; margin-bottom: 8px; min-width: 0;
}
.card > h3:first-child, .card > .card-head:first-child {
  margin: -8px -10px 8px; padding: 4px 10px; background: linear-gradient(#f3f6fb, #e1e9f5);
  border-bottom: 1px solid #c8d6ea;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: start; }
.grid2.wide-left { grid-template-columns: 2fr 1fr; }
.grid2 > * { margin-bottom: 0; }
.grid2 + * { margin-top: 8px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.kpi { background: var(--card); border: 1px solid #b5c7e0; padding: 6px 10px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi b { display: block; font-size: 20px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; color: var(--title); }
.kpi small { color: var(--muted); }
.kpi.warn b { color: var(--warn); }
.sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 6px; margin-bottom: 8px; }
.sections .kpi { color: inherit; text-decoration: none; }
.sections .kpi:hover { background: var(--hover); border-color: #7fae7f; }
.sections .kpi b { font-size: 17px; }
.badge { background: var(--bad); color: #fff; border-radius: 8px; padding: 0 5px; font-size: 11px; margin-left: 4px; }
.status { display: inline-block; padding: 0 6px; border: 1px solid var(--line); font-size: 12px; background: #f7f7f7; white-space: nowrap; }
.status.s-new { background: #fff3c4; border-color: #e0c060; font-weight: 700; }
.status.s-accepted, .status.s-ready { background: var(--warn-soft); color: var(--warn); }
.status.s-canceled { color: var(--muted); text-decoration: line-through; }
tr.clickable { cursor: pointer; }
.add-purchase > summary { cursor: pointer; list-style: none; }
.add-purchase > summary::-webkit-details-marker { display: none; }
.add-purchase[open] > summary { margin-bottom: 8px; }
label.block { display: block; margin: 6px 0 8px; }
label.block textarea { display: block; width: 100%; margin-top: 3px; font: inherit; padding: 4px 6px;
  border: 1px solid #a5acb5; background: #fff; color: var(--text); }
tr.group { scroll-margin-top: 16px; }

/* ---- сообщения ---- */
.flashes { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.flash { padding: 5px 10px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: #9fd0b0; }
.flash.error { background: var(--bad-soft); color: var(--bad); border-color: #e3a49d; }
.note { background: #fffbe0; color: #5c4a00; border: 1px solid #e6d27a; padding: 5px 10px; margin: 0 0 8px; }
.empty { color: var(--muted); padding: 6px 0; margin: 0; }

/* ---- период ---- */
.period {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 8px;
  padding: 4px 6px; background: var(--card); border: 1px solid #b5c7e0;
}
.chips { display: flex; flex-wrap: wrap; gap: 2px; }
.chip {
  padding: 2px 9px; background: linear-gradient(#fff, #e6e6e6); border: 1px solid #adadad; border-radius: 2px;
  color: var(--text); text-decoration: none; font-size: 12px;
}
.chip:hover { background: linear-gradient(#fdfeff, #dbe8f5); border-color: #7da2ce; }
.chip.on { background: linear-gradient(#cfe0f5, #b4cdee); border-color: #6c93c7; box-shadow: inset 0 1px 2px #0002; font-weight: 700; }
.range { display: flex; align-items: center; gap: 4px; }
.chips-sep { width: 1px; align-self: stretch; margin: 0 4px; background: #b8b8b8; }
.chip.month { font-weight: 700; color: var(--title); }
.chip.month.on { color: var(--text); }

#costs-table form.inline { display: flex; gap: 2px; align-items: center; }
#costs-table .btn { min-height: 22px; padding: 0 8px; }

/* ---- продажи по дням ---- */
table.heat td[style] { background: linear-gradient(rgba(79, 127, 192, calc(var(--h) * 0.0045)), rgba(79, 127, 192, calc(var(--h) * 0.0045))) !important; }
table.heat td.best { box-shadow: inset 0 0 0 2px var(--ok); font-weight: 700; }
table.heat td.worst { color: var(--muted); }
.daily-scroll { overflow-x: auto; }
table.daily td:first-child, table.daily th:first-child { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 180px; }
table.daily thead th:first-child { background: var(--head-bg); }
table.daily td.num, table.daily th.num { min-width: 52px; }

/* ---- сравнение месяцев ---- */
.cmp-pick { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.up { color: var(--ok); }
.down { color: var(--bad); }
td.up, td.down { font-weight: 700; }
tr.new td:first-child::after { content: " новый"; font-size: 10px; color: var(--ok); border: 1px solid #9fd0b0; padding: 0 3px; margin-left: 4px; }
tr.gone td { color: var(--muted); }
.dyn td.num { min-width: 82px; }
.dyn .bar { display: block; height: 4px; background: var(--bar); margin-top: 2px; }
.dyn tr.total td { font-weight: 700; border-top: 2px solid #555; }
.movers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 760px) { .movers { grid-template-columns: 1fr; } }

/* ---- поля и кнопки ---- */
input, select, button, textarea { font: inherit; color: inherit; }
input, select {
  background: #fff; border: 1px solid #a5acb5; border-radius: 0; padding: 2px 5px; min-width: 0; height: 22px;
}
input[type=checkbox], input[type=radio] { height: auto; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: #3d7bc8; box-shadow: 0 0 0 1px #3d7bc855; background: #fffde8; }
input[readonly] { background: #f3f3f3; }
label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: #333; }
label input, label select { color: var(--text); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 6px; }
.row:last-child { margin-bottom: 0; }
.grow { flex: 1 1 220px; }
input.short { width: 110px; }
input.num { text-align: right; }
.day { margin-bottom: 6px; max-width: 180px; }
.btn, button.btn {
  background: linear-gradient(#ffffff, #e1e1e1); color: var(--text); border: 1px solid #adadad; border-radius: 3px;
  padding: 2px 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap; min-height: 24px; font-weight: 400;
}
.btn:hover { background: linear-gradient(#fdfeff, #d6e6f7); border-color: #6c93c7; }
.btn:active { background: linear-gradient(#cfe0f5, #b4cdee); }
.btn.primary { font-weight: 700; border-color: #3d6fb0; }
.btn.ghost { background: linear-gradient(#ffffff, #ececec); }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; border-radius: 2px;
  width: 22px; height: 20px; padding: 0;
}
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); border-color: #e3a49d; }
form.inline { display: inline; margin: 0; }
.file { position: relative; flex: 1 1 240px; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; height: auto; }
.file span {
  display: block; border: 1px solid #a5acb5; background: #fff; padding: 2px 8px; height: 24px;
  color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file span::before { content: "📂 "; }
.file.has span { border-color: #3d7bc8; }
.filter { width: 100%; max-width: 300px; margin-bottom: 6px; }
.card-head .filter { margin: 0; }

/* ---- таблицы-сетки ---- */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; background: #fff; }
th, td { padding: 2px 6px; border: 1px solid #e2e2e2; text-align: left; vertical-align: middle; }
thead th, tfoot td, tfoot th {
  background: var(--head-bg); border-color: var(--line); font-weight: 400; color: #222; white-space: nowrap;
}
thead th { border-bottom-color: #a8a8a8; }
tbody tr:nth-child(even) td { background: #fafafa; }
tbody tr:hover td { background: var(--hover); }
tbody tr.picked td { background: var(--pick); }
.num { text-align: right; white-space: nowrap; }
.neg { color: var(--bad); font-weight: 700; }
.nowrap { white-space: nowrap; }
tr.group th { background: #eef2f8; color: var(--title); font-weight: 700; padding-top: 4px; }
tr.group th.num { text-align: right; }
tr.bad td { background: var(--bad-soft); }
.sortable thead th { cursor: pointer; user-select: none; }
.sortable thead th:hover { background: linear-gradient(#fdfeff, #dbe8f5); }
.sortable th.asc::after { content: " ▲"; font-size: 9px; }
.sortable th.desc::after { content: " ▼"; font-size: 9px; }
table.entry td { padding: 0; }
table.entry input { width: 100%; border: 0; height: 22px; background: transparent; }
table.entry input:focus { box-shadow: inset 0 0 0 1px #3d7bc8; }
table.entry td:first-child { width: 50%; }
.summary td { padding: 4px 6px; }
.summary tr.total td { border-top: 2px solid #555; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.green { background: var(--ok); } .dot.yellow { background: #d9a400; } .dot.red { background: var(--bad); }
.sticky-save { position: sticky; bottom: 0; background: var(--panel); padding: 6px 0 0; text-align: right; }
.tabs { margin-bottom: 8px; }

/* ---- приходная накладная (документ) ---- */
.doc { display: flex; flex-direction: column; gap: 6px; }
.doc-links { display: flex; gap: 14px; padding: 0 2px; }
.doc-links a { font-weight: 700; }
.doc-head {
  display: grid; grid-template-columns: auto 1fr auto 140px auto 150px; gap: 5px 8px; align-items: center;
  background: var(--panel); border: 1px solid #c4c4c4; padding: 6px 8px;
}
.doc-head > span { text-align: right; color: #333; white-space: nowrap; }
.doc-head .wide { grid-column: 4 / -1; }
.doc-head input, .doc-head select { width: 100%; }
.doc-sum {
  display: flex; flex-wrap: wrap; gap: 6px 24px; align-items: center; background: var(--panel);
  border: 1px solid #c4c4c4; padding: 5px 8px;
}
.doc-sum output { display: inline-block; min-width: 120px; text-align: right; background: #f7f7f7; border: 1px solid #c4c4c4; padding: 1px 6px; font-weight: 700; }
.doc-grid { border: 1px solid #8a8a8a; background: #fff; overflow: auto; min-height: 260px; max-height: 60vh; }
.doc-grid table { border: 0; }
.doc-grid thead th { position: sticky; top: 0; z-index: 1; }
.doc-grid table.entry td.n, .doc-grid td.n { width: 52px; text-align: center; color: #555; background: var(--head-bg) !important; cursor: default; }
.doc-grid tr.cur td.n::before { content: "▶ "; font-size: 9px; }
.doc-grid tr.cur td { background: var(--pick); }
.doc-grid td.code { width: 80px; }
.doc-grid td.unit { width: 50px; text-align: center; color: #444; }
.doc-grid td.qty, .doc-grid td.price { width: 100px; }
.doc-grid td.sumc { width: 110px; }
.doc-grid td.stock { width: 90px; color: #555; }
.doc-grid td.del { width: 26px; text-align: center; }
.doc-grid tr.bad td { background: #fdecea; }
.doc-grid tr.other td { background: #fff6d6; }
.doc-grid .hint { color: var(--muted); }
.doc-picker { background: #fff; border: 1px solid #c4c4c4; padding: 4px 8px; }
.doc-picker > summary { cursor: pointer; color: var(--link); }
.doc-picker .show-all { display: inline-flex; flex-direction: row; gap: 4px; margin-left: 12px; font-weight: 400; }
.goods-group { margin: 6px 0; display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.goods-group > b { width: 100%; font-size: 12px; color: var(--title); }
.goods-group .chip { cursor: pointer; background: linear-gradient(#fff, #eee); }
.goods-group .chip small { color: var(--accent); }
.doc-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.doc-foot .keys { color: var(--muted); font-size: 12px; }
.doc-foot .btns { display: flex; gap: 6px; margin-left: auto; }
.doc-foot .btn { min-width: 110px; justify-content: center; }
.stamp { display: inline-block; border: 1px solid #7fae7f; background: var(--pick); padding: 0 6px; font-size: 12px; }

/* фото товаров в справочнике */
.photo-cell { width: 54px; }
.photo-form { display: flex; align-items: center; gap: 2px; margin: 0; }
.photo-pick { display: grid; place-items: center; width: 40px; height: 40px; overflow: hidden;
  border: 1px dashed #a5acb5; cursor: pointer; background: #fafafa; font-size: 16px; }
.photo-pick img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick:hover { border-color: #3d7bc8; }
.photo-del { font-size: 11px; opacity: .5; }
.photo-del:hover { opacity: 1; }

/* ---- график ---- */
.bars {
  display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 3px; align-items: end;
  height: 200px; padding-bottom: 20px; position: relative; border-bottom: 1px solid #999;
}
.bar { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; }
.bar .fill { background: var(--bar); min-height: 2px; display: flex; align-items: flex-end; border: 1px solid #7b98c6; border-bottom: 0; }
.bar .profit { background: #4f7fc0; width: 100%; }
.bar:hover .fill { filter: brightness(1.08); }
.bar span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars[style*="--n: 1"] .bar, .bars[style*="--n: 2"] .bar { max-width: 120px; }
.legend { color: var(--muted); font-size: 12px; margin-top: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; margin: 0 4px 0 10px; border: 1px solid #7b98c6; }
.sw.rev { background: var(--bar); margin-left: 0; } .sw.prof { background: #4f7fc0; }

.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 3px 0; border-bottom: 1px solid #e6e6e6; }
.log li.bad { color: var(--bad); }
.log time { color: var(--muted); margin-right: 8px; font-size: 12px; }
.steps li { margin-bottom: 6px; }
.path { margin: 10px 0; word-break: break-all; }

/* ---- вход ---- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; padding: 0; background: var(--panel); border: 1px solid var(--frame); }
.login .win-title { margin: 0; }
.login .login-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.login input { height: 26px; }

/* ---- телефон и узкий экран ---- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid2, .grid2.wide-left { grid-template-columns: 1fr; }
  .grid2 > * { margin-bottom: 8px; }
  .doc-head { grid-template-columns: auto 1fr; }
  .doc-head .wide { grid-column: 2; }
}
@media (max-width: 760px) {
  body { font-size: 14px; }
  .appbar-sub, .statusbar span:nth-child(2) { display: none; }
  .main-tools a { padding: 4px 6px; }
  .desk { grid-template-columns: 1fr; padding: 4px; }
  .tree { position: static; }
  .tree:not([open]) nav { display: none; }
  .tree nav { flex-direction: row; flex-wrap: wrap; gap: 2px; padding: 4px; }
  .tree .folder { width: 100%; padding-left: 4px; }
  .tree nav a { padding: 3px 6px; border: 1px solid #ccc; background: #fafafa; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .card, .win-body { overflow-x: auto; }
  input, select { height: 30px; font-size: 16px; }  /* на iPhone поле меньше 16px увеличивает страницу */
  .btn { min-height: 32px; }
  .doc-grid { max-height: none; }
  .doc-foot .btns { width: 100%; }
  .doc-foot .btn { flex: 1; min-width: 0; }
}
