/* Цвета берутся из темы Telegram (--tg-theme-*), с запасными значениями для браузера */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2a7de1);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --warn: #f59e0b;
  --ok: #22a06b;
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 76px;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- шапка ---------- */
.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px 6px;
}
.hello { font-weight: 700; font-size: 18px; }
.role { color: var(--hint); font-size: 13px; }
.stats { display: flex; gap: 6px; }
.stat {
  background: var(--card); border-radius: 10px; padding: 4px 9px; text-align: center; min-width: 48px;
}
.stat b { display: block; font-size: 16px; }
.stat small { color: var(--hint); font-size: 11px; }
.stat.danger b { color: var(--danger); }

main { padding: 6px 16px 16px; }

/* ---------- сегменты ---------- */
.segments {
  display: flex; background: var(--card); border-radius: 11px; padding: 3px; margin: 6px 0 12px; gap: 2px;
}
.segments button {
  flex: 1; border: 0; background: transparent; padding: 7px 4px; border-radius: 9px; font-size: 14px; color: var(--hint);
}
.segments button.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

/* ---------- карточки ---------- */
.group-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint);
  margin: 16px 4px 6px;
}
.group-title.danger { color: var(--danger); }
.card {
  display: block; width: 100%; text-align: left; border: 0;
  background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px;
  border-left: 4px solid transparent;
}
.card.overdue { border-left-color: var(--danger); }
.card.soon { border-left-color: var(--warn); }
.card.done { opacity: .6; }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-title { font-weight: 600; word-break: break-word; }
.card-meta { color: var(--hint); font-size: 13px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 12px; }

.chip {
  flex-shrink: 0; font-size: 12px; padding: 2px 8px; border-radius: 99px; white-space: nowrap;
  background: color-mix(in srgb, var(--hint) 16%, transparent); color: var(--text);
}
.chip.new { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--link); }
.chip.in_progress, .chip.todo { background: color-mix(in srgb, var(--warn) 20%, transparent); }
.chip.done { background: color-mix(in srgb, var(--ok) 20%, transparent); }
.chip.canceled { text-decoration: line-through; }
.chip.high { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.dl { font-weight: 500; }
.dl.overdue { color: var(--danger); }
.dl.soon { color: var(--warn); }

/* ---------- договоры ---------- */
.search {
  width: 100%; border: 0; border-radius: 11px; padding: 10px 12px; margin: 6px 0 12px;
  background: var(--card); color: var(--text); font: inherit; outline: none;
}
.progress { height: 4px; border-radius: 2px; background: var(--line); margin-top: 10px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 2px; }
.back { border: 0; background: none; color: var(--link); padding: 4px 0; font-size: 15px; }
.contract-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin: 2px 0 4px; }
.contract-head h1 { font-size: 21px; margin: 0 0 2px; word-break: break-word; }
.contract-head .sub { color: var(--hint); font-size: 14px; white-space: pre-wrap; }
.icon-btn { border: 0; background: var(--card); border-radius: 10px; width: 38px; height: 38px; font-size: 17px; flex-shrink: 0; }
label.field small { font-size: 12px; }

.empty { text-align: center; color: var(--hint); padding: 48px 12px; }
.empty div { font-size: 40px; margin-bottom: 6px; }

/* ---------- нижняя навигация ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center;
  font-size: 12px; color: var(--hint); position: relative; padding: 2px 0;
}
.tabs button span { font-size: 20px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs button.active span { filter: none; opacity: 1; }
.badge {
  position: absolute; top: -2px; left: 50%; margin-left: 6px; font-style: normal;
  background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px; padding: 0 5px;
}
.badge.warn { background: var(--danger); color: #fff; }
.badge:empty { display: none; }

.fab {
  position: fixed; right: 18px; bottom: 82px; width: 54px; height: 54px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}

/* ---------- нижний лист (детали / формы) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 90vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { margin: 4px 0 12px; font-size: 19px; word-break: break-word; }
.rows { background: var(--card); border-radius: var(--radius); padding: 2px 14px; margin-bottom: 12px; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row span:first-child { color: var(--hint); }
.row span:last-child { text-align: right; word-break: break-word; }
.desc { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; white-space: pre-wrap; word-break: break-word; }

.actions { display: flex; flex-direction: column; gap: 8px; }
.btn {
  border: 0; border-radius: 12px; padding: 13px; font-weight: 600; width: 100%;
  background: var(--accent); color: var(--accent-text);
}
.btn.secondary { background: var(--card); color: var(--link); }
.btn.danger { background: var(--card); color: var(--danger); }
.btn:disabled { opacity: .5; }

/* ---------- формы ---------- */
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 4px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px;
  background: var(--card); color: var(--text); font: inherit; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { min-height: 80px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 20;
  background: rgba(20,20,20,.88); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px);
}

/* ---------- ленты вкладок: договоры / изготовители ---------- */
.chip-tabs {
  display: flex; gap: 6px; overflow-x: auto; margin: 6px -16px 10px; padding: 2px 16px 4px;
  scrollbar-width: none;
}
.chip-tabs::-webkit-scrollbar { display: none; }
.chip-tabs button {
  flex-shrink: 0; border: 0; background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 99px; font-size: 15px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip-tabs button.active { background: var(--accent); color: var(--accent-text); }
.chip-tabs button i {
  font-style: normal; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; line-height: 18px;
  border-radius: 9px; padding: 0 5px; background: var(--warn); color: #fff; text-align: center;
}
.chip-tabs button.add { background: transparent; color: var(--link); border: 1.5px dashed var(--line); }

.summary {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  color: var(--hint); font-size: 14px; margin: 0 4px 10px;
}
.summary b { color: var(--text); }
.summary .sub { margin-bottom: 2px; }

.due { font-size: 13px; font-weight: 600; margin-top: 4px; }
.due.overdue { color: var(--danger); }
.due.soon { color: var(--warn); }
.tag {
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text);
  border-radius: 6px; padding: 0 6px;
}
.stat.warn b { color: var(--warn); }
small.ok { color: var(--ok); }
small.hint { color: var(--hint); }

