:root {
  --bg: #0F1115;
  --card: #1A1D24;
  --bar: #14161C;
  --text: #E6E8EB;
  --sub: #8A9099;
  --accent: #F5A623;
  --green: #2EA05A;
  --blue: #3D84E6;
  --red: #DC4646;
  --line: #2A2E37;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; min-height: 100%; }
body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--bg);
  border-bottom: 1px solid var(--line); padding: 14px 16px 12px; }
header.top h1 { margin: 0; font-size: 22px; }
header.top .sub { color: var(--sub); font-size: 13px; margin-top: 2px; }

.content { padding: 12px; }
.card { background: var(--card); border-radius: var(--radius); padding: 12px;
  display: flex; gap: 12px; margin-bottom: 10px; cursor: pointer; }
.card:active { opacity: .8; }
.thumb { width: 96px; height: 72px; border-radius: 8px; flex: 0 0 96px;
  position: relative; overflow: hidden; }
.thumb::before { content: ""; position: absolute; left: 14px; right: 14px; top: 26px;
  height: 14px; border-radius: 5px; background: rgba(0,0,0,.35); }
.thumb::after { content: ""; position: absolute; left: 10px; right: 10px; top: 40px;
  height: 14px; border-radius: 5px; background: rgba(0,0,0,.25); }
