/* «Недостачи на складе» — стиль Пульса: холодная нейтральная палитра, поверхности без рамок. */
:root {
  --bg: #f4f5f9; --surface: #ffffff; --surface-2: #f7f8fb; --text: #111318; --muted: #6b7385; --faint: #9aa1b4;
  --accent: #3b82f6; --accent-soft: rgba(59,130,246,.12); --pos: #16a34a; --neg: #dc2626; --warn: #d97706;
  --violet: #8b5cf6; --grid: #eceef4; --row-hover: #f3f5fa;
  --shadow: 0 1px 2px rgba(17,19,24,.04), 0 8px 24px -12px rgba(17,19,24,.12);
  --shadow-up: 0 1px 2px rgba(17,19,24,.06), 0 14px 32px -14px rgba(17,19,24,.2);
  --seg-active: #ffffff;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0a0b0f; --surface: #12141a; --surface-2: #181b23; --text: #f1f2f6; --muted: #8a91a5; --faint: #5f667a;
  --accent: #5b9dff; --accent-soft: rgba(91,157,255,.14); --pos: #34c759; --neg: #ff453a; --warn: #ffb340;
  --violet: #a78bfa; --grid: #1c1f28; --row-hover: #191c25;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 12px 32px -16px rgba(0,0,0,.6);
  --shadow-up: 0 1px 0 rgba(255,255,255,.05) inset, 0 16px 36px -14px rgba(0,0,0,.75);
  --seg-active: #232733;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { overflow-anchor: none; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* шапка */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); }
.top-in { max-width: 1320px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 38px; height: 38px; flex: none; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.02em; white-space: nowrap; }
.brand .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 0; border-radius: 10px;
  background: var(--surface); color: var(--text); font: 500 13px/1 inherit; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, background .12s; white-space: nowrap; }
.btn:hover { box-shadow: var(--shadow-up); transform: translateY(-1px); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 1320px; margin: 0 auto; padding: 6px 20px 60px; }

/* вкладки: недостачи / излишки / брак */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 14px; }
.tab { --c: var(--neg); display: inline-flex; align-items: center; gap: 9px; height: 40px; padding: 0 16px 0 13px; border: 0;
  border-radius: 999px; background: transparent; color: var(--muted); font: 600 14px/1 inherit; cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s; }
.tab .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab:hover:not([aria-selected="true"]) { color: var(--text); background: color-mix(in srgb, var(--surface) 55%, transparent); }
.tab .cnt { font-weight: 500; color: var(--faint); font-size: 12.5px; }
.tab[data-tab="surplus"] { --c: var(--warn); }
.tab[data-tab="defect"] { --c: var(--violet); }

/* панель фильтров */
.bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.seg { position: relative; display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface-2);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 6%, transparent); }
.seg button { position: relative; z-index: 1; height: 30px; padding: 0 12px; border: 0; border-radius: 9px; background: none;
  color: var(--muted); font: 500 13px/1 inherit; cursor: pointer; white-space: nowrap; transition: color .18s; }
.seg button[aria-pressed="true"] { color: var(--text); }
.seg .ind { position: absolute; z-index: 0; top: 3px; height: 30px; border-radius: 9px; background: var(--seg-active);
  box-shadow: 0 1px 2px rgba(0,0,0,.12); transition: transform .22s cubic-bezier(.2,.8,.2,1), width .22s cubic-bezier(.2,.8,.2,1); }
@media (prefers-reduced-motion: reduce) { .seg .ind { transition: none; } }
.search { position: relative; flex: 1 1 220px; max-width: 340px; }
.search input { width: 100%; height: 36px; padding: 0 34px 0 34px; border: 0; border-radius: 10px; background: var(--surface);
  color: var(--text); font: 14px inherit; box-shadow: var(--shadow); outline: none; }
