/* ТЕК-9 Прибыль — стиль как у приёмки и смен ТЕК-9 */
:root {
  --accent: #e10600;          /* фирменный красный, меняется здесь */
  --accent-press: #b80500;
  --on-accent: #fff;
  --bg: #efedeb;
  --card: #ffffff;
  --card-2: #f7f6f4;
  --text: #1c1b1a;
  --muted: #6d6a66;
  --line: #e3e0dc;
  --head: #151414;
  --head-2: #2a2827;
  --head-text: #f4f2f0;
  --pos: #18794a;
  --neg: #d00500;
  --neg-bg: #fdecea;
  --pos-bg: #e7f4ec;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --input: #ffffff;
  --shadow: 0 1px 2px rgba(20, 18, 16, .06), 0 4px 14px rgba(20, 18, 16, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110; --card: #1d1c1b; --card-2: #252321; --text: #f1efed; --muted: #a29e99; --line: #34312e;
    --head: #0a0a0a; --head-2: #232120; --pos: #4cc77f; --neg: #ff5446; --neg-bg: #3a1714; --pos-bg: #12301f;
    --warn: #ffb547; --warn-bg: #3a2a0c; --input: #161514; --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121110; --card: #1d1c1b; --card-2: #252321; --text: #f1efed; --muted: #a29e99; --line: #34312e;
  --head: #0a0a0a; --head-2: #232120; --pos: #4cc77f; --neg: #ff5446; --neg-bg: #3a1714; --pos-bg: #12301f;
  --warn: #ffb547; --warn-bg: #3a2a0c; --input: #161514; --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }

/* ---------- Шапка ---------- */
.top { background: var(--head); color: var(--head-text); position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top); }
.top-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.logo { height: 34px; width: auto; display: block; }
.logo-text { font-weight: 800; font-size: 22px; letter-spacing: .5px; }
.logo-text b { color: var(--accent); }
.brand-sub { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px; color: #b9b4ae;
  border-left: 1px solid #3a3836; padding-left: 10px; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.who { font-size: 13px; color: #c9c4be; text-align: right; line-height: 1.2; margin-right: 4px; }
.who small { display: block; color: #8d8883; font-size: 11px; }
.icon-btn { background: transparent; border: 0; color: var(--head-text); width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--head-2); }
.tabs { max-width: 1180px; margin: 0 auto; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 0 max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; text-decoration: none; padding: 8px 14px; border-radius: 10px; background: var(--head-2);
  color: var(--head-text); font-weight: 600; font-size: 14px; }
.tabs a.active { background: var(--accent); color: var(--on-accent); }

/* ---------- Раскладка ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left)); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .section + .section { margin-top: 14px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 22px 2px 10px; }
h1 { font-size: 22px; margin: 4px 2px 14px; }
h2 { font-size: 17px; margin: 0 0 12px; }

/* ---------- Кнопки и поля ---------- */
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; background: var(--card-2); color: var(--text); min-height: 44px; text-decoration: none; }
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-press); filter: none; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--neg); border: 1px solid var(--line); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; }
label.f { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
label.f > span { display: block; margin-bottom: 5px; }
.inp, select.inp, textarea.inp { width: 100%; border: 1px solid var(--line); background: var(--input); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; font-size: 16px; color: var(--text); font-weight: 400; }
.inp:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea.inp { min-height: 80px; resize: vertical; }
.inp.money { text-align: right; font-variant-numeric: tabular-nums; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Вход ---------- */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .card { padding: 24px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 20px; }
.login form > * + * { margin-top: 12px; }
.err { color: var(--neg); font-size: 14px; min-height: 20px; }

/* ---------- Чипсы периода ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; cursor: pointer; min-height: 36px; }
.chip.on { background: var(--head); color: var(--head-text); border-color: var(--head); }
:root[data-theme="dark"] .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; } }
.range { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.range .inp { width: auto; flex: 1; min-width: 140px; }

/* ---------- Плитки сводки ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 14px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 24px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .s { font-size: 13px; color: var(--muted); margin-top: 2px; }
.kpi.main { grid-column: span 2; background: var(--head); color: var(--head-text); }
.kpi.main .l, .kpi.main .s { color: #b9b4ae; }
.kpi.main .v { font-size: 34px; }
.kpi.main .v.neg { color: #ff5446; }
.kpi.main .v.pos { color: #fff; }
.split { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.split > * { min-width: 0; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.chart .b { flex: 1; min-width: 3px; background: var(--accent); border-radius: 3px 3px 0 0; position: relative; }
.chart .b.n { background: var(--muted); opacity: .5; }
.chart-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.toplist { list-style: none; margin: 0; padding: 0; }
.toplist li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.toplist li:first-child { border-top: 0; }
.toplist .nm small { overflow: hidden; text-overflow: ellipsis; }
.toplist .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.toplist .nm small { display: block; font-weight: 400; color: var(--muted); }
.toplist .pr { font-weight: 800; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }
.stockline { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 8px; font-size: 14px; }
.stockline b { font-variant-numeric: tabular-nums; }

/* ---------- Фильтры и список ---------- */
.filters { display: grid; gap: 10px; grid-template-columns: 2fr 1fr 1fr; }
.filters .more { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters .more label { flex: 1; min-width: 140px; }
.list-head { display: flex; align-items: center; gap: 10px; margin: 16px 2px 10px; flex-wrap: wrap; }
.list-head .cnt { color: var(--muted); font-size: 14px; }
.totals { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.totals b { color: var(--text); }

.dev-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.dev-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card-2); white-space: nowrap; }
.dev-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dev-table tr:last-child td { border-bottom: 0; }
.dev-table tbody tr { cursor: pointer; }
.dev-table tbody tr:hover td { background: var(--card-2); }
.dev-table .r { text-align: right; }
.dev-table .nm { font-weight: 700; }
.dev-table .nm small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
tr.loss td { background: var(--neg-bg); }
tr.loss:hover td { background: var(--neg-bg) !important; filter: brightness(.98); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.repair { background: var(--warn-bg); color: var(--warn); }
.badge.sale { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.badge.sold { background: var(--pos-bg); color: var(--pos); }

.dev-cards { display: none; }
.dev-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; cursor: pointer; border-left: 4px solid transparent; }
.dev-card + .dev-card { margin-top: 10px; }
.dev-card.loss { border-left-color: var(--neg); }
.dev-card .t { display: flex; gap: 10px; align-items: flex-start; }
.dev-card .t .nm { flex: 1; font-weight: 700; min-width: 0; }
.dev-card .t .nm small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.dev-card .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; font-size: 13px; }
.dev-card .nums div span { display: block; color: var(--muted); font-size: 12px; }
.dev-card .nums b { font-size: 15px; font-variant-numeric: tabular-nums; }

/* ---------- Карточка устройства (окно) ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(10, 9, 8, .55); display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 24px 16px; overscroll-behavior: contain; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; border-radius: 18px; overflow: clip; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.sheet-head { background: var(--head); color: var(--head-text); display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px; position: sticky; top: 0; z-index: 2; }
.sheet-head h2 { margin: 0; flex: 1; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 16px; }
.sheet-body .card + .card { margin-top: 12px; }
.wide { grid-column: span 2; }
.statuses { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.statuses button { border: 1px solid var(--line); background: var(--input); border-radius: 10px; padding: 10px 6px; font-weight: 700; cursor: pointer; min-height: 44px; font-size: 14px; }
.statuses button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.cost-rows { display: flex; flex-direction: column; gap: 8px; }
.cost-row { display: grid; grid-template-columns: 1fr 130px 40px; gap: 8px; align-items: center; }
.cost-row .x { width: 40px; height: 44px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.cost-row .x:hover { color: var(--neg); background: var(--card-2); }
.cost-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.cost-foot .sum { margin-left: auto; font-weight: 700; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.quick button { border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer; color: var(--muted); }
.quick button:hover { color: var(--text); border-style: solid; }
.calc { position: sticky; bottom: 0; background: var(--head); color: var(--head-text); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); z-index: 2; }
.calc-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.calc-nums span { display: block; font-size: 12px; color: #b9b4ae; }
.calc-nums b { font-size: 19px; font-variant-numeric: tabular-nums; }
.calc-nums b.neg { color: #ff5446; }
.calc-nums b.pos { color: #6fe09c; }
.calc-note { font-size: 12px; color: #b9b4ae; margin-top: 4px; }
.calc .row { margin-top: 10px; }
.calc .btn-ghost { color: var(--head-text); border-color: #3a3836; }
.calc .btn-danger { border-color: #3a3836; color: #ff6b60; }
.meta { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------- Аккаунты и журнал ---------- */
.users .u { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.users .u:first-child { border-top: 0; }
.users .u .nm { flex: 1; min-width: 0; }
.users .u .nm small { display: block; color: var(--muted); }
.log-item { padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.log-item:first-child { border-top: 0; }
.log-item .when { color: var(--muted); font-size: 12px; }
.log-item b { font-weight: 700; }

/* ---------- Кнопка «Добавить» и тост ---------- */
.fab { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 999px; padding: 14px 20px 14px 16px;
  font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 8px; box-shadow: 0 6px 20px rgba(225, 6, 0, .35); cursor: pointer; }
.fab:hover { background: var(--accent-press); }
.fab svg { width: 22px; height: 22px; stroke-width: 2.6; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--head); color: var(--head-text); padding: 11px 16px; border-radius: 12px; font-weight: 600; opacity: 0;
  pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--neg); color: #fff; }

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .dev-table { display: none; }
  .dev-cards { display: block; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .q { grid-column: 1 / -1; }
  .who { display: none; }
  .brand-sub { font-size: 12px; letter-spacing: .8px; }
}
@media (max-width: 560px) {
  .modal { padding: 0; }
  .sheet { border-radius: 0; min-height: 100%; max-width: none; }
  .sheet-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .kpi .v { font-size: 20px; }
  .kpi.main .v { font-size: 30px; }
  .cost-row { grid-template-columns: 1fr 108px 36px; gap: 6px; }
  .wide { grid-column: auto; }
  .calc-nums b { font-size: 17px; }
  .sheet-body { padding: 12px; }
  .card { padding: 14px; }
}
@media print {
  .top, .fab, .filters, .toast { display: none !important; }
  body { background: #fff; padding: 0; }
}

/* ---------- переключатель темы (общий для сайтов ТЕК-9) ---------- */
.t9-theme { border: 1px solid #3a3836; border-radius: 50%; }
.t9-theme svg { display: none; }
html:not([data-tmode]) .t9-theme .ti-auto, html[data-tmode="auto"] .t9-theme .ti-auto, html[data-tmode="light"] .t9-theme .ti-light, html[data-tmode="dark"] .t9-theme .ti-dark { display: block; }
.t9-tip { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1a1516; color: #fff;
  padding: 9px 14px; border-radius: 10px; font-size: 14px; font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 9999; white-space: nowrap; }
.t9-tip.on { opacity: 1; }
@media print { .t9-theme, .t9-tip { display: none !important; } }

/* пометка «из выкупа» */
.tag-buy { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; vertical-align: 2px;
  background: var(--card-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
