/* Компенсации: мини-приложение внутри Telegram.
   Цвета фона и текста берём из темы Telegram, статусы держим одной палитрой в обеих темах. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --text: var(--tg-theme-text-color, #14181f);
  --hint: var(--tg-theme-hint-color, #6b7686);
  --accent: var(--tg-theme-button-color, #2481cc);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);

  --surface: color-mix(in srgb, var(--bg2) 55%, var(--bg));
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --line-strong: color-mix(in srgb, var(--hint) 38%, transparent);

  --s-pending: #d99a00;
  --s-approved: #2f7fe0;
  --s-returned: #e8702a;
  --s-rejected: #d94452;
  --s-done: #1f9d68;
  --danger: var(--s-rejected);

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
  --tab-h: 62px;
  --bar-h: 76px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.4; }
body { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 16px); }
body.has-bar { padding-bottom: calc(var(--tab-h) + var(--bar-h) + env(safe-area-inset-bottom, 0px) + 16px); }
#app { max-width: 560px; margin: 0 auto; }
button { font-family: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ── шапка ── */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--on-accent);
}
.logo svg { width: 18px; height: 18px; }
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.1; }
.brand-sub { color: var(--hint); font-size: 12px; margin-top: 2px; }
.who { color: var(--hint); font-size: 12px; text-align: right; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#screen { padding: 18px 16px 8px; }
h1 { font-size: 24px; line-height: 1.15; letter-spacing: -.015em; margin: 0 0 4px; font-weight: 750; }
h2 { font-size: 17px; letter-spacing: -.01em; margin: 26px 0 10px; font-weight: 700; }
.lead { color: var(--hint); font-size: 14px; margin: 0 0 18px; }
.hint { color: var(--hint); font-size: 13px; line-height: 1.4; margin: 0 0 12px; }
.muted { color: var(--hint); font-size: 13px; }
.hidden { display: none !important; }

/* ── форма ── */
.block { margin: 0 0 22px; }
.block-title { font-size: 13px; font-weight: 650; color: var(--hint); margin: 0 0 8px 2px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; }
.field:last-child { margin-bottom: 0; }
.field > span, .label { font-size: 13px; font-weight: 600; color: var(--hint); }
.label { display: block; margin: 0 0 8px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line-strong); background: var(--bg); color: var(--text);
  border-radius: var(--r-md); padding: 12px 13px; font-size: 16px; font-family: inherit; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { min-height: 84px; resize: vertical; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--hint) 75%, transparent); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--bg); border-radius: 999px; padding: 9px 14px;
  font-size: 15px; line-height: 1.2; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.chip.soft { background: var(--bg2); border-color: transparent; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 14px; }
.suggest:empty { display: none; }

.amount-wrap { position: relative; }
.amount-wrap input { font-size: 30px; font-weight: 750; letter-spacing: -.02em; padding: 12px 44px 12px 14px; font-variant-numeric: tabular-nums; }
.amount-wrap::after { content: "₽"; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 24px; color: var(--hint); font-weight: 600; }

.shots-edit { display: flex; gap: 8px; flex-wrap: wrap; }
.add-photo {
  width: 84px; height: 84px; border-radius: var(--r-md); border: 1.5px dashed var(--line-strong); background: var(--bg);
  display: grid; place-items: center; color: var(--hint); cursor: pointer; padding: 0;
}
.add-photo svg { width: 26px; height: 26px; }
.thumb { position: relative; width: 84px; height: 84px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--r-md); border: 1px solid var(--line); display: block; }
.thumb button {
  position: absolute; top: -7px; right: -7px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--bg);
  background: var(--text); color: var(--bg); font-size: 14px; line-height: 1; padding: 0; cursor: pointer;
}
.counter { text-align: right; font-size: 12px; color: var(--hint); margin-top: 4px; }

