:root {
  --bg: #0f1117;
  --bg-elevated: #161b26;
  --bg-card: #1a1f2e;
  --bg-input: #12151f;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-soft: rgba(88, 101, 242, 0.12);
  --text: #f2f3f5;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --border: #2e3340;
  --border-focus: #5865f2;
  --ok: #3ba55d;
  --ok-soft: rgba(59, 165, 93, 0.15);
  --warn: #fee75c;
  --danger: #ed4245;
  --danger-soft: rgba(237, 66, 69, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* Hero */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  font-weight: 700;
  line-height: 1.25;
}

.hero-sub {
  margin: 0;
  max-width: 36rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.tech-details {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
}
.tech-details summary { cursor: pointer; }
.tech-details span { display: block; margin-top: 0.25rem; }

/* Steps */
.steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  flex: 1;
  justify-content: center;
}

.step-num {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.step.is-active { color: var(--text); }
.step.is-active .step-num {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.step.is-done { color: var(--ok); }
.step.is-done .step-num {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.step-line {
  flex: 0 0 2rem;
  height: 1px;
  background: var(--border);
  max-width: 3rem;
}

@media (max-width: 520px) {
  .step-label { display: none; }
  .step-line { flex: 0 0 0.75rem; }
}

/* Layout */
.layout {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr 380px;
    align-items: start;
  }
  .side-col {
    position: sticky;
    top: 1rem;
  }
}

.main-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.15rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(88, 101, 242, 0.08) 0%, transparent 100%);
}

.card-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.card-hint {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.card-hint strong { color: var(--text); }

/* Tabs */
.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.75rem 1rem 0;
}

.tab {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); border-color: var(--text-dim); }
.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab-panel { padding: 1rem 1.15rem; }
.tab-panel.hidden { display: none; }

/* Voice */
.voice-box { text-align: center; }

.mic-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  max-width: 220px;
  margin: 0 auto 1rem;
  padding: 1.25rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.mic-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.mic-btn.recording {
  border-color: var(--danger);
  background: var(--danger-soft);
  animation: pulse 1.5s ease infinite;
}
.mic-icon { width: 2.5rem; height: 2.5rem; color: var(--accent); }
.mic-btn.recording .mic-icon { color: var(--danger); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(237, 66, 69, 0.35); }
  50% { box-shadow: 0 0 0 12px rgba(237, 66, 69, 0); }
}