/* ---------- выбор из вариантов ---------- */
.picker { display: flex; flex-wrap: wrap; gap: 6px; }
.pick {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 11px; font-size: 14px;
}
.pick.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--card)); font-weight: 600; }
.pick-input { margin-top: 6px; }
.hint-line { color: var(--hint); font-size: 12px; margin: -4px 4px 10px; }

/* ---------- метал ---------- */
.metal-list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.metal-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.metal-row:last-child { border-bottom: 0; }
.metal-row.received .card-title { color: var(--hint); }
.metal-info { flex: 1; min-width: 0; cursor: pointer; }
.check {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--line);
  background: transparent; color: #fff; font-size: 18px; font-weight: 700; line-height: 1;
}
.metal-row.received .check { background: var(--ok); border-color: var(--ok); }
.metal-form { margin-top: 18px; }
.row span.ok { color: var(--ok); font-weight: 600; }

/* ---------- персонал ---------- */
.tabs button[hidden] { display: none; }
.tabs .icon-tab { flex: 0 0 64px; justify-content: center; }
.tabs .icon-tab span { font-size: 24px; }
.staff-list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 4px; }
.staff-row { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left;
  padding: 11px 14px; border-bottom: 1px solid var(--line); }
.staff-row:last-child { border-bottom: 0; }
.staff-row .who { flex: 1; min-width: 0; }
.staff-row .who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.staff-row .who small { color: var(--hint); font-size: 13px; }
.staff-row .due-sum { font-size: 13px; color: var(--warn); font-weight: 600; white-space: nowrap; }
.quick { display: flex; gap: 6px; padding: 0 14px 12px; border-bottom: 1px solid var(--line); }
.quick button { flex: 1; border: 0; border-radius: 9px; padding: 8px 4px; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 14%, var(--card)); color: var(--link); }
.quick button.no { background: color-mix(in srgb, var(--danger) 12%, var(--card)); color: var(--danger); flex: 0 0 44px; }
.money-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.money-grid div { background: var(--card); border-radius: 12px; padding: 10px 8px; text-align: center; }
.money-grid small { display: block; color: var(--hint); font-size: 12px; }
.money-grid b { font-size: 14px; word-break: break-word; }
.money-grid .due b { color: var(--warn); }
.pay-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pay-row .x { border: 0; background: none; color: var(--danger); font-size: 18px; padding: 0 4px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 14px 4px 6px; }
/* ---------- файлы заказа ---------- */
.files { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.file-row { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.file-row:last-child { border-bottom: 0; }
.file-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; border: 0; background: none;
  text-align: left; padding: 11px 14px; color: var(--link); }
.file-open span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-open small { color: var(--hint); flex-shrink: 0; }
.file-row .x { border: 0; background: none; color: var(--danger); font-size: 18px; padding: 0 14px; }
.warn-line { color: var(--warn); font-weight: 600; margin-top: 4px; }
.check-line { display: block; background: var(--card); border-radius: 11px; padding: 11px 12px; margin-bottom: 10px; font-weight: 600; }
.check-line input { width: 18px; height: 18px; vertical-align: -3px; margin-right: 6px; }
.check-line small { display: block; font-weight: 400; color: var(--hint); font-size: 12px; margin-top: 4px; }
/* ---------- 5 вкладок внизу ---------- */
.tabs button { font-size: 11px; min-width: 0; }
.tabs button span { font-size: 19px; }
.tabs .icon-tab { flex: 0 0 52px; }

/* ---------- метка договора в карточках ---------- */
.tag.contract { background: color-mix(in srgb, var(--hint) 16%, transparent); font-weight: 600; }

/* ---------- бетон ---------- */
.concrete-obj { border-bottom: 1px solid var(--line); padding: 10px 14px; }
.concrete-obj:last-child { border-bottom: 0; }
.concrete-obj .metal-info { margin-bottom: 4px; }
.concrete-obj .vol { white-space: nowrap; font-size: 15px; }
.delivery { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.metal-list > .delivery { padding: 9px 14px; border-bottom: 1px solid var(--line); }
.metal-list > .delivery:last-child { border-bottom: 0; }
.delivery span { flex: 1; min-width: 0; color: var(--hint); }
.delivery b { white-space: nowrap; }
.delivery .check { width: 26px; height: 26px; font-size: 15px; }
.delivery.received .check { background: var(--ok); border-color: var(--ok); }
.delivery .x { border: 0; background: none; color: var(--danger); font-size: 18px; padding: 0 2px; }
/* ---------- счётчики сроков в шапке — кнопки ---------- */
button.stat { border: 0; font: inherit; color: inherit; cursor: pointer; }
button.stat:active { opacity: .7; }

/* ---------- выбор объекта с поиском ---------- */
.obj-q { margin: 0 0 6px; border: 1px solid var(--line); }
.obj-list { background: var(--card); border-radius: 11px; max-height: 240px; overflow-y: auto; border: 1px solid var(--line); }
.obj-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.obj-item:last-child { border-bottom: 0; }
.obj-item b { display: block; font-weight: 600; font-size: 14px; }
.obj-item small { color: var(--hint); font-size: 12px; }
.obj-list .hint-line { margin: 8px 12px; }
.obj-chosen { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--card);
  border: 1.5px solid var(--accent); border-radius: 11px; padding: 10px 12px; }
.obj-chosen .card-meta { margin-top: 4px; }