:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg-2: var(--tg-theme-secondary-bg-color, #171a21);
  --text: var(--tg-theme-text-color, #f2f4f8);
  --hint: var(--tg-theme-hint-color, #8b93a7);
  --btn: var(--tg-theme-button-color, #4ea1ff);
  --btn-text: var(--tg-theme-button-text-color, #0f1115);
  --danger: var(--tg-theme-destructive-text-color, #ff5c5c);
  --radius: 16px;
  --border: 1px solid rgba(127, 127, 127, .18);

  /* Подсказки (второстепенный серый текст). В тёмной теме --tg-theme-hint-color
     выглядит слишком ярко, поэтому на тёмной теме приглушаем прозрачностью.
     Крутилки: --hint-alpha (серый текст), --placeholder-alpha (плейсхолдеры в полях).
     Атрибут data-scheme ставит app.js по tg.colorScheme, в светлой теме — без приглушения. */
  --hint-alpha: .75;
  --placeholder-alpha: .6;
}

html[data-scheme="light"] {
  --hint-alpha: 1;
  --placeholder-alpha: 1;
}

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

/* КРИТИЧНО: авторское display (flex/grid) перебивает атрибут hidden,
   из-за этого «скрытые» блоки оставались на экране. Правило обязано быть ниже. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 12px 12px calc(28px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#app { display: flex; flex-direction: column; gap: 12px; max-width: 640px; margin: 0 auto; }
#main { display: flex; flex-direction: column; gap: 12px; }

.card { background: var(--bg-2); border-radius: var(--radius); padding: 14px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.muted { color: var(--hint); font-weight: 400; }
.small { font-size: 12px; }
.req { color: var(--danger); }

.banner {
  background: rgba(255, 92, 92, .16);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}

.muted, .hint, .empty, .author, .comment, .expiry, .responded-note, .responders-count,
.stat span, .custom-city summary {
  opacity: var(--hint-alpha, .75);
}

/* плейсхолдеры в полях ввода тоже читались как «яркая подсказка» */
::placeholder { color: var(--hint); opacity: var(--placeholder-alpha, .6); }

/* профиль */
.profile { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 50%;
  background: var(--btn); color: var(--btn-text);
  display: grid; place-items: center; font-weight: 700; font-size: 18px; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.meta { flex: 1; min-width: 0; }
.name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip {
  background: var(--bg); border: var(--border); color: var(--text);
  border-radius: 999px; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:disabled { opacity: .5; cursor: default; }
/* компактная кнопка автогорода — не растягивается на всю ширину */
.geo-btn { width: auto; align-self: flex-start; }

/* отклики под своей заявкой */
.responses { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.responses-title { font-weight: 600; font-size: 13px; }
.responses-empty { font-size: 12px; }
.response-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.response-who { font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-btn {
  flex: 0 0 auto; border: 0; border-radius: 9px; padding: 8px 12px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--btn); color: var(--btn-text);
}
.mini-btn:disabled { opacity: .5; }
.responded-note { font-size: 12px; font-weight: 600; color: var(--hint); }
.responders-count { font-size: 12px; }

/* вкладки */
.tabs { display: flex; gap: 6px; background: var(--bg-2); border-radius: 12px; padding: 4px; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--hint);
  padding: 10px 4px; border-radius: 9px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.tabs button.active { background: var(--btn); color: var(--btn-text); }
/* счётчик откликов, ждущих решения автора (вкладка «Отклики») */
.tab-badge {
  display: inline-grid; place-items: center; vertical-align: middle;
  min-width: 17px; height: 17px; margin-left: 5px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 10.5px; font-weight: 700; line-height: 1;
}
.tabs button.active .tab-badge { background: rgba(0, 0, 0, .22); }

/* ---------- вкладка «Отклики» ---------- */
.response-card.closed { opacity: .8; }
.response-card .response-who { font-weight: 600; }
.closed-note { font-size: 12px; }
.waiting-card { background: var(--bg-2); border: var(--border); gap: 4px; }
.waiting-title { font-weight: 600; font-size: 13px; }
.waiting-row { color: var(--hint); font-size: 12.5px; }

/* переключатели */
.seg { display: flex; gap: 4px; }
.seg button {
  flex: 1; border: var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 9px 6px; font-size: 13px; cursor: pointer; font-weight: 500;
}
.seg button.active { background: var(--btn); color: var(--btn-text); border-color: transparent; font-weight: 600; }
.seg.big button { padding: 12px 8px; font-size: 14px; }
/* активные «Приму»/«Отдам» окрашены так же, как карточки на дашборде */
#type-seg button[data-v="pickup"].active, #filter-type button[data-v="pickup"].active { background: rgba(78, 161, 255, .88); color: #08121f; }
#type-seg button[data-v="handover"].active, #filter-type button[data-v="handover"].active { background: rgba(255, 176, 32, .90); color: #221a05; }
.filters { display: flex; flex-direction: column; gap: 8px; padding: 10px; }

/* статистика */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--bg-2); border-radius: 12px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 20px; line-height: 1.2; }
.stat span { color: var(--hint); font-size: 11px; }

/* список заявок */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--bg-2); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.item.is-mine { border: 1px dashed rgba(127, 127, 127, .45); }
/* разделение по типу: «Приму» — синий, «Отдам» — янтарный */
.item.kind-pickup { background: rgba(78, 161, 255, .10); border-left: 4px solid rgba(78, 161, 255, .75); }
.item.kind-handover { background: rgba(255, 176, 32, .10); border-left: 4px solid rgba(255, 176, 32, .80); }
.item.urgent { background: rgba(190, 60, 60, .18); border-left: 4px solid rgba(255, 92, 92, .80); }
.check { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; padding: 0; accent-color: var(--btn); }
.own-note { font-size: 12px; font-weight: 600; color: var(--btn); }
.item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item-mid { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px; }
.type-pickup { background: rgba(78, 161, 255, .18); color: #4ea1ff; }
.type-handover { background: rgba(255, 176, 32, .18); color: #ffb020; }
.when { font-weight: 600; font-size: 14px; white-space: nowrap; }
.reward { font-size: 13px; font-weight: 600; color: #2ecc71; }
.author { color: var(--hint); font-size: 13px; }
.comment { margin: 0; font-size: 13px; color: var(--hint); word-break: break-word; }

.status { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; }
.s-open { background: rgba(46, 204, 113, .18); color: #2ecc71; }
.s-taken { background: rgba(78, 161, 255, .18); color: #4ea1ff; }
.s-done { background: rgba(139, 147, 167, .18); color: var(--hint); }
.s-cancelled { background: rgba(255, 92, 92, .16); color: var(--danger); }
.s-expired { background: rgba(255, 176, 32, .16); color: #ffb020; }

.actions { display: flex; gap: 8px; }
.actions button {
  flex: 1; border: 0; border-radius: 10px; padding: 11px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  background: var(--btn); color: var(--btn-text);
}
.actions button.ghost-btn { background: var(--bg); color: var(--text); border: var(--border); }
.actions button.danger { background: rgba(255, 92, 92, .16); color: var(--danger); }

.empty { color: var(--hint); text-align: center; font-size: 14px; margin: 12px 0; }

/* форма */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.field .row { flex: 1; }
input, textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: var(--border); border-radius: 12px; padding: 12px; font-size: 15px;
  font-family: inherit; outline: none;
}
input:focus, textarea:focus { border-color: var(--btn); }
textarea { resize: vertical; }
button.ghost-btn {
  width: 100%; background: var(--bg); color: var(--text); border: var(--border);
  border-radius: 12px; padding: 11px; font-size: 14px; font-weight: 600; cursor: pointer;
}

button.primary {
  border: 0; border-radius: 12px; background: var(--btn); color: var(--btn-text);
  padding: 13px; font-size: 15px; font-weight: 700; cursor: pointer;
}
button.primary:disabled { opacity: .5; }

select {
  width: 100%; background: var(--bg); color: var(--text);
  border: var(--border); border-radius: 12px; padding: 12px; font-size: 15px;
  font-family: inherit; outline: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
}
select:focus { border-color: var(--btn); }

.custom-city summary { color: var(--hint); font-size: 13px; cursor: pointer; }
.custom-city form { margin-top: 8px; }

.expiry { color: var(--hint); font-size: 12px; }
.contacts { font-size: 13px; display: flex; flex-direction: column; gap: 4px; color: var(--text); }
.contacts a { color: var(--btn); text-decoration: none; }

/* выбор города */
.gate { display: flex; flex-direction: column; gap: 12px; }
.gate h1 { font-size: 20px; margin: 0; }
.gate-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gate-head .chip { flex: 0 0 auto; }
.gate p { margin: 0; font-size: 13px; }
.cities { display: flex; flex-wrap: wrap; gap: 8px; }
.cities button {
  background: var(--bg); border: var(--border); color: var(--text);
  border-radius: 999px; padding: 10px 14px; font-size: 14px; cursor: pointer;
}
.cities button:hover { border-color: var(--btn); }


/* ---------- ЦФЗ (адрес курьерской точки) ---------- */
/* обязательное поле — акцентная левая полоса, чтобы не сливалось с остальными */
.field.cfz-field { border-left: 4px solid var(--btn); padding-left: 10px; }
.field.cfz-field input { font-weight: 600; }

/* подсказки ЦФЗ — свой список: <datalist> в Telegram на iOS роняет WebView */
.cfz-suggest { display: flex; flex-direction: column; gap: 6px; }
.cfz-suggest button {
  text-align: left; font-size: 14px; padding: 10px 12px; border-radius: 10px;
  background: var(--bg-2); color: var(--text); border: var(--border);
}
.cfz-suggest button:active { border-color: var(--btn); }

/* ЦФЗ в карточке заявки */
.cfz-line { font-size: 13px; font-weight: 600; color: var(--text); }

/* select фильтра по ЦФЗ — в стиле остальных полей */
.filters #filter-cfz { font-size: 14px; padding: 10px 12px; }

/* ---------- «Взять часть»: разделение смены ---------- */
.item-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* приглушённый бейдж части смены */
.badge.part-badge { background: rgba(139, 147, 167, .18); color: var(--hint); }
/* часть смены: пунктирная рамка в цвете типа заявки (правила ниже kind-*, чтобы перебить border-left) */
.item.part-item { border: 2px dashed rgba(127, 127, 127, .45); }
.item.part-item.kind-pickup { border-color: rgba(78, 161, 255, .75); }
.item.part-item.kind-handover { border-color: rgba(255, 176, 32, .80); }
.part-origin, .part-note, .part-split { font-size: 12px; }

.split-box {
  display: flex; flex-direction: column; gap: 8px;
  border: var(--border); border-radius: 12px; padding: 10px;
  background: rgba(127, 127, 127, .06);
}
.split-title { font-weight: 600; font-size: 13px; }
.split-box .row { align-items: flex-end; }
.split-hint { font-size: 12px; }
.split-hint.warn { color: var(--danger); opacity: 1; }
.split-box .actions button { padding: 9px 11px; font-size: 13px; }