.voice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.status-line {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.status-line.ok { color: var(--ok); }
.status-line.recording { color: var(--warn); }
.status-line.warn { color: var(--warn); }

.mic-btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.mic-hint {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.audio-player {
  width: 100%;
  margin-top: 0.75rem;
  border-radius: var(--radius-sm);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--bg-input); }

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-lg { width: 100%; padding: 0.95rem 1.25rem; font-size: 1rem; }
.btn-file { cursor: pointer; }
.btn-file input { display: none; }

.submit-hint {
  margin: -0.35rem 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Text field */
.field-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

textarea {
  width: 100%;
  min-height: 110px;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea::placeholder { color: var(--text-dim); }
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.help-details {
  margin: 0 1.15rem 1rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.help-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
}
.help-details[open] summary { margin-bottom: 0.5rem; color: var(--text); }
.help-order {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.help-list {
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.help-list li { margin-bottom: 0.45rem; }
.help-list--example .help-li-title {
  color: var(--accent);
  font-weight: 600;
}
.help-list em {
  font-style: normal;
  color: var(--warn);
  font-size: 0.78rem;
}
.example-label {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.example-text {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Drop zone */
.drop-zone {
  margin: 1rem 1.15rem;
  padding: 2rem 1.25rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: var(--text-muted);
}
.drop-zone:hover,
.drop-zone:focus,
.drop-zone.dragover {
  outline: none;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.drop-zone:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.upload-icon {
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.drop-title { margin: 0; font-weight: 600; color: var(--text); }
.drop-sub { margin: 0.2rem 0 0; font-size: 0.85rem; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.6rem;
  padding: 0 1.15rem 1rem;
}
.photo-grid.hidden { display: none; }

.photo-thumb {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-thumb .remove-photo {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.photo-thumb .remove-photo:hover { background: var(--danger); }

.photo-count {
  margin: 0 0 1rem;
  padding: 0 1.15rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ok);
}
.photo-count.hidden { display: none; }

/* Readiness checklist */
.readiness {
  padding: 0.85rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.readiness-title {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.checklist {
  margin: 0;
  padding: 0;
  list-style: none;
}
.check-item {
  padding: 0.35rem 0 0.35rem 1.5rem;
  position: relative;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.check-item::before {
  content: "○";
  position: absolute;
  left: 0;
  color: var(--text-dim);
}
.check-item.is-ok { color: var(--ok); }
.check-item.is-ok::before { content: "✓"; color: var(--ok); }
.check-item.is-bad::before { content: "!"; color: var(--warn); }

/* Results */
.banner {
  margin: 0 1rem 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
}
.banner.ok {
  background: var(--ok-soft);
  border: 1px solid var(--ok);
  color: #b8e0c8;
}
.banner.err {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: #f5b5b6;
}

.result-gallery {
  padding: 0.75rem 1rem 1rem;
  min-height: 160px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  color: var(--text-dim);
  text-align: center;
}
.empty-state svg {
  width: 3rem;
  height: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}
.empty-state p { margin: 0; font-size: 0.9rem; }

.result-gallery.has-items .empty-state { display: none; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.65rem;
}

.wall-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-input);
}
.wall-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}
.wall-card .caption {
  padding: 0.5rem 0.6rem;
  font-size: 0.78rem;
}
.wall-card .caption strong {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--text);
}
.wall-card.no-defect .caption strong { color: var(--ok); }

.transcript {
  margin: 0 1rem 1rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.transcript-label {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
}
.transcript-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Downloads */
.download-body {
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.empty-download {
  margin: 0;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-dim);
  padding: 1rem 0;
}

.download-body.has-files .empty-download { display: none; }

.download-btn {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.download-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.download-btn .dl-icon { font-size: 1.5rem; }
.download-btn strong { display: block; font-size: 0.95rem; }
.download-btn small { color: var(--text-muted); font-size: 0.8rem; }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 17, 23, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.overlay-card {
  text-align: center;
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 320px;
}
.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-title { margin: 0 0 0.35rem; font-weight: 600; }
.overlay-text { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.overlay-hint { margin: 0.5rem 0 0; font-size: 0.8rem; color: var(--text-dim); }

.hidden { display: none !important; }

/* --- Мобильные браузеры (iOS Safari, Chrome Android) --- */
html {
  -webkit-text-size-adjust: 100%;
}

@media (max-width: 899px) {
  .page {
    padding: 1rem max(1rem, env(safe-area-inset-right)) calc(1.25rem + env(safe-area-inset-bottom));
    padding-left: max(1rem, env(safe-area-inset-left));
  }

  .hero {
    flex-direction: column;
    margin-bottom: 1rem;
  }

  .tech-details {
    width: 100%;
  }

  .steps {
    padding: 0.65rem 0.5rem;
  }

  .card-header,
  .tab-panel,
  .drop-zone {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .drop-zone {
    margin-left: 1rem;
    margin-right: 1rem;
    padding: 1.25rem 0.75rem;
  }

  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* iOS не зумит поле, если font-size >= 16px */
  textarea,
  input[type="text"],
  input[type="search"] {
    font-size: 16px;
  }

  .tab,
  .btn,
  .mic-btn,
  .download-btn {
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  .mic-btn {
    max-width: none;
    width: 100%;
  }

  .voice-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .voice-actions .btn,
  .voice-actions .btn-file {
    width: 100%;
    justify-content: center;
  }

  .photo-thumb .remove-photo {
    width: 32px;
    height: 32px;
    font-size: 1.25rem;
    top: 6px;
    right: 6px;
  }

  /* Кнопка «Сформировать акт» — липкая внизу экрана */
  .btn-submit.btn-lg {
    position: sticky;
    bottom: calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 40;
    margin-bottom: 0.25rem;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
  }

  .submit-hint {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .side-col {
    margin-top: 0.5rem;
  }

  .result-gallery {
    min-height: 120px;
  }

  .overlay-card {
    margin: 1rem;
    max-width: calc(100% - 2rem);
  }
}

@media (max-width: 380px) {
  .help-list--example {
    font-size: 0.8rem;
  }

  .example-text {
    font-size: 0.82rem;
    word-break: break-word;
  }
}
