/* Цвета берутся из темы Telegram (--tg-theme-*), запасные — для браузера. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #14171c);
  --muted: var(--tg-theme-hint-color, #7d8592);
  --accent: var(--tg-theme-button-color, #2f7cf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7cf6);
  --section-head: var(--tg-theme-section-header-text-color, var(--muted));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --steel: color-mix(in srgb, var(--text) 72%, var(--accent));
  --ok: #2fa35a;
  --warn: #e08a00;
  --radius: 14px;
  --safe-top: max(var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top, 0px));
  --safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  --safe-left: max(var(--tg-safe-area-inset-left, 0px), env(safe-area-inset-left, 0px));
  --safe-right: max(var(--tg-safe-area-inset-right, 0px), env(safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #101317; --card: #1b1f25; --text: #eef1f5; --muted: #8b93a1; --accent: #4c8dff; --link: #6aa2ff;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: var(--tg-viewport-height, 100vh);
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  max-width: 980px; margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 14px) calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 14px);
}

/* шапка */
.top { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 36px; height: 36px; flex: none; }
.logo-bg { fill: var(--accent); }
.logo-line { fill: none; stroke: var(--accent-text); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-sub { color: var(--muted); font-size: 12.5px; }
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--line); border-radius: 11px; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--muted); display: inline-flex; justify-content: center; gap: 6px; align-items: center;
}
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.count { background: var(--accent); color: var(--accent-text); border-radius: 10px; font-size: 11px; padding: 1px 7px; }

/* раскладка: телефон — столбец, широкое окно — форма + закреплённый разрез */
.layout { display: grid; gap: 12px; }
@media (min-width: 760px) {
  .app { padding-top: calc(var(--safe-top) + 20px); }
  .top { flex-direction: row; align-items: center; justify-content: space-between; }
  .tabs { width: 340px; }
  .layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 16px; }
  .preview { position: sticky; top: 16px; order: 2; }
  .form { order: 1; }
}

.card, .block { background: var(--card); border-radius: var(--radius); }
.block { padding: 14px 14px 6px; margin-bottom: 12px; }
.block h2 {
  margin: 0 0 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--section-head);
}

/* разрез */
.preview { padding: 12px; overflow: hidden; }
.section { width: 100%; height: auto; display: block; }
.section .ground { stroke: var(--muted); stroke-width: 1; }
.section .hatch { stroke: var(--line); stroke-width: 1; }
.section .col { stroke: var(--steel); stroke-width: 3; stroke-linecap: square; }
.section .truss { stroke: var(--accent); stroke-width: 1.6; fill: none; stroke-linejoin: round; }
.section .slab { stroke: var(--steel); stroke-width: 2.2; }
.section .crane { stroke: var(--warn); stroke-width: 2; fill: none; }
.section .dim { stroke: var(--muted); stroke-width: .8; }
.section text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.section .draw { stroke-dasharray: 600; stroke-dashoffset: 0; transition: stroke-dashoffset .5s ease; }
.preview-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.fact { background: var(--bg); border-radius: 10px; padding: 8px; text-align: center; min-width: 0; }
.fact span { display: block; font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.fact small { color: var(--muted); font-size: 11px; }

/* типы зданий */
.types { display: grid; gap: 8px; grid-template-columns: repeat(3, 1fr); margin-bottom: 8px; }
.type {
  border: 1.5px solid var(--line); background: transparent; border-radius: 12px; padding: 10px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 12.5px; line-height: 1.2;
  transition: border-color .15s, background .15s;
}
.type .ico { font-size: 24px; }
.type.on { border-color: var(--accent); background: var(--soft); font-weight: 600; }
.option { display: flex; align-items: center; gap: 10px; margin: 12px 0 2px; font-weight: 600; cursor: pointer; }
.option input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }

