/* ГАРАЖ — светлая тема, адаптив под телефон */
:root {
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #1e2a3a;
  --muted: #64748b;
  --line: #e3e9f1;
  --accent: #2563eb;
  --accent-soft: #eaf1fe;
  --green: #16a34a;
  --green-soft: #e8f7ee;
  --red: #dc2626;
  --red-soft: #fdecec;
  --orange: #d97706;
  --orange-soft: #fdf3e2;
  --violet: #7c3aed;
  --violet-soft: #f1eafe;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 42, 58, .07), 0 4px 16px rgba(30, 42, 58, .05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }

#app { display: flex; min-height: 100dvh; }
#sidebar {
  width: 230px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line);
  padding: 18px 12px; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}
.logo { font-size: 18px; font-weight: 700; padding: 4px 10px 16px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 500; margin-bottom: 2px;
}
#nav a .ico { width: 22px; text-align: center; }
#nav a:hover { background: var(--bg); }
#nav a.active { background: var(--accent-soft); color: var(--accent); }

#main { flex: 1; min-width: 0; padding: 20px 24px 90px; max-width: 1150px; }
#bottomNav { display: none; }

h1 { font-size: 22px; margin-bottom: 4px; }
h2 { font-size: 17px; margin: 18px 0 10px; }
.sub { color: var(--muted); margin-bottom: 16px; font-size: 14px; }

/* панель заголовка страницы */
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead h1 { margin: 0; }

