:root {
  --bg: #14110e;
  --bg-2: #1d1914;
  --panel: #231e18;
  --line: #3a3128;
  --text: #f3ece3;
  --muted: #b7aa9a;
  --accent: #e08a2c;
  --accent-2: #f0c27a;
  --ok: #8fbf6a;
  --danger: #d66a5a;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(224, 138, 44, 0.16), transparent 50%),
    linear-gradient(180deg, var(--bg), #0f0d0b 80%);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; overflow-x: hidden; }
.side {
  background: #181410;
  border-right: 1px solid var(--line);
  padding: 22px 16px;
}
.brand { font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }
.brand span { color: var(--accent); }
.error {
  background: #3a1e1a;
  color: #f0b4ab;
  border: 1px solid #6a3a34;
  border-radius: 10px;
  padding: 10px 12px;
}
.notice {
  background: #24331c;
  color: var(--ok);
  border: 1px solid #3a5530;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.status.wait_parts { background: #3a2a16; color: var(--accent-2); }
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-card {
  width: min(420px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card .brand { font-size: 26px; }
.side nav { margin-top: 28px; display: grid; gap: 6px; }
.side a {
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
}
.side a.active, .side a:hover {
  background: #2b241c;
  color: var(--text);
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.check input { width: auto; }
.main { padding: 28px 32px 48px; min-width: 0; max-width: 100%; overflow-x: hidden; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 22px;
  min-width: 0;
  max-width: 100%;
}
.top h1, .top h2 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: break-word;
  align-self: center;
}
.top .grow { flex: 1 1 160px; min-width: 0; max-width: 380px; }
.top .btn, .top button, .top form { flex: 0 0 auto; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}
.catalog-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 170px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
  max-width: 100%;
}
.catalog-add input,
.catalog-add select { width: 100%; }
h1, h2 { margin: 0 0 12px; font-weight: 650; }
.muted { color: var(--muted); }
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(3, 1fr); }
.card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.card { padding: 18px; }
.card .n { font-size: 28px; font-weight: 700; color: var(--accent-2); }
.panel { padding: 18px; max-width: 100%; overflow-x: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea, button {
  font: inherit;
  color: var(--text);
}
input, select, textarea {
  background: #16130f;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  min-width: 0;
}
textarea { min-height: 78px; width: 100%; }
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: end;
  background: var(--accent);
  color: #1a120b;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  height: 40px;
  white-space: nowrap;
}
.btn.ghost, button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.ok { background: var(--ok); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
td a { color: var(--accent-2); text-decoration: none; }
td a:hover { color: var(--text); }
th { color: var(--muted); font-size: 12px; font-weight: 600; }
.table-wrap { overflow: auto; }
.vin { font-family: Consolas, "Segoe UI", monospace; font-size: 12px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.status { padding: 3px 8px; border-radius: 999px; font-size: 12px; background: #3a3128; white-space: nowrap; display: inline-block; }
.status.open { background: #3a2a16; color: var(--accent-2); }
.status.done { background: #24331c; color: var(--ok); }
.btn.danger, button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid #6a3a34;
}
[hidden] { display: none !important; }
.new-client-box,
.new-client-box[hidden] { display: none !important; }
.new-client-box.is-open { display: flex !important; }
.combo { position: relative; min-width: 0; z-index: 2; }
.combo:focus-within { z-index: 80; }
.combo-list {
  display: none;
  position: absolute;
  z-index: 90;
  left: 0;
  top: calc(100% + 4px);
  width: 100%;
  max-width: min(480px, calc(100vw - 32px));
  max-height: 280px;
  overflow-x: hidden;
  overflow-y: auto;
  background: #16130f;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px 0;
}
.combo-list.open {
  display: block !important;
}
.combo-list .combo-item,
.combo-list .hint {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 0;
  padding: 9px 14px;
  line-height: 1.35;
  font: inherit;
  font-weight: 400;
  cursor: pointer;
  height: auto;
  align-self: auto;
  justify-content: flex-start;
  white-space: normal;
}
.combo-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.combo-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.combo-list .combo-item:hover,
.combo-list .combo-item.active { background: #2b241c; }
.combo-list .hint { color: var(--muted); cursor: default; font-weight: 400; }
.car-info {
  margin-top: 14px;
  padding: 12px 14px;
  background: #16130f;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  gap: 10px;
}
.car-info.is-empty {
  color: var(--muted);
  font-size: 13px;
  display: block;
}
.car-info-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.car-info-title {
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
}
.car-info-plate {
  font-family: Consolas, "Segoe UI", monospace;
  letter-spacing: 0.06em;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #2b241c;
  white-space: nowrap;
}
.car-info-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.car-tag {
  display: grid;
  gap: 2px;
  min-width: 84px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #1d1914;
}
.car-tag em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
}
.car-tag b {
  color: var(--text);
  font-weight: 650;
  font-size: 13px;
  word-break: break-all;
}
.line-grid { display: grid; grid-template-columns: 36px minmax(180px, 1.6fr) 88px 88px 150px 100px 100px 40px; gap: 6px; margin-bottom: 6px; overflow: visible; align-items: end; }
.line-grid > input[type="hidden"] { display: none; }
.line-grid.parts { grid-template-columns: 36px minmax(180px, 1.8fr) 88px 110px 110px 40px; }
.line-grid input, .line-grid select, .line-grid .combo { width: 100%; }
.line-head {
  margin-bottom: 4px;
  padding: 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.line-head span { padding: 0 4px; line-height: 1.2; }
.line-grid > button { padding: 0; }
.catalog-edit { margin: 0; }
#filter-table .act { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; }
#filter-table .act form { display: none; }
.totals { margin-left: auto; width: 280px; display: grid; gap: 8px; }
.totals div { display: flex; justify-content: space-between; }
.warehouse { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.warehouse .table-wrap { min-width: 0; overflow: auto; }
#stock-table { width: 100%; }
#stock-table th, #stock-table td { vertical-align: top; }
#stock-table td:first-child { min-width: 0; }
#stock-table tbody tr[data-id] { cursor: pointer; }
#stock-table tbody tr.is-on { background: #2b241c; }
#details input[readonly] { opacity: 0.9; }
.report-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 200px;
  padding: 8px 4px 28px;
}
.chart-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}
.chart-bar {
  width: 70%;
  max-width: 26px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-radius: 6px 6px 0 0;
}
.chart-col span {
  position: absolute;
  bottom: -22px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.mobile-bar { display: none; }
.nav-backdrop { display: none; }
@media (min-width: 861px) {
  .panel { overflow-x: auto; }
  table { width: 100%; }
  th, td { vertical-align: middle; }
  .catalog-table { table-layout: fixed; }
  .catalog-table th,
  .catalog-table td { white-space: nowrap; }
  .catalog-table th:nth-child(2), .catalog-table td:nth-child(2) { width: 130px; }
  .catalog-table th:nth-child(3), .catalog-table td:nth-child(3) { width: 190px; }
  .catalog-table th:nth-child(4), .catalog-table td:nth-child(4) { width: 230px; }
  .catalog-table td input,
  .catalog-table td select { width: 100%; min-width: 0; box-sizing: border-box; }
}

@media (max-width: 980px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .warehouse { grid-template-columns: 1fr; }
  .report-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  html, body {
    overflow-x: hidden;
    max-width: 100%;
    background: #0f0d0b;
  }
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 160;
    width: 100%;
    max-width: 100%;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: #181410;
    border-bottom: 1px solid var(--line);
  }
  .menu-toggle {
    display: inline-flex;
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    align-self: center;
    font-size: 22px;
    line-height: 1;
    background: #2b241c;
    color: var(--text);
  }
  .app {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }
  .side {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    z-index: 220;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    overflow: auto;
    padding-top: max(22px, env(safe-area-inset-top));
    box-shadow: var(--shadow);
  }
  .side .brand { display: none; }
  .side nav {
    display: grid;
    margin-top: 8px;
  }
  .side a { padding: 12px 14px; font-size: 16px; }
  body.nav-open .side { transform: none; }
  body.nav-open { overflow: hidden; }
  body.nav-open .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 180;
    background: rgba(0, 0, 0, 0.5);
  }
  .main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 14px 12px 36px;
    padding-bottom: max(36px, env(safe-area-inset-bottom));
    overflow-x: hidden;
  }
  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
    min-width: 0;
  }
  .top > div { min-width: 0; }
  .top .grow { max-width: 100%; flex: 1 1 auto; }
  .top .btn, .top button { align-self: start; }
  h1 { font-size: 22px; overflow-wrap: break-word; }
  .muted { overflow-wrap: break-word; }
  .top .actions, .top .row, .top form, .top .toolbar { width: 100%; max-width: 100%; }
  .toolbar { justify-content: flex-start; margin-left: 0; }
  .toolbar label.grow { flex: 1 1 100%; max-width: 100%; }
  .top .actions .btn,
  .top .actions button,
  .actions .btn,
  .actions button {
    flex: 1 1 auto;
    max-width: 100%;
    white-space: normal;
  }
  .panel, .card, .grid, .cards {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .panel { padding: 12px; overflow: visible; }
  .table-wrap { overflow: visible; }
  table { font-size: 15px; width: 100%; border-collapse: separate; border-spacing: 0; }
  thead { display: none; }
  tbody { display: block; }
  tbody tr {
    display: block;
    background: #1d1914;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  tbody tr:last-child { margin-bottom: 0; }
  th, td {
    padding: 0;
    border: 0;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
  }
  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid #2b241c;
    text-align: right;
  }
  tbody td:last-child { border-bottom: 0; }
  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    flex: 0 0 34%;
    max-width: 38%;
  }
  tbody td:not([data-label]):not(:only-child) { display: none; }
  tbody td[colspan],
  tbody td:only-child {
    display: block;
    text-align: left;
    padding: 0;
    border: 0;
  }
  tbody td[colspan]::before,
  tbody td:only-child::before { content: none; }
  .panel:has(> table:only-child) {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
  }
  .catalog-table tbody td {
    display: grid;
    gap: 6px;
    justify-content: stretch;
    text-align: left;
  }
  .catalog-table tbody td::before {
    flex: none;
    max-width: none;
  }
  .catalog-table tbody .act {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .catalog-table tbody .act::before { content: none; }
  #stock-table td[data-label="Применимость"],
  #stock-table td[data-label="QR / штрихкод"],
  #stock-table td[data-label="Резерв"],
  #stock-table td[data-label="Ожидается"],
  #stock-table td[data-label="Закупка"] { display: none; }
  #details { display: none; }
  .catalog-add {
    grid-template-columns: 1fr;
  }
  .catalog-edit { flex-direction: column; align-items: stretch; }
  .catalog-edit label,
  .catalog-edit button { width: 100%; }
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .card { padding: 12px; }
  .card .n { font-size: 22px; overflow-wrap: break-word; }
  .report-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart { height: 160px; overflow: hidden; }
  .row { width: 100%; }
  .row > label,
  .row > .grow { flex: 1 1 100%; min-width: 0; max-width: 100%; }
  .grow { min-width: 0; }
  label { font-size: 12px; }
  input, select, textarea {
    font-size: 16px;
    min-height: 44px;
    max-width: 100%;
  }
  textarea { min-height: 96px; }
  button, .btn {
    height: auto;
    min-height: 44px;
  }
  .combo { max-width: 100%; }
  .combo-list {
    width: 100%;
    max-width: 100%;
    max-height: 220px;
  }
  .combo-list .combo-item { padding: 12px 14px; }
  .totals { width: 100%; margin-left: 0; }
  .car-info-head { flex-wrap: wrap; }
  .line-head { display: none; }
  .line-grid,
  .line-grid.parts {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px;
    gap: 8px;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #1d1914;
    align-items: stretch;
    max-width: 100%;
  }
  .line-grid > input:disabled:not(.js-sum) { display: none; }
  .line-grid > .combo {
    grid-column: 1 / 3;
    grid-row: 1;
    min-width: 0;
  }
  .line-grid > button {
    grid-column: 3;
    grid-row: 1;
    align-self: stretch;
    height: 44px;
  }
  .line-grid.parts > [name^="p_quantity_"] { grid-column: 1; }
  .line-grid.parts > [name^="p_price_"] { grid-column: 2; }
  .line-grid.parts > .js-sum { grid-column: 1 / 4; }
}

@media (max-width: 520px) {
  .cards, .report-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