.info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--sub); font-size: 13px; }
.badges { display: flex; gap: 6px; align-items: center; margin-top: auto; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 10px; color: #0F1115; }
.b-inspection { background: var(--blue); color: #fff; }
.b-repair { background: var(--accent); }
.b-ready { background: var(--text); }
.b-overdue { background: var(--red); color: #fff; }
.b-sold { background: var(--green); color: #fff; }
.term { color: var(--sub); font-size: 12px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(72px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--bar);
  border-top: 1px solid var(--line); display: flex; z-index: 10; }
.tab { flex: 1; background: none; border: 0; color: var(--sub); display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600; min-height: 44px; position: relative; }
.tab .ic { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); }
.tab.active::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%;
  height: 2px; background: var(--accent); border-radius: 2px; }

.btn { background: var(--accent); color: #0F1115; border: 0; border-radius: var(--radius);
  padding: 14px; font-size: 16px; font-weight: 700; width: 100%; min-height: 48px; }
.btn.ghost { background: var(--card); color: var(--text); }
.btn.danger { background: var(--red); color: #fff; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { color: var(--sub); font-size: 13px; }
.field input { background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 14px; font-size: 16px; min-height: 48px; }
.field input:focus { outline: none; border-color: var(--accent); }
.err { color: var(--red); font-size: 14px; margin: 8px 0; min-height: 18px; }
.hint { color: var(--sub); font-size: 13px; margin: 6px 0 14px; }

.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 28px; }
.logo { font-size: 36px; font-weight: 800; letter-spacing: 1px; margin-bottom: 4px; }
.logo span { color: var(--accent); }
.dash { width: 56px; height: 4px; background: var(--accent); border-radius: 2px; margin-bottom: 28px; }

.detail-section { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.detail-section h3 { margin: 0 0 10px; font-size: 13px; color: var(--sub); font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; }
.row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.row:last-child { border-bottom: 0; }
.row span:first-child { color: var(--sub); }
.back { background: none; border: 0; color: var(--accent); font-size: 16px; padding: 8px 0; min-height: 44px; }
.plate-hdr { font-size: 22px; font-weight: 700; margin: 6px 0 2px; }
.lock { color: var(--sub); font-size: 13px; }
.list-item { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center; }
.list-item small { color: var(--sub); display: block; margin-top: 2px; }
.logout { margin-top: 18px; }
select.inp { background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 14px; font-size: 16px; min-height: 48px; width: 100%; }
.pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.pcell { background: var(--bar); border-radius: 10px; overflow: hidden; }
.pcell img { width: 100%; height: 120px; object-fit: cover; display: block; background: var(--line); }
.pcap { font-size: 12px; color: var(--sub); padding: 6px 8px; }
.pcell { position: relative; }
.pdel { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border: none; border-radius: 50%;
        background: rgba(0,0,0,0.6); color: #fff; font-size: 14px; line-height: 28px; text-align: center; cursor: pointer; padding: 0; }
.ibtns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.ibtn { width: auto; padding: 8px 12px; min-height: 36px; font-size: 14px; }
.icom { flex: 1; min-width: 160px; }
.grp { font-size: 13px; color: var(--sub); margin: 14px 0 6px; font-weight: 600; }
.ap-over { border-left: 3px solid var(--red); }
.rating .row { font-size: 15px; }
.hrow { padding: 8px 0; border-bottom: 1px solid var(--line); }
.hrow:last-child { border-bottom: 0; }
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 200px); }
.cmsgs { flex: 1; overflow-y: auto; padding: 4px 0 8px; }
.cbar { display: flex; gap: 6px; align-items: center; padding-top: 8px; border-top: 1px solid var(--line); }
.cbar .inp { flex: 1; min-width: 0; }
.cbar .btn { width: auto; padding: 8px 12px; min-height: 40px; }
.cattach { display: inline-flex; align-items: center; justify-content: center; width: 40px; min-height: 40px;
  background: var(--card); color: var(--text); border-radius: var(--radius); font-size: 22px; cursor: pointer; }
.cmsg { display: flex; margin: 6px 0; }
.cmsg.mine { justify-content: flex-end; }
.cbub { max-width: 82%; background: var(--card); border-radius: 12px; padding: 8px 10px; }
.cmsg.mine .cbub { background: var(--bar); }
.cwho { font-size: 12px; color: var(--sub); margin-bottom: 4px; }
.cwho span { margin-left: 6px; }
.ctext { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.cmedia { margin-bottom: 4px; }
.cimg { max-width: 100%; max-height: 260px; border-radius: 8px; display: block; }
.caudio { width: 220px; max-width: 100%; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 12px; }
.kv { font-size: 22px; font-weight: 700; }
.kl { font-size: 12px; color: var(--sub); margin-top: 2px; }
.legend { font-size: 12px; color: var(--sub); display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 8px; }
.dot.insp, .scol.insp { background: var(--sub); }
.dot.sold, .scol.sold { background: var(--accent); }
.chart { display: flex; gap: 6px; align-items: flex-end; height: 160px; }
.sbar { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.scols { flex: 1; width: 100%; display: flex; gap: 2px; align-items: flex-end; justify-content: center; }
.scol { width: 40%; min-height: 0; border-radius: 3px 3px 0 0; }
.slabel { font-size: 11px; color: var(--sub); margin-top: 4px; }

/* ---- крупные поля и кнопки для пальцев ---- */
input:not([type=checkbox]):not([type=radio]):not([type=file]),
select, textarea, .inp {
  min-height: 48px; font-size: 17px; padding: 12px 14px; box-sizing: border-box;
}
textarea { min-height: 96px; }
.btn { min-height: 48px; font-size: 17px; padding: 12px 18px; }
.btn.ibtn { min-height: 44px; font-size: 15px; padding: 10px 14px; }
.ibtns .btn, .ibtns select, .ibtns input { min-height: 44px; }
.cbar .btn, .cattach { min-width: 48px; min-height: 48px; font-size: 20px; }
.cbar .inp { min-height: 48px; }
.field label { font-size: 14px; }
/* ---- сворачиваемые разделы карточки ---- */
.car-view .detail-section > h3 { cursor: pointer; display: flex; justify-content: space-between; align-items: center; user-select: none; }
.car-view .detail-section > h3::after { content: "▾"; font-size: 16px; color: var(--sub); transition: transform .2s; }
.car-view .detail-section.collapsed > h3::after { transform: rotate(-90deg); }
.car-view .detail-section.collapsed > :not(h3) { display: none; }
/* ---- плашки ролей ---- */
.rbadge { font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 12px; white-space: nowrap; color: #0F1115; flex: none; }
.rb-admin { background: #2ECC71; }
.rb-member { background: #F39C12; }
.rb-off { background: #9AA0A6; }
.user-row.is-active { cursor: pointer; }
/* ---- значок непрочитанного в чате ---- */
.tab[data-unread]::after { content: attr(data-unread); position: absolute; top: 6px; left: calc(50% + 8px);
  background: #E74C3C; color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px;
  border-radius: 9px; display: none; align-items: center; justify-content: center; padding: 0 5px; }
.tab[data-unread]:not([data-unread=""])::after { display: flex; }
/* ---- всплывающее уведомление ---- */
.toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -140%); transition: transform .3s;
  background: var(--card); color: var(--text); padding: 12px 18px; border-radius: 12px; z-index: 999;
  box-shadow: 0 6px 24px rgba(0,0,0,.35); font-size: 15px; max-width: 90%; }
.toast.show { transform: translate(-50%, 0); }
/* ---- фото: группы и дефекты ---- */
.pgroup-h { font-size: 13px; color: var(--sub); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.defrow { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--card); border-radius: var(--radius); margin-bottom: 8px; }
/* ---- плашка ответственного ---- */
/* ---- сотрудники ---- */
.tagrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.ttag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); color: var(--sub); }
.car-link, .staff-row { cursor: pointer; }
/* ---- просмотр фото на весь экран ---- */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 12px; box-sizing: border-box; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; user-select: none; }
.viewer-x { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 12px); right: 12px; width: 44px; height: 44px;
  border-radius: 22px; border: none; background: rgba(255,255,255,.18); color: #fff; font-size: 20px; cursor: pointer; }
/* ---- компактная плашка ответственного (в одной строке со статусом) ---- */
.badge.b-owner { background: #3B82F6; color: #fff; }
/* ---- кнопка скачать ---- */
.viewer-dl { position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); left: 50%; transform: translateX(-50%);
  background: #E8A94A; color: #0F1115; font-weight: 700; padding: 12px 22px; border-radius: 12px; text-decoration: none; font-size: 16px; }
.cdl { display: inline-block; margin-top: 6px; font-size: 14px; color: var(--accent, #E8A94A); text-decoration: none; }
/* ---- статус «Архив» ---- */
.badge.b-archived { background: #7F8C8D; color: #fff; }
/* ---- компактные плашки в карточке: ответственный и статус ---- */
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 10px; }
.pill-owner { background: #3B82F6; color: #fff; }
.row .badge { font-size: 12px; padding: 3px 10px; }
/* ---- список машин: дата заведения и кнопка архива ---- */
.added { font-size: 12px; color: var(--sub); margin-top: 6px; }
.archive-btn { margin-top: 16px; }
/* ---- вкладка «Офис» только для админов ---- */
.tab.admin-only { display: none; }
body.is-admin .tab.admin-only { display: flex; }
/* ---- офис: редактирование, удалённые, нейтральная плашка имени ---- */
.nameplate { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 8px; background: #3A4150; color: #E6E9EF; margin: 0 2px; }
.oact { display: flex; gap: 8px; margin-top: 8px; }
.oact .btn { width: auto; padding: 6px 12px; min-height: 32px; font-size: 13px; }
.strike { text-decoration: line-through; color: var(--sub); }
.is-deleted { opacity: .75; }
.deleted-box { margin-top: 14px; }
.deleted-box summary { cursor: pointer; color: var(--sub); padding: 8px 0; }
/* значок «Сотрудники» (SVG) */
.tab .ic svg { display: block; margin: 0 auto; }

/* ---- рейтинг продаж: места 1–3 выделены цветом ---- */
.rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 8px;
  border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.rank-no { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 14px; background: var(--line); color: var(--text); flex: none; }
.rank-main { min-width: 0; flex: 1; }
.rank-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-sub { font-size: 12px; color: var(--sub); margin-top: 2px; }
.rank-row.is-me .rank-name { color: var(--accent); }
.you { font-size: 11px; font-weight: 600; color: var(--sub); margin-left: 4px; }
.place-1 { background: linear-gradient(90deg, rgba(245,184,46,.22), var(--card)); border-color: #F5B82E; }
.place-1 .rank-no { background: #F5B82E; color: #0F1115; }
.place-2 { background: linear-gradient(90deg, rgba(192,199,209,.20), var(--card)); border-color: #C0C7D1; }
.place-2 .rank-no { background: #C0C7D1; color: #0F1115; }
.place-3 { background: linear-gradient(90deg, rgba(205,127,50,.22), var(--card)); border-color: #CD7F32; }
.place-3 .rank-no { background: #CD7F32; color: #0F1115; }
.rank-hint { margin-top: 4px; }

/* ---- список сделок ---- */
.deal-card { display: block; }
.deal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.deal-head .title { font-weight: 700; }
.deal-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.fact { display: flex; flex-direction: column; min-width: 0; }
.fact span { font-size: 11px; color: var(--sub); }
.fact b { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buyer-line { font-size: 12px; color: var(--sub); margin-top: 4px; }
.buyer-line b { color: var(--text); font-weight: 600; }

/* ---- «Ответственный» в списке машин: отдельная выделенная строка ---- */
.owner-tag { display: flex; flex-direction: column; margin: 8px 0 6px; padding: 6px 10px;
  border-left: 3px solid #3B82F6; background: rgba(59,130,246,.12); border-radius: 0 8px 8px 0; }
.owner-label { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: #93C5FD; font-weight: 700; }
.owner-name { font-size: 14px; font-weight: 700; color: var(--text); }

/* ---- ответственный в карточке сделки: небольшая нейтральная плашка ---- */
.deal-owner { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 8px; margin-top: 2px;
  background: #3A4150; color: #E6E9EF; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- кнопка «‹ Назад» вверху слева в подразделах «Ещё» ---- */
.top-back { display: block; background: none; border: 0; color: var(--accent); font-size: 16px;
  padding: 6px 0; min-height: 36px; margin-bottom: 4px; text-align: left; }

/* ---- кнопки «Продано» (зелёная) и «Архив» (приглушённая красная) ---- */
.archive-btn.sold-btn { background: rgba(34,197,94,.16); border-color: rgba(34,197,94,.55); color: #4ADE80; font-weight: 700; }
.archive-btn.archive-red { background: rgba(220,38,38,.10); border-color: rgba(220,38,38,.35); color: #E07A7A; font-weight: 700; }