/* карточки и сетки */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; cursor: pointer; }
.stat .num { font-size: 24px; font-weight: 700; margin-top: 2px; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.warn .num { color: var(--orange); }
.stat.bad .num { color: var(--red); }
.stat.good .num { color: var(--green); }

/* таблицы */
.tblwrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; }
table { border-collapse: collapse; width: 100%; min-width: 560px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.wrap, th.wrap { white-space: normal; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f7fafd; }
td.r, th.r { text-align: right; }

/* бейджи */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; }
.b-green { background: var(--green-soft); color: var(--green); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-orange { background: var(--orange-soft); color: var(--orange); }
.b-blue { background: var(--accent-soft); color: var(--accent); }
.b-violet { background: var(--violet-soft); color: var(--violet); }
.b-gray { background: #eef1f5; color: var(--muted); }

/* кнопки */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; padding: 9px 16px; border-radius: 10px; font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn.sec { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.sec:hover { background: var(--bg); filter: none; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.green { background: var(--green); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

/* формы */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=month], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 70px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 10px; cursor: pointer; font-weight: 500; background: #fff;
}
.checks label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* панель фильтров */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type=text] { flex: 1 1 200px; min-width: 150px; width: auto; }
.filters select, .filters input[type=date], .filters input[type=month] { width: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 99px;
  cursor: pointer; font-weight: 600; color: var(--muted);
}
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* модальные окна */
#modalRoot:empty { display: none; }
.modal-back {
  position: fixed; inset: 0; background: rgba(20, 30, 45, .45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 10px; overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 640px;
  padding: 20px; box-shadow: 0 12px 48px rgba(0,0,0,.22); margin: auto 0;
}
.modal h2 { margin: 0 0 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* тост */
#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 99;
  background: #1e2a3a; color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .25s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--red); }

/* список ремонтов в карточке машины */
.rep-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.rep-item .top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }
.rep-item .parts { color: var(--muted); font-size: 13.5px; margin-top: 6px; }

/* прогресс-полоски в отчётах */
.bar { height: 8px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt { margin-top: 12px; }
.nowrapline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.empty .big { font-size: 34px; margin-bottom: 6px; }

/* строки запчастей в ремонте */
.partline { display: grid; grid-template-columns: 1fr 84px 32px; gap: 8px; margin-bottom: 8px; align-items: center; }
.partline .del { background: var(--red-soft); color: var(--red); border: none; border-radius: 8px; height: 36px; cursor: pointer; font-size: 16px; }
.partline.order { grid-template-columns: 1fr 74px 92px 32px; }
@media (max-width: 480px) { .partline.order { grid-template-columns: 1fr 64px 76px 30px; } }

/* табель: сетка месяца */
.att-scroll { overflow-x: auto; }
.att-grid td, .att-grid th { padding: 6px 6px; text-align: center; font-size: 12.5px; }
.att-grid td.name { text-align: left; white-space: nowrap; font-weight: 600; }
.att-grid td.wknd { background: #f7f9fc; }
.att-p { color: var(--green); font-weight: 700; }
.att-a { color: var(--red); font-weight: 700; }
.att-s { color: var(--orange); font-weight: 700; }
.att-v { color: var(--violet); font-weight: 700; }

/* вход по PIN и текущий пользователь */
body.login-mode #sidebar, body.login-mode #bottomNav { display: none !important; }
.login-wrap { min-height: 90dvh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; }
.login-user { width: 100%; justify-content: flex-start; margin-top: 8px; padding: 12px 16px; font-size: 16px; }
.userbox { margin-top: 14px; padding: 10px 12px; border-top: 1px solid var(--line); }
.userbox a { color: var(--red); cursor: pointer; text-decoration: none; }

/* фишки категорий и группировка склада */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 99px;
  padding: 5px 13px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted);
}
.chip:hover { background: var(--bg); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
tr.cat-row td { background: var(--accent-soft); font-weight: 700; color: var(--accent); border-bottom: 1px solid var(--line); padding: 7px 12px; }
tr.grp-row td { background: #f7f9fc; font-weight: 600; font-size: 13px; color: var(--violet); padding: 5px 12px 5px 22px; }

/* наклейки: лента 58×40 мм, QR слева, текст справа ~30 мм */
.labels-sheet { display: flex; flex-wrap: wrap; gap: 6px; }
.label {
  width: 58mm; height: 40mm; border: 1px dashed #bbb; border-radius: 4px; background: #fff;
  display: flex; align-items: flex-start; gap: 1.5mm; padding: 1.5mm; box-sizing: border-box;
  overflow: hidden; page-break-inside: avoid; color: #000;
}
.label .qrbox { width: 22mm; height: 22mm; flex-shrink: 0; margin-top: 0.5mm; }
.label .qrbox svg { width: 100%; height: 100%; display: block; }
.label .ltxt { min-width: 0; flex: 1; line-height: 1.15; overflow: hidden; max-height: 100%; }
.label .lname { font-weight: 700; font-size: 8.5pt; line-height: 1.12; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; word-break: break-word; }
.label .lfits { font-size: 7.5pt; font-weight: 700; margin-top: 0.5mm; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.label .lsku { font-size: 7pt; font-family: Consolas, monospace; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.label .lmeta { font-size: 6.5pt; color: #333; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
@media print {
  #sidebar, #bottomNav, #toast, .noprint { display: none !important; }
  #main { padding: 0; max-width: none; }
  body { background: #fff; }
  .labels-sheet { display: block; gap: 0; }
  .label { border: none; border-radius: 0; page-break-after: always; margin: 0; }
  @page { size: 58mm 40mm; margin: 0; }
}

/* ответ ИИ */
.ai-answer h2, .ai-answer h3, .ai-answer h4 { margin: 14px 0 6px; }
.ai-answer p { margin: 6px 0; }
.ai-answer ul { margin: 6px 0 6px 22px; }
.ai-answer li { margin: 3px 0; }

/* мобильный вид */
@media (max-width: 760px) {
  #sidebar { display: none; }
  #main { padding: 14px 12px 84px; }
  #bottomNav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  #bottomNav a {
    flex: 1; text-align: center; text-decoration: none; color: var(--muted);
    font-size: 10.5px; font-weight: 600; padding: 3px 0; border-radius: 10px;
  }
  #bottomNav a .ico { display: block; font-size: 21px; }
  #bottomNav a.active { color: var(--accent); background: var(--accent-soft); }
  .row2, .row3 { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  .modal-back { padding: 12px 8px; }
  .modal { padding: 16px 14px; }
}