.submit-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px)); z-index: 6;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
.submit-inner { max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.submit-sum { min-width: 0; flex: none; }
.submit-sum small { display: block; color: var(--hint); font-size: 12px; }
.submit-sum b { font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.submit-inner .primary { flex: 1; }

/* ── кнопки ── */
.primary, .ghost, .danger, .quiet {
  border: 0; border-radius: var(--r-md); padding: 13px 16px; font-size: 16px; font-weight: 650; width: 100%; cursor: pointer;
}
.primary { background: var(--accent); color: var(--on-accent); }
.primary:disabled { opacity: .55; }
.ghost { background: var(--bg2); }
.danger { background: color-mix(in srgb, var(--danger) 14%, var(--bg)); color: var(--danger); }
.quiet { background: transparent; color: var(--accent); padding: 10px 6px; width: auto; font-weight: 600; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.actions > * { flex: 1 1 auto; width: auto; }
.actions .wide { flex-basis: 100%; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0 0 6px; }

/* ── карточка заявки ── */
.req {
  --c: var(--hint);
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 14px 16px 14px 20px; margin: 0 0 12px; overflow: hidden;
}
.req::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.req[data-status="pending"] { --c: var(--s-pending); }
.req[data-status="approved"] { --c: var(--s-approved); }
.req[data-status="returned"] { --c: var(--s-returned); }
.req[data-status="rejected"] { --c: var(--s-rejected); }
.req[data-status="withdrawn"] { --c: var(--hint); }
.stat[data-s="withdrawn"] { --c: var(--hint); }
.req[data-status="done"] { --c: var(--s-done); }
.req.clickable { cursor: pointer; }
.req-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; color: var(--c); }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.req-no { color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }
.req-amount { font-size: 30px; line-height: 1.1; font-weight: 800; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.req-driver { font-size: 16px; font-weight: 600; margin-top: 4px; }
.req-car { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.plate {
  display: inline-block; font-weight: 700; font-size: 14px; letter-spacing: .06em; padding: 2px 9px; border-radius: 6px;
  background: #fbfbf6; color: #1b1f24; border: 1.5px solid #1b1f24; font-variant-numeric: tabular-nums;
}
.req-where { color: var(--hint); font-size: 13px; margin-top: 8px; }
.req-where b { color: var(--text); font-weight: 600; }
.req-foot { color: var(--hint); font-size: 12px; margin-top: 8px; }
.note { margin-top: 10px; padding: 8px 11px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--bg) 70%, transparent); border-left: 3px solid var(--line-strong); font-size: 14px; }
.note small { display: block; color: var(--hint); font-size: 12px; margin-bottom: 1px; }
.note.warn { border-left-color: var(--s-returned); }
.note.bad { border-left-color: var(--s-rejected); }
.note.ok { border-left-color: var(--s-done); }
.shots { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.shots img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); }
.reply-box { margin-top: 12px; }

/* ── диалог ── */
.thread { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.bubble { max-width: 86%; padding: 9px 13px; border-radius: 16px 16px 16px 5px; background: var(--bg2); white-space: pre-wrap; word-break: break-word; }
.bubble.mine { margin-left: auto; border-radius: 16px 16px 5px 16px; background: var(--accent); color: var(--on-accent); }
.bubble .who-line { font-size: 12px; opacity: .72; margin-bottom: 2px; }
.empty-thread { text-align: center; color: var(--hint); font-size: 14px; padding: 26px 20px; }
.composer {
  position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 8px); display: flex; gap: 8px; align-items: center;
  background: var(--bg); padding: 8px 0; border-top: 1px solid var(--line);
}
.composer input { flex: 1; border-radius: 999px; }
.composer .primary { width: 46px; height: 46px; padding: 0; border-radius: 50%; flex: none; display: grid; place-items: center; }
.composer .primary svg { width: 20px; height: 20px; }
.timeline { margin: 0; padding: 0; list-style: none; border-left: 2px solid var(--line-strong); }
.timeline li { position: relative; padding: 0 0 14px 16px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.timeline b { font-size: 15px; }
.timeline .muted { font-size: 12px; }

/* ── отчёты ── */
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 12px; padding-inline: 16px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg .chip { white-space: nowrap; flex: none; }
.filters { margin: 0 0 14px; }
.filters summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: 4px 0 10px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 0 0 6px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; }
.stat small { display: block; color: var(--hint); font-size: 12px; }
.stat b { font-size: 22px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat.wide { grid-column: 1 / -1; }
.stat.wide b { font-size: 30px; font-weight: 800; }
.stat[data-s] b { color: var(--c); }
.stat[data-s="pending"] { --c: var(--s-pending); }
.stat[data-s="done"] { --c: var(--s-done); }
.stat[data-s="returned"] { --c: var(--s-returned); }
.stat[data-s="rejected"] { --c: var(--s-rejected); }
.bar-row { margin: 0 0 12px; }
.bar-top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.bar-top span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.bar-track { height: 6px; background: var(--bg2); border-radius: 99px; margin-top: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.wait { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.wait:last-child { border-bottom: 0; }
.wait b { display: block; font-size: 15px; }
.wait .age { text-align: right; font-size: 13px; color: var(--s-pending); font-weight: 650; white-space: nowrap; }

/* ── нижняя навигация ── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar-inner { display: flex; gap: 2px; width: 100%; max-width: 560px; }
.tabbar button {
  position: relative; flex: 1; min-width: 0; background: transparent; border: 0; border-radius: var(--r-md);
  padding: 6px 2px 5px; font-size: 11px; line-height: 1.15; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar .count.info { background: var(--hint); }
.tabbar-inner.many { gap: 0; }
.tabbar-inner.many button { font-size: 10px; letter-spacing: -.02em; padding-left: 0; padding-right: 0; }
.req-decided {
  margin-top: 10px; padding: 7px 10px; border-radius: var(--r-md); font-size: 14px; line-height: 1.25;
  color: var(--c-dec); background: color-mix(in srgb, var(--c-dec) 14%, var(--bg)); border: 1px solid color-mix(in srgb, var(--c-dec) 45%, transparent);
}
.req-decided b { font-weight: 750; color: var(--text); }
.req-decided.ok { --c-dec: var(--s-approved); }
.req-decided.bad { --c-dec: var(--s-rejected); }
.req-decided.wait { --c-dec: var(--accent); display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; }
.req-decided.wait .lbl { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.req-decided.wait b { font-size: 17px; font-weight: 750; overflow-wrap: anywhere; }
.req-done { margin-top: 8px; font-size: 13px; color: var(--s-done, var(--hint)); font-weight: 600; }
#doneMore { margin: 4px 0 12px; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 650; }
.tabbar .count {
  position: absolute; top: 1px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 99px;
  background: var(--s-rejected); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; font-variant-numeric: tabular-nums;
}

/* ── окно ввода ── */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: rgba(8, 12, 20, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  animation: rise .22s ease-out;
}
.sheet h3 { margin: 0 0 6px; font-size: 19px; letter-spacing: -.01em; }
.sheet p { margin: 0 0 14px; color: var(--hint); font-size: 14px; }
.sheet .list { margin: 0 0 14px; }
.sheet .actions { margin-top: 12px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--bar-h) + env(safe-area-inset-bottom, 0px) + 12px); transform: translateX(-50%);
  z-index: 30; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast.bad { background: var(--s-rejected); color: #fff; }

/* ── пустые и загрузка ── */
.empty { text-align: center; padding: 44px 24px; }
.empty .big { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.empty b { display: block; font-size: 18px; margin-bottom: 4px; }
.empty p { margin: 0 0 16px; color: var(--hint); font-size: 14px; }
.empty .primary { width: auto; padding-inline: 22px; }
.skel { height: 148px; border-radius: var(--r-lg); background: linear-gradient(100deg, var(--bg2) 30%, color-mix(in srgb, var(--bg2) 55%, var(--bg)) 50%, var(--bg2) 70%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; margin: 0 0 12px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.done-screen { text-align: center; padding: 28px 8px 8px; }
.done-mark { width: 64px; height: 64px; border-radius: 50%; background: color-mix(in srgb, var(--s-done) 16%, var(--bg)); color: var(--s-done); display: grid; place-items: center; margin: 0 auto 14px; }
.done-mark svg { width: 34px; height: 34px; }
.done-screen .req { text-align: left; margin-top: 18px; }

.lightbox { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .86); }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .skel { animation: none; }
}

/* v1.7: отмена выполненной заявки */
.req[data-status="cancel_pending"], .req[data-status="cancel_approved"], .req[data-status="cancelled"] { --c: var(--s-rejected); }
.cancel-tag { background: var(--s-rejected); color: #fff; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 2px 7px; border-radius: 6px; margin-right: 2px; }
.req[data-status^="cancel"] .badge::before { display: none; }
.req-cancel { margin-top: 10px; padding: 9px 12px; border-radius: var(--r-md); font-size: 14px; line-height: 1.3;
  background: color-mix(in srgb, var(--s-rejected) 12%, var(--bg)); border: 1px solid color-mix(in srgb, var(--s-rejected) 45%, transparent); }
.req-cancel .rc-title { color: var(--s-rejected); font-weight: 750; margin-bottom: 3px; }
.req-cancel .lbl { color: var(--hint); font-size: 12px; }
.req-cancel b { overflow-wrap: anywhere; }
.req-cancel .rc-meta { color: var(--hint); font-size: 12.5px; margin-top: 2px; }
.req-cancel .rc-meta b { color: var(--text); }
.req-cancel.refused { background: color-mix(in srgb, var(--hint) 10%, var(--bg)); border-color: var(--line-strong); }
.req-cancel.refused .rc-title { color: var(--hint); }
.req[data-status="revoked"], .req[data-status="revoked_proc"] { --c: var(--s-rejected); }
#doneQ { margin: 4px 0 10px; }
