/* Автопомощник — оформление Mini App.
   Цвета берутся из themeParams Telegram (переменные проставляет app.js),
   значения ниже — фолбэк для обычного браузера. */

:root {
  --bg: #f2f3f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #1c1c1e;
  --hint: #8b8e97;
  --link: #2f7fed;
  --accent: #2f7fed;
  --accent-contrast: #ffffff;
  --border: rgba(0, 0, 0, .08);
  --danger: #e5484d;
  --warning: #e08b1a;
  --success: #2ba24c;
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;

  --c-fuel: #2f7fed;
  --c-service: #9a5cf0;
  --c-expenses: #e08b1a;
  --c-extra-1: #2ba24c;
  --c-extra-2: #e5484d;
  --c-extra-3: #12a3b4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #22242a;
    --surface-2: #2a2d34;
    --text: #f2f3f5;
    --hint: #91949c;
    --border: rgba(255, 255, 255, .09);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }

/* ------------------------------------------------------------ загрузка */

.boot {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--hint);
}
.boot__logo { font-size: 40px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .45 } 50% { opacity: 1 } }

/* ------------------------------------------------------------ каркас */

.screen { padding: var(--gap) var(--gap) 24px; max-width: 720px; margin: 0 auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px var(--gap);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__title { font-weight: 650; font-size: 17px; flex: 1; min-width: 0; }
.topbar__title small { display: block; font-weight: 400; font-size: 12px; color: var(--hint); }

.vehicle-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 550;
  max-width: 48%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------ карточки */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: var(--gap);
  border: 1px solid var(--border);
}
.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.card__title { font-weight: 600; font-size: 14px; }
.card__hint { font-size: 12px; color: var(--hint); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-2 > .card { margin-bottom: 0; }

.metric__value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.metric__unit { font-size: 14px; font-weight: 500; color: var(--hint); margin-left: 3px; }
.metric__label { font-size: 12px; color: var(--hint); margin-top: 2px; }
.metric__delta { font-size: 12px; margin-top: 6px; font-weight: 550; }
.metric__delta.up { color: var(--danger); }
.metric__delta.down { color: var(--success); }
.metric__delta.flat { color: var(--hint); }

/* ------------------------------------------------------------ быстрые действия */

.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: var(--gap); }
.quick__btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 550;
  transition: transform .12s ease;
}
.quick__btn:active { transform: scale(.96); }
.quick__icon { font-size: 20px; line-height: 1; }

/* ------------------------------------------------------------ период */

.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: var(--gap);
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: 1 0 auto;
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 550;
  color: var(--hint);
  white-space: nowrap;
}
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ------------------------------------------------------------ списки */

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list__item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  width: 100%;
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  text-align: left;
}
.list__item:last-child { border-bottom: 0; }
.list__item:active { background: var(--surface-2); }
.list__icon {
  width: 36px; height: 36px; flex: 0 0 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  font-size: 17px;
}
.list__body { flex: 1; min-width: 0; }
.list__title { font-weight: 550; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list__sub { font-size: 12px; color: var(--hint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list__right { text-align: right; flex: 0 0 auto; }
.list__amount { font-weight: 600; font-size: 14px; white-space: nowrap; }
.list__meta { font-size: 12px; color: var(--hint); margin-top: 2px; white-space: nowrap; }

.group-title { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; margin: 18px 2px 8px; font-weight: 600; }

.empty { text-align: center; color: var(--hint); padding: 34px 16px; }
.empty__icon { font-size: 34px; margin-bottom: 8px; opacity: .6; }
.empty__text { font-size: 14px; }

/* ------------------------------------------------------------ бейджи */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--hint);
}
.badge--danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge--warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge--success { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge--partial { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }

/* ------------------------------------------------------------ прогресс ресурса */

.resource { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.resource:last-child { border-bottom: 0; }
.resource__head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.resource__name { font-weight: 550; font-size: 14px; }
.resource__left { font-size: 12px; color: var(--hint); }
.resource__bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.resource__fill { height: 100%; border-radius: 3px; background: var(--success); transition: width .3s ease; }
.resource__fill.soon { background: var(--warning); }
.resource__fill.overdue { background: var(--danger); }

/* ------------------------------------------------------------ графики */

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-size: 10px; fill: var(--hint); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .bar { transition: opacity .15s ease; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); }
.chart .area { fill: var(--accent); opacity: .12; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.legend__item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--hint); }
.legend__dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 9px; }

.donut-wrap { display: flex; align-items: center; gap: 14px; }
.donut-wrap svg { flex: 0 0 128px; }
.donut-legend { flex: 1; min-width: 0; }
.donut-legend__row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.donut-legend__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend__val { color: var(--hint); font-size: 12px; white-space: nowrap; }

/* ------------------------------------------------------------ таббар */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar__btn {
  flex: 1;
  border: 0;
  background: none;
  padding: 8px 2px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 550;
  color: var(--hint);
  position: relative;
}
.tabbar__btn.is-active { color: var(--accent); }
.tabbar__icon { font-size: 19px; line-height: 1; }
.tabbar__dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

/* ------------------------------------------------------------ формы и шторки */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.sheet {
  background: var(--bg);
  width: 100%;
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slide-up .24s cubic-bezier(.2, .8, .3, 1);
  max-width: 720px;
  margin: 0 auto;
}
@keyframes slide-up { from { transform: translateY(28px); opacity: .5 } to { transform: none; opacity: 1 } }

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.sheet__title { font-weight: 650; font-size: 16px; }
.sheet__close { border: 0; background: var(--surface-2); border-radius: 50%; width: 30px; height: 30px; color: var(--hint); font-size: 16px; }
.sheet__body { padding: 14px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet__foot { padding: 10px 16px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--border); display: flex; gap: 8px; }

.field { margin-bottom: 12px; }
.field__label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 5px; font-weight: 550; }
.field__row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input, .select, .textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 16px; /* 16px — иначе iOS зумит при фокусе */
  outline: none;
  appearance: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.textarea { min-height: 76px; resize: vertical; font-size: 15px; }
.select { background-image: none; }
.field__error { color: var(--danger); font-size: 12px; margin-top: 5px; }
.field__hint { color: var(--hint); font-size: 11px; margin-top: 5px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  margin-bottom: 12px;
}
.switch-row__text { font-size: 14px; }
.switch-row__text small { display: block; color: var(--hint); font-size: 11px; margin-top: 2px; }
.switch { position: relative; width: 46px; height: 27px; flex: 0 0 46px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch__track { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; transition: background .18s; }
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.28);
  transition: transform .18s;
}
.switch input:checked + .switch__track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(19px); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
}
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-contrast);
  flex: 1;
}
.btn:disabled { opacity: .55; }
.btn--ghost { background: var(--surface-2); color: var(--text); }
.btn--danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn--sm { padding: 9px 13px; font-size: 13px; flex: 0 0 auto; }

.file-input { display: none; }
.file-pick {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: 11px 12px; width: 100%;
  font-size: 14px; color: var(--hint);
}
.file-preview { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.file-preview img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; }
.file-preview__name { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ уведомления */

#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  max-width: 92%;
  animation: fade .18s ease;
}
.toast--error { color: var(--danger); }
.toast--success { color: var(--success); }

.skeleton { background: var(--surface-2); border-radius: var(--radius); height: 92px; margin-bottom: var(--gap); animation: pulse 1.3s ease-in-out infinite; }

.divider { height: 1px; background: var(--border); margin: 14px 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--hint); }
.nowrap { white-space: nowrap; }
.text-sm { font-size: 13px; }
.mt-8 { margin-top: 8px; }
.mb-0 { margin-bottom: 0; }