/* поля */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); font-weight: 400; }
.req { color: var(--danger); }
input:not([type=range]):not([type=checkbox]), select, textarea {
  width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 11px;
  padding: 11px 12px; font-size: 16px; /* 16px — iOS не увеличивает страницу при вводе */
  outline: none; transition: border-color .15s; -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 32px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.hint { margin: -4px 0 10px; color: var(--muted); font-size: 12.5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1.5px solid var(--line); background: transparent; border-radius: 20px; padding: 7px 14px; cursor: pointer;
  font-weight: 600; font-variant-numeric: tabular-nums; min-width: 56px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.stepper { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 11px; overflow: hidden; background: var(--bg); }
.stepper button { border: 0; background: transparent; width: 44px; height: 42px; font-size: 20px; cursor: pointer; color: var(--accent); flex: none; }
.stepper button:disabled { color: var(--line); cursor: default; }
.stepper output { flex: 1; text-align: center; font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }

.range-row { display: flex; align-items: center; gap: 12px; }
.range-row output { min-width: 48px; text-align: right; font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
input[type=range] { flex: 1; accent-color: var(--accent); height: 28px; }

.note { color: var(--muted); font-size: 12.5px; margin: 4px 4px 12px; }
.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; }

.btn {
  border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 600; cursor: pointer; font-size: 15px;
  background: var(--soft); color: var(--link); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }
.tg-main .fallback { display: none; } /* в Telegram — нижняя кнопка MainButton */

/* список заявок */
.list { display: grid; gap: 10px; }
@media (min-width: 760px) { .list { grid-template-columns: 1fr 1fr; } }
.item { background: var(--card); border-radius: var(--radius); padding: 14px; cursor: pointer; border: 0; text-align: left; width: 100%; }
.item-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.item-title { font-weight: 700; }
.item-sub { color: var(--muted); font-size: 13px; }
.item-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.badge { font-size: 12px; font-weight: 600; border-radius: 8px; padding: 3px 8px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.run { color: var(--link); background: var(--soft); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* карточка заявки */
.detail { display: grid; gap: 12px; max-width: 620px; margin: 0 auto; }
.hero { background: var(--card); border-radius: var(--radius); padding: 22px 16px; text-align: center; }
.hero .big { font-size: 22px; font-weight: 800; margin: 8px 0 2px; letter-spacing: -.01em; }
.hero p { margin: 0; color: var(--muted); }
.check { width: 56px; height: 56px; margin: 0 auto; border-radius: 50%; background: color-mix(in srgb, var(--ok) 15%, transparent); display: grid; place-items: center; }
.check svg { width: 30px; height: 30px; stroke: var(--ok); stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .5s .15s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric { background: var(--card); border-radius: var(--radius); padding: 14px; }
.metric span { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.metric small { color: var(--muted); }
.rows { background: var(--card); border-radius: var(--radius); padding: 4px 14px; }
.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(--muted); }
.row span:last-child { text-align: right; font-weight: 600; }
.progress { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin: 14px auto 0; max-width: 220px; }
.progress::after { content: ""; display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 2px; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* просмотр отчёта: только картинки на canvas, без выделения, меню и перетаскивания */
.viewer {
  position: fixed; inset: 0; z-index: 10; background: #23262b; display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.viewer-bar {
  display: flex; align-items: center; gap: 8px; color: #fff; background: #17191d;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 10px) 8px calc(var(--safe-left) + 10px);
}
.viewer-title { flex: 1; font-weight: 600; text-align: center; font-size: 14px; }
.zoom { display: flex; gap: 4px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: rgba(255,255,255,.1); color: #fff; font-size: 18px; cursor: pointer; }
.viewer-pages {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px calc(var(--safe-bottom) + 16px);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.viewer-pages canvas { display: block; background: #fff; border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,.4); pointer-events: none; }
.viewer-pages .ph { width: 100%; max-width: 900px; aspect-ratio: 210/297; background: #2d3036; border-radius: 4px; }
@media print { body { display: none !important; } }