.search input:focus { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.search .lens { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; stroke: var(--faint); fill: none; stroke-width: 1.8; }
.search .clear { position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; border: 0; border-radius: 7px; background: var(--surface-2);
  color: var(--muted); cursor: pointer; display: none; font-size: 15px; line-height: 24px; }
.search.has .clear { display: block; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 26px; font-weight: 620; letter-spacing: -0.02em; margin-top: 4px; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 3px; min-height: 17px; }
.kpi.main .v { color: var(--c, var(--neg)); }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.card-h { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-h h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card-h .hint { margin-left: auto; font-size: 12px; color: var(--faint); }

/* таблица */
.tbl-wrap { max-height: calc(100vh - 150px); overflow: auto; margin: 0 -16px; border-radius: 0 0 16px 16px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); color: var(--muted); font-weight: 500; font-size: 12px;
  text-align: right; padding: 8px 10px; white-space: nowrap; box-shadow: inset 0 -1px 0 var(--grid); }
thead th:first-child, tbody td:first-child { text-align: left; padding-left: 16px; }
thead th:last-child, tbody td:last-child { padding-right: 16px; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sorted { color: var(--text); }
tbody td { padding: 9px 10px; text-align: right; vertical-align: top; }
tbody tr.row { cursor: pointer; transition: background .12s; }
tbody tr.row:hover td { background: var(--row-hover); }
tbody tr.row.open td { background: var(--row-hover); }
.prod { display: flex; flex-direction: column; gap: 2px; min-width: 220px; max-width: 460px; }
.prod .code { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.prod .name { color: var(--text); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.links { display: inline-flex; gap: 8px; margin-left: 6px; font-size: 12px; }
.links a { display: inline-flex; align-items: center; gap: 3px; }
.links svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; }
.co { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.co.c2 { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.co.c1 { background: color-mix(in srgb, var(--violet) 13%, transparent); color: var(--violet); }
.money { font-weight: 600; }
.zero { color: var(--faint); }
.age { font-size: 11.5px; color: var(--warn); }
.bar-in { height: 4px; border-radius: 4px; background: var(--grid); margin-top: 5px; overflow: hidden; }
.bar-in i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--c, var(--neg)), color-mix(in srgb, var(--c, var(--neg)) 55%, white)); }
.more { display: flex; justify-content: center; padding: 12px 0 2px; }
.empty { padding: 40px 10px; text-align: center; color: var(--muted); }

/* раскрытая строка */
tr.detail > td { padding: 0 16px 14px; background: var(--row-hover); text-align: left; cursor: default; }
.det { background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.det h3 { margin: 2px 0 8px; font-size: 13px; font-weight: 600; }
.det table { font-size: 12.5px; }
.det table td, .det table th { padding: 5px 8px; text-align: left; box-shadow: none; position: static; background: none; vertical-align: top; }
.det table th { color: var(--muted); font-weight: 500; font-size: 11.5px; }
.det tbody tr:hover td { background: none; }
.det table td.num, .det table th.num { text-align: right; }
.det .note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11.5px; font-weight: 600; }
.pill.buffer { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); }
.pill.virtual { background: color-mix(in srgb, var(--neg) 12%, transparent); color: var(--neg); }
.pill.defect { background: color-mix(in srgb, var(--violet) 14%, transparent); color: var(--violet); }
.plus { color: var(--pos); } .minus { color: var(--neg); }

/* справа: кто проводил */
.users { display: flex; flex-direction: column; gap: 10px; }
.user .n { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.user .n span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.callout { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: 12.5px; color: var(--muted); }
.callout b { color: var(--text); font-weight: 600; }
.status-bad { color: var(--neg); }

.fade { animation: fade .25s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.loading { opacity: .6; transition: opacity .15s; }

@media (max-width: 1000px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .top-in, main { padding-left: 14px; padding-right: 14px; }
  .brand .sub, .btn .t { display: none; }
  .top-in { gap: 8px; }
  .brand { gap: 9px; }
  .brand img { width: 32px; height: 32px; }
  .brand h1 { font-size: 14.5px; white-space: normal; line-height: 1.15; }
  .kpi .v { font-size: 21px; }
  .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .search { max-width: none; flex-basis: 100%; }
  .tbl-wrap { max-height: none; }
  .prod { min-width: 170px; }
}
