:root {
  --ink: #0d1830;
  --ink-2: #16244a;
  --ink-text: #b9c3dc;
  --primary: #2350e6;
  --primary-600: #1b3fc0;
  --primary-50: #edf1fe;
  --primary-100: #d9e2fd;
  --bg: #f3f5f9;
  --card: #ffffff;
  --line: #e3e7ef;
  --line-2: #eef1f6;
  --text: #111827;
  --muted: #5b6476;
  --faint: #8b93a5;
  --pos: #0e7c66;
  --pos-50: #e6f4f0;
  --neg: #c8373d;
  --neg-50: #fcecec;
  --warn: #b7791f;
  --warn-50: #fdf4e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--ink); color: var(--ink-text); padding: 18px 12px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand svg { flex: none; }
.nav-group { font-size: 11.5px; color: #7c89a8; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-text); text-decoration: none; font-size: 14px;
}
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.on { background: var(--primary); color: #fff; }
.nav a .badge { margin-left: auto; background: #2c3b66; color: #fff; border-radius: 999px; font-size: 11.5px; padding: 1px 7px; }
.nav a.on .badge { background: rgba(255,255,255,.22); }
.nav svg { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--ink-2); font-size: 12.5px; }
.side-foot .who { color: #fff; }
.side-foot button { background: none; border: 0; color: var(--ink-text); padding: 0; cursor: pointer; text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 14px 28px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.top h1 { font-size: 19px; margin: 0 auto 0 0; font-weight: 650; letter-spacing: -.01em; }
.content { padding: 22px 28px 60px; }
.sub { color: var(--muted); font-size: 13px; }

/* ---------- элементы ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { border-color: #c9d0de; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.ghost { border-color: transparent; background: none; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.danger { color: var(--neg); }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; padding: 7px 11px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary-50); color: var(--primary-600); font-weight: 600; }
input.inp, select.inp, textarea.inp {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; min-width: 0;
}
input.inp:focus, select.inp:focus, textarea.inp:focus { outline: 2px solid var(--primary-100); border-color: var(--primary); }
input.cell { width: 96px; text-align: right; border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px; }
input.cell.dirty { border-color: var(--warn); background: var(--warn-50); }
label.fld { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.fld .inp { color: var(--text); font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mt { margin-top: 18px; }
.mt-s { margin-top: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; }
.card > .hd h2 { font-size: 15px; margin: 0; font-weight: 650; }
.card > .bd { padding: 14px 16px 16px; }
.card.pad { padding: 16px; }

.kpi { padding: 14px 16px; }
.kpi .lbl { color: var(--muted); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.kpi .val { font-size: 24px; font-weight: 650; margin-top: 6px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .note { font-size: 12.5px; color: var(--faint); margin-top: 4px; }
.chg { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chg.up { color: var(--pos); }
.chg.down { color: var(--neg); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

.pill { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ozon { background: #e8efff; color: #1d4ed8; }
.pill.wb { background: #f6e9f7; color: #8b1f8f; }
.pill.red { background: var(--neg-50); color: var(--neg); }
.pill.amber { background: var(--warn-50); color: var(--warn); }
.pill.green { background: var(--pos-50); color: var(--pos); }
.pill.gray { background: var(--line-2); color: var(--muted); }

/* ---------- таблицы ---------- */
.tbl-wrap { overflow: auto; border-top: 1px solid var(--line); }
.card > .tbl-wrap { border-radius: 0 0 var(--radius) var(--radius); }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 9px 10px;
  background: #f8f9fc; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
table.t th.sort { cursor: pointer; user-select: none; }
table.t th.sort:hover { color: var(--text); }
table.t th .arr { font-size: 10px; margin-left: 3px; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f8faff; }
table.t tr.total td { font-weight: 650; background: #f8f9fc; }
table.t td.c-red { background: var(--neg-50); }
table.t td.c-amber { background: var(--warn-50); }
table.t td.c-green { background: var(--pos-50); }
.prod { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 420px; }
.prod img, .prod .ph { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; flex: none; background: var(--line-2); }
.prod .nm { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.prod .art { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 16px; }
.tabs button { border: 0; background: none; padding: 11px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.tabs .cnt { color: var(--faint); margin-left: 4px; font-variant-numeric: tabular-nums; }

.pager { display: flex; align-items: center; gap: 8px; padding: 10px 16px; color: var(--muted); font-size: 13px; }

/* ---------- подсказки ---------- */
.tip { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); align-items: start; }
.tip:last-child { border-bottom: 0; }
.tip .kind { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 6px; margin-top: 1px; white-space: nowrap; }
.tip .kind.action { background: var(--neg-50); color: var(--neg); }
.tip .kind.observation { background: var(--warn-50); color: var(--warn); }
.tip .kind.opportunity { background: var(--pos-50); color: var(--pos); }
.tip .ttl { font-weight: 550; }
.tip .act { color: var(--muted); font-size: 13px; margin-top: 3px; }
.tip.done { opacity: .55; }
.tip.done .ttl { text-decoration: line-through; }

/* ---------- график ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; }
.chart .tt {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12.5px; border-radius: 8px;
  padding: 8px 10px; white-space: nowrap; transform: translate(-50%, -100%); display: none; z-index: 5;
}
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr 110px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bar-row .bar { height: 8px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.bar-row .bar > div { height: 100%; border-radius: 4px; }

/* ---------- выпадашки, панели ---------- */
.dd { position: relative; }
.dd-menu {
  position: absolute; top: calc(100% + 6px); right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16,24,40,.12); padding: 8px; min-width: 240px; z-index: 40; display: none;
}
.dd.open .dd-menu { display: block; }
.dd-menu label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.dd-menu label:hover { background: var(--bg); }

.overlay { position: fixed; inset: 0; background: rgba(13, 24, 48, .35); z-index: 50; display: flex; justify-content: flex-end; }
.drawer { width: min(860px, 96vw); height: 100%; background: var(--bg); overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
.drawer .dh { position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--line); padding: 14px 20px; display: flex; gap: 12px; align-items: center; z-index: 2; }
.drawer .db { padding: 18px 20px 40px; }
.modal-wrap { position: fixed; inset: 0; background: rgba(13, 24, 48, .35); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: min(720px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal .mh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .mh h3 { margin: 0; font-size: 16px; }
.modal .mb { padding: 18px 20px; }
.modal .mf { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.notice { border: 1px solid var(--line); background: #fff; border-left: 3px solid var(--primary); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--muted); }
.notice.warn { border-left-color: var(--warn); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; font-size: 13.5px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--primary-100); border-top-color: var(--primary); border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); margin-right: 6px; }
.dot.ok { background: var(--pos); } .dot.err { background: var(--neg); } .dot.run { background: var(--warn); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 20px; }
.login form { background: #fff; border-radius: 14px; padding: 30px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login .brand { color: var(--ink); padding: 0 0 6px; }
.login .err { color: var(--neg); font-size: 13px; min-height: 18px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.check-list { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 4px 16px; }
.check-list label { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .side .nav-group, .side-foot { display: none; }
  .brand { padding: 4px 10px; width: 100%; }
  .g2 { grid-template-columns: 1fr; }
  .top, .content { padding-left: 14px; padding-right: 14px; }
}
