:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b92a3;
  --accent: #4f8cff;
  --ok: #34c759;
  --soon: #ffb020;
  --overdue: #ff4d4f;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
button {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
}
button.ghost { background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
button.danger { background: var(--overdue); }
a { color: var(--accent); }

/* --- логін --- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-logo { width: 112px; height: 112px; margin: 0 auto 4px; border-radius: 26px; }
.login-box h1 { margin: 0 0 12px; font-size: 22px; }
.err { color: var(--overdue); font-size: 13px; min-height: 16px; }

/* --- каркас --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px calc(10px + env(safe-area-inset-top));
  background: rgba(15,17,21,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; }
.topbar .icon-btn { background: none; padding: 6px; font-size: 18px; }
main { max-width: 640px; margin: 0 auto; padding: 12px 12px 90px; }

/* --- вибір авто --- */
.car-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.car-tab {
  flex: none; padding: 8px 14px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
  font-weight: 600; font-size: 13px; white-space: nowrap;
}
.car-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- картка авто --- */
.car-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.car-card .name { font-size: 18px; font-weight: 700; margin-bottom: 2px; }
.car-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.mileage-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mileage-row .val { font-size: 22px; font-weight: 700; }
.mileage-row .lbl { color: var(--muted); font-size: 12px; }

.summary-row { display: flex; gap: 8px; margin-bottom: 14px; }
.summary-pill {
  flex: 1; text-align: center; padding: 10px 6px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
}
.summary-pill .n { font-size: 20px; font-weight: 700; display: block; }
.summary-pill.overdue .n { color: var(--overdue); }
.summary-pill.soon .n { color: var(--soon); }
.summary-pill.ok .n { color: var(--ok); }
.summary-pill .l { color: var(--muted); font-size: 11px; }

/* --- список ТО --- */
.to-list { display: flex; flex-direction: column; gap: 8px; }
.to-item {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 10px; padding: 12px 14px; display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.to-item.overdue { border-left-color: var(--overdue); }
.to-item.soon { border-left-color: var(--soon); }
.to-item.ok { border-left-color: var(--ok); }
.to-item .body { flex: 1; min-width: 0; }
.to-item .title { font-weight: 600; }
.to-item .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.to-item .status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.to-item.overdue .status-dot { background: var(--overdue); }
.to-item.soon .status-dot { background: var(--soon); }
.to-item.ok .status-dot { background: var(--ok); }
.badge-est { font-size: 10.5px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; margin-left: 6px; }

/* --- історія --- */
.record-item {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 10px;
}
.record-item .title { font-weight: 600; }
.record-item .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.record-item .cost { font-weight: 700; white-space: nowrap; }

/* --- нижня навігація --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; background: rgba(23,26,33,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; background: none; border-radius: 0; padding: 8px 4px;
  color: var(--muted); font-weight: 600; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar button.active { color: var(--accent); }
.tabbar .ic { font-size: 19px; }

/* --- модалка --- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 640px; background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
.sheet h2 { margin: 0 0 14px; font-size: 17px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions button { flex: 1; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 18px 0 8px; }
.hidden { display: none !important; }

/* --- гараж: індикатор стану авто --- */
.car-tab .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.car-tab .dot.overdue { background: var(--overdue); }
.car-tab .dot.soon { background: var(--soon); }
.btn-col { display: flex; flex-direction: column; gap: 6px; }
.btn-col button { padding: 9px 16px; }
.btn-block { width: 100%; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }

/* --- сервісна книга --- */
.search { margin: 10px 0 8px; }
.chip-row { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.add { border-style: dashed; color: var(--accent); }
.hist-summary { color: var(--muted); font-size: 12.5px; margin: 2px 0 6px; }
.year-head {
  display: flex; justify-content: space-between; gap: 10px; margin: 16px 0 8px;
  font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
}
.year-head span:first-child { color: var(--text); font-size: 15px; }
.visit {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.visit-top { display: flex; justify-content: space-between; gap: 10px; }
.v-date { font-weight: 700; }
.v-meta { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.v-cost { font-weight: 700; white-space: nowrap; }
.v-items { list-style: none; margin: 8px 0 0; padding: 0; }
.v-items li { padding: 3px 0 3px 12px; position: relative; font-size: 14px; }
.v-items li::before { content: ''; position: absolute; left: 0; top: 11px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.part { color: var(--muted); font-size: 12.5px; margin-left: 4px; }
.v-notes { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); color: var(--muted); font-size: 12.5px; }

/* --- форма візиту --- */
.work-row { background: var(--panel2); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.work-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.work-name { flex: 1; font-weight: 600; font-size: 14px; }
.work-custom { flex: 1; }
.x { background: none; color: var(--muted); padding: 4px 8px; font-size: 15px; }

/* --- налаштування --- */
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; }
.check input { width: auto; }
.check.inline { margin: 0; white-space: nowrap; }
.share-link { margin-top: 12px; font-size: 13px; }
.archived-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; }
.archived-row button { padding: 8px 12px; }
.chip-row, .car-tabs { scrollbar-width: none; }
.chip-row::-webkit-scrollbar, .car-tabs::-webkit-scrollbar { display: none; }
.chip.done { background: var(--ok); border-color: var(--ok); color: #0b1a10; }

/* --- статус-бар (прогрес до заміни / строк дії поліса) --- */
.bar { height: 6px; border-radius: 999px; background: var(--panel2); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.bar span.ok { background: var(--ok); }
.bar span.soon { background: var(--soon); }
.bar span.overdue, .bar span.expired { background: var(--overdue); }
.bar.est { background: repeating-linear-gradient(90deg, var(--panel2) 0 6px, transparent 6px 10px); }
.bar-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.bar-row .bar { flex: 1; }
.bar-pct { font-size: 11.5px; color: var(--muted); min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }

.ins-card {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--ok);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; cursor: pointer;
}
.ins-card.soon { border-left-color: var(--soon); }
.ins-card.overdue { border-left-color: var(--overdue); }
.ins-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.ins-title { font-weight: 700; }
.ins-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.ins-days { font-weight: 700; font-size: 13px; text-align: right; color: var(--ok); }
.ins-days.soon { color: var(--soon); }
.ins-days.overdue { color: var(--overdue); }
.ins-dates { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }
.ins-add { color: var(--accent); font-weight: 600; font-size: 13px; }

/* --- регламент за заводом --- */
.plan-title { font-weight: 700; font-size: 16px; }
.pre { white-space: pre-line; }
.stage {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 12px; padding: 4px 14px 12px; margin-bottom: 8px;
}
.stage.done { border-left-color: var(--ok); }
.stage.partial { border-left-color: var(--soon); }
.stage.missed { border-left-color: var(--overdue); opacity: .9; }
.stage.next { border-left-color: var(--accent); }
.stage.future { border-left-color: var(--border); }
.stage-head {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: none; padding: 10px 0 6px; border-radius: 0; font-size: 15px;
}
.stage-km { font-weight: 700; flex: 1; }
.chev { color: var(--muted); font-size: 13px; }
.badge { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.badge.ok { background: rgba(52,199,89,.15); color: var(--ok); }
.badge.soon { background: rgba(255,176,32,.15); color: var(--soon); }
.badge.miss { background: rgba(255,77,79,.15); color: var(--overdue); }
.badge.next { background: rgba(79,140,255,.15); color: var(--accent); }
.stage-tasks { margin-top: 6px; }
.st-task { display: flex; gap: 10px; padding: 5px 0; font-size: 14px; }
.st-mark { width: 16px; text-align: center; color: var(--muted); flex: none; }
.st-task.done .st-mark { color: var(--ok); font-weight: 700; }
.st-meta { color: var(--muted); font-size: 12px; margin-top: 1px; }
.stage-do { width: 100%; margin-top: 10px; padding: 10px; }
.stage-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.stage-pill { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: rgba(79,140,255,.15); color: var(--accent); }
.plan-opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border); }
.plan-opt.current .plan-opt-title { color: var(--accent); }
.plan-opt-title { font-weight: 600; font-size: 14px; }
.plan-opt button { flex: none; padding: 9px 14px; }
.unv { font-size: 10.5px; color: var(--soon); border: 1px solid rgba(255,176,32,.4); border-radius: 6px; padding: 0 5px; margin-left: 6px; vertical-align: middle; }
.plan-details { margin-top: 6px; }
.plan-details summary { color: var(--accent); font-size: 13px; cursor: pointer; padding: 4px 0; }
