:root {
  --navy: #14406a;
  --navy-dark: #0e2f50;
  --blue: #2a6fb0;
  --blue-light: #eaf2fb;
  --line: #e2e6ec;
  --text: #1d2733;
  --muted: #6b7785;
  --bg: #ffffff;
  --row-alt: #f6f8fb;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* --- Поиск VIN --- */
.vin-bar { border-bottom: 1px solid var(--line); padding: 18px 20px; }
.vin-bar__inner { max-width: none; margin: 0 auto; display: flex; align-items: center; gap: 16px; }
.vin-bar__label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.vin-bar__field { display: flex; flex: 1; max-width: none; position: relative; }
.vin-bar__field input {
  flex: 1; height: 40px; border: 1px solid var(--line); border-right: none;
  border-radius: var(--radius) 0 0 var(--radius); padding: 0 12px; font-size: 15px;
  letter-spacing: 0.5px; outline: none; color: var(--text);
}
.vin-bar__field input:focus { border-color: var(--blue); }
.vin-bar__field button {
  width: 46px; border: none; background: var(--navy); color: #fff; cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0; display: flex; align-items: center; justify-content: center;
}
.vin-bar__field button:hover { background: var(--navy-dark); }

/* --- Выпадашка истории VIN (последние, из localStorage) --- */
.vin-history {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .14); z-index: 60;
  max-height: 340px; overflow-y: auto; overflow-x: hidden;
}
.vin-history.hidden { display: none; }
.vin-history__head { padding: 7px 12px; font-size: 12px; color: var(--muted); background: #f6f7f9; border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.vin-history__item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; cursor: pointer; }
.vin-history__item:hover { background: #eef3ff; }
.vin-history__vin { font-family: ui-monospace, Consolas, monospace; letter-spacing: 1px; font-size: 14px; color: var(--text); }
.vin-history__del { color: #c2c7cf; font-size: 13px; padding: 0 6px; line-height: 1; }
.vin-history__del:hover { color: var(--blue); }

/* --- Шапка авто --- */
.vehicle { max-width: none; margin: 0 auto; padding: 16px 20px 0; }
.vehicle h1 { font-size: 20px; margin: 0 0 12px; color: var(--navy); font-weight: 600; }
.vehicle__table { width: 100%; border-collapse: collapse; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.vehicle__table th {
  background: var(--navy); color: #fff; font-weight: 500; font-size: 11px; letter-spacing: 0.4px;
  text-transform: uppercase; text-align: left; padding: 8px 12px;
}
.vehicle__table td { padding: 9px 12px; border-top: 1px solid var(--line); }
.vehicle__table td.brand { color: var(--blue); font-weight: 600; }
.vehicle__badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--blue-light); color: var(--blue); margin-left: 6px; }

/* --- Тело каталога --- */
.catalog { max-width: none; margin: 18px auto 40px; padding: 0 20px; display: grid; grid-template-columns: 300px 1fr; gap: 22px; align-items: start; }

.catalog__tree { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tree-search { padding: 10px; border-bottom: 1px solid var(--line); }
.tree-search input { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 10px; outline: none; font-size: 13px; }
.tree-search input:focus { border-color: var(--blue); }
.tree { max-height: 70vh; overflow-y: auto; padding: 6px 0; }

.tnode__row { display: flex; align-items: center; gap: 6px; padding: 6px 10px; cursor: pointer; user-select: none; font-size: 13px; }
.tnode__row:hover { background: var(--blue-light); }
.tnode__row.active { background: var(--blue-light); color: var(--blue); font-weight: 600; }
.tnode__caret { width: 14px; color: var(--muted); font-size: 10px; flex: none; transition: transform .15s; }
.tnode__caret.open { transform: rotate(90deg); }
.tnode__caret.leaf { visibility: hidden; }
.tnode__name { flex: 1; }
.tnode__count { color: var(--muted); font-size: 11px; }
.tnode__children { display: none; }
.tnode__children.open { display: block; }

/* Закреплённый раздел «Фільтри» сверху дерева */
.tree-pin { font-weight: 600; color: var(--navy); background: #f0f6ff; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.tree-pin:hover { background: var(--blue-light); }
.tree-pin.active { background: var(--blue-light); color: var(--blue); }
.tree-pin .tnode__count { background: var(--navy); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 10px; }

/* Раздел фильтров справа */
.filters-view { border: 1px solid var(--line); border-top: none; border-radius: 0 0 var(--radius) var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 16px; }
.fcard { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.fcard__head { display: flex; align-items: center; gap: 8px; background: var(--blue-light); color: var(--navy); font-weight: 600; font-size: 14px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.fcard__ic { font-size: 16px; line-height: 1; }
.fcard__count { margin-left: auto; background: var(--navy); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 9px; }
.oil-note { color: var(--muted); font-size: 12px; }
.floc { color: var(--blue); cursor: pointer; font-size: 12px; text-decoration: none; }
.floc:hover { text-decoration: underline; }

/* --- Контент справа --- */
.catalog__content { min-height: 300px; }
.placeholder { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

.section-head { font-size: 12px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--muted); background: #eef1f5; padding: 10px 14px; border-radius: var(--radius) var(--radius) 0 0; border: 1px solid var(--line); }
.section-head .crumb { color: var(--blue); cursor: pointer; }
.section-head .crumb:hover { text-decoration: underline; }
.section-head .crumb:last-child { color: var(--text); cursor: default; }
.section-head .crumb:last-child:hover { text-decoration: none; }
.crumb-sep { color: var(--muted); margin: 0 6px; }

.callout { border: 1px solid var(--line); border-top: none; padding: 14px; display: grid; grid-template-columns: 320px 1fr; gap: 18px; }
@media (max-width: 1000px) { .callout { grid-template-columns: 1fr; } .callout__img img { max-height: 420px; } }
.callout:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.callout__title { grid-column: 1 / -1; color: var(--blue); font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.callout__title .num { color: var(--muted); font-weight: 400; margin-right: 6px; }
.callout__img { position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 6px; display: flex; align-items: center; justify-content: center; min-height: 200px; }
.callout__img img { max-width: 100%; max-height: 340px; object-fit: contain; }
.callout__img svg { display: block; max-width: 100%; max-height: 380px; }
.callout__img.empty { color: var(--muted); font-size: 12px; }
.svg-loading { color: var(--muted); font-size: 12px; }
.zoom-link { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; background: rgba(20,64,106,0.9); color: #fff; border-radius: 4px; display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 15px; z-index: 3; }
.zoom-link:hover { background: var(--navy-dark); }
.svg-hot { cursor: pointer; }
.svg-hot:hover { fill: #e24b4a; font-weight: bold; }
.svg-hl { fill: #e24b4a !important; font-weight: bold; }            /* наведення на рядок → підсвічений номер на схемі */
tr.row-flash td { background: #fff3b0 !important; }
tr.row-linked:hover td { background: #eaf2ff !important; }          /* рядок, у якого є номер на схемі — підсвічуємо при наведенні */

.parts { width: 100%; border-collapse: collapse; font-size: 13px; }
.parts th { background: var(--navy); color: #fff; font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; text-align: left; padding: 7px 10px; }
.parts td { padding: 7px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.parts tr:nth-child(even) td { background: var(--row-alt); }
.parts .finis { color: var(--blue); font-weight: 600; cursor: pointer; white-space: nowrap; }
.parts .finis:hover { text-decoration: underline; }
.parts .oem { color: var(--text); cursor: pointer; white-space: nowrap; }
.parts .oem:hover { text-decoration: underline; }
.parts .callout-no { color: var(--muted); width: 34px; }
.parts .bnote { color: var(--muted); font-size: 11px; }
.parts .qty-col { width: 46px; text-align: center; white-space: nowrap; color: var(--muted); }   /* кількість на вузол */
.parts .qty-col.qty-multi { color: var(--text); font-weight: 700; }                              /* >1 виділяємо */
.ecopy { margin-left: 5px; padding: 0 4px; border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 4px; cursor: pointer; font-size: 11px; line-height: 16px; vertical-align: middle; }
.ecopy:hover { color: var(--blue); border-color: var(--blue); }   /* кнопка «копіювати номер» у режимі правок */
.eoem-line { margin-left: 10px; white-space: nowrap; }            /* інженерний (OEM) номер — у тому ж рядку, поряд з FINIS */
.eoem { font-size: 11px; color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace; }
/* Блок прямых результатов поиска по названию (над деревом) */
.search-hits { margin: 0 0 8px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.search-hits__head { background: var(--navy); color: #fff; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; padding: 5px 10px; }
.search-hit { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; cursor: pointer; border-top: 1px solid var(--line); font-size: 13px; }
.search-hit:hover { background: #eaf2ff; }
.search-hit b { color: var(--navy); }
.search-hit .sh-loc { color: var(--muted); font-size: 11px; }
.search-hit .sh-finis { color: var(--blue); font-weight: 600; margin-left: auto; white-space: nowrap; }
.search-hits__more { padding: 5px 10px; color: var(--muted); font-size: 12px; }
.brake-zone { margin-bottom: 18px; }                              /* блок «передні»/«задні» гальма */
.brake-zone__head { font-size: 14px; font-weight: 700; color: #fff; background: var(--navy); border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; }

/* --- Состояния --- */
.state { max-width: 720px; margin: 60px auto; text-align: center; color: var(--muted); padding: 0 20px; }
.state--error { color: #b3261e; font-weight: 500; }
.state__hint { font-size: 12px; margin-top: 6px; color: var(--muted); }
.welcome-ic { width: 56px; height: 56px; border-radius: 50%; background: var(--blue-light); color: var(--blue); font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; letter-spacing: 1px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; margin: 0 auto 14px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Шапка авто (адаптивная сетка) --- */
.vehicle__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); }
.vh-item { background: #fff; display: flex; flex-direction: column; }
.vh-label { font-size: 10px; letter-spacing: 0.4px; text-transform: uppercase; color: #fff; background: var(--navy); padding: 6px 12px; }
.vh-val { font-size: 13px; color: var(--text); padding: 8px 12px; }
.vh-val .brand { color: var(--blue); font-weight: 600; }

/* --- Прокрутка таблицы деталей на узких экранах --- */
.parts-wrap { overflow-x: auto; }
a.finis { text-decoration: none; }
a.finis:hover { text-decoration: underline; }

/* --- Результат поиска по артикулу --- */
.part-result { padding: 18px 20px 40px; }
.pr-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px; }
.pr-name { font-size: 18px; font-weight: 600; color: var(--navy); }
.pr-name-en { color: var(--muted); font-size: 13px; font-style: italic; }
.pr-finis { background: var(--blue-light); color: var(--blue); border: 1px solid #cfe0f3; border-radius: 6px; padding: 4px 12px; font-size: 13px; white-space: nowrap; }
.pr-block { margin-bottom: 16px; }
.pr-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--blue); font-weight: 700; margin-bottom: 8px; }
.pr-loc { font-size: 13px; color: var(--text); padding: 3px 0; }
.pr-qty { color: var(--blue); font-weight: 600; white-space: nowrap; }
.pr-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.pr-role { display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.pr-role--new { background: rgba(0,160,90,0.12); color: #0a7a45; }
.pr-role--req { background: var(--blue-light); color: var(--blue); }
.pr-role--old { background: rgba(200,140,0,0.12); color: #9a6a00; }
.pr-app { font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.pr-code { color: var(--blue); font-weight: 700; }
.pr-empty { color: var(--muted); font-style: italic; }
.avail-btn { display: inline-block; background: #0a7a45; color: #fff; text-decoration: none; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 5px; white-space: nowrap; }
.avail-btn:hover { background: #086237; }

@media (max-width: 860px) {
  .catalog { grid-template-columns: 1fr; }
  .callout { grid-template-columns: 1fr; }
  .vin-bar__inner { flex-wrap: wrap; }
  .vin-bar__field { max-width: none; }
  .pr-cols { grid-template-columns: 1fr; }
  .tree { max-height: 320px; }
}

/* ====== АДМІН-режим: збір патернів фільтрів ====== */
.admin-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 20px 14px; padding: 10px 14px; background: #fff8e6; border: 1px solid #ecd9a3; border-radius: var(--radius); }
.admin-badge { font-weight: 700; color: #8a6a00; font-size: 13px; }
.admin-vin { margin-left: auto; color: var(--muted); font-size: 12px; }
.admin-btn { border: none; background: var(--navy); color: #fff; cursor: pointer; font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: var(--radius); }
.admin-btn:hover { background: var(--navy-dark); }
.admin-btn--ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.admin-btn--ghost:hover { background: var(--blue-light); }

/* Модалка */
.modal-ov { position: fixed; inset: 0; background: rgba(15,30,50,0.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 10px; max-width: 460px; width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,0.25); overflow: hidden; }
.afm { padding: 18px 20px 16px; }
.afm-head { font-size: 14px; color: var(--text); margin-bottom: 14px; line-height: 1.5; }
.afm-vin { color: var(--blue); font-weight: 700; letter-spacing: 0.5px; }
.afm-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.afm-ic { font-size: 18px; width: 22px; text-align: center; }
.afm-label { width: 150px; font-size: 13px; color: var(--muted); }
.afm-input { flex: 1; height: 36px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 10px; font-size: 14px; outline: none; }
.afm-input:focus { border-color: var(--blue); }
.afm-note { font-size: 12px; color: var(--muted); margin: 10px 0 14px; }
.afm-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Результат аналізу */
.an-model { color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 400; }
.an-wrap { border: 1px solid var(--line); border-top: none; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.an-card { border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: var(--radius); padding: 10px 12px; }
.an-card.miss { border-left-color: #c98a00; background: #fffaf0; }
.an-card.ok { border-left-color: #0a7a45; }
.an-card__head { font-weight: 600; font-size: 14px; margin-bottom: 6px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.an-entry { padding: 2px 0; }
.an-entry + .an-entry { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }
.an-entry__head { font-size: 13px; margin-bottom: 2px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.an-finis { color: var(--blue); font-weight: 600; font-size: 13px; }
.an-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 1px 8px; border-radius: 5px; }
.an-tag.ok { background: rgba(10,122,69,0.12); color: #0a7a45; }
.an-tag.miss { background: rgba(201,138,0,0.14); color: #9a6a00; }
.an-loc { font-size: 13px; padding: 5px 0; color: var(--text); border-top: 1px dashed var(--line); margin-top: 6px; }
.an-loc .an-parent { background: #fff3b0; padding: 0 4px; border-radius: 3px; font-weight: 600; }
.an-go { color: var(--blue); cursor: pointer; font-size: 12px; margin-left: 6px; white-space: nowrap; }
.an-go:hover { text-decoration: underline; }
.an-desc { color: var(--muted); font-size: 12px; margin-top: 3px; }
.an-hint { padding: 12px 4px; font-size: 13px; color: var(--muted); }

/* Патерни */
.pat-wrap { padding: 4px 0 10px; }
.pat-title { font-size: 14px; margin: 10px 0 14px; }
.pat-block { margin-bottom: 18px; }
.pat-block__head { font-weight: 600; font-size: 14px; color: var(--navy); margin-bottom: 6px; }
.pat-empty { color: var(--muted); font-style: italic; font-size: 13px; }
.pat-table .pat-c { text-align: right; white-space: nowrap; }
.pat-vins { color: var(--muted); font-size: 11px; }
.pat-leaves { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* ====== Режим правок (admin, ?edit=ключ) ====== */
.edit-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; background: var(--navy); color: #fff; box-shadow: 0 -2px 10px rgba(0,0,0,0.25); }
.edit-bar__t { font-weight: 700; }
.edit-bar__n { color: #cfe0f3; font-size: 13px; }
.edit-bar .admin-btn { background: #fff; color: var(--navy); }
.edit-bar .admin-btn--ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.45); }
.edit-mode #content, .edit-mode .catalog { padding-bottom: 64px; }
th.ecmt-h, td.ecmt-cell { width: 190px; }
input.ecmt { width: 100%; height: 28px; border: 1px solid var(--line); border-radius: 5px; padding: 0 8px; font-size: 12px; outline: none; }
input.ecmt:focus { border-color: var(--blue); }
input.ecmt:not(:placeholder-shown) { background: #fff7cc; border-color: #e0c200; }

/* Лёгкий тост копирования */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy-dark); color: #fff; padding: 9px 16px; border-radius: var(--radius); font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
#toast.show { opacity: 1; }
