*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --fg: #000000;
  --fg-soft: #555555;
  --muted: #888888;
  --line: #000000;
  --line-soft: #d4d4d4;
  --bg-soft: #f4f4f4;
  --bg-inv: #000000;
  --fg-inv: #ffffff;
  --bubble-me: #000000;
  --bubble-me-fg: #ffffff;
  --bubble-them: #f0f0f0;
  --bubble-them-fg: #000000;
  --radius: 14px;
  --radius-sm: 8px;
  --gap: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --maxw: 420px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Inter", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

body { min-height: 100vh; min-height: 100dvh; }

body.landing-page {
  height: 100dvh;
  overflow: hidden;
}

a { color: var(--fg); }
a:hover { text-decoration: none; }

button { font: inherit; cursor: pointer; }

input, textarea, button {
  font: inherit;
  color: inherit;
}

textarea { resize: none; }

h1, h2, h3 {
  margin: 0 0 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

h1 { font-size: clamp(34px, 9vw, 46px); }
h2 { font-size: clamp(22px, 6vw, 28px); }
h3 { font-size: 17px; }

p { margin: 0 0 12px; }

.muted { color: var(--muted); font-size: 14px; }

.brand {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.app {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(20px + var(--safe-top)) 20px calc(24px + var(--safe-bot));
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.landing-page .app {
  width: 100%;
  max-width: none;
  height: 100dvh;
  min-height: 0;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bot));
  display: grid;
  place-items: center;
  gap: 0;
}

.landing-screen {
  width: min(100%, 640px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
}

.landing-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: 100%;
}

.landing-actions .btn { min-width: 220px; }

.landing-legend {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--fg-soft);
  text-align: left;
  max-width: 360px;
  width: 100%;
}

.landing-legend li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  line-height: 1.4;
}

.legend-key {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg);
}
.legend-key-primary { background: var(--bg-inv); color: var(--fg-inv); border-color: var(--bg-inv); }
.legend-key-ghost { background: transparent; }

.landing-text {
  max-width: 52ch;
  margin: 0;
  color: var(--fg-soft);
  font-size: clamp(17px, 2.5vw, 21px);
  line-height: 1.5;
}
.landing-text + .landing-text { margin-top: 8px; }

/* === HERO === */
.hero {
  padding: 24px 0 8px;
}
.hero-inner { display: flex; flex-direction: column; gap: 16px; }
.hero .brand { color: var(--fg); }
.hero h1 { margin-top: 4px; }
.lead { color: var(--fg-soft); font-size: 16px; max-width: 38ch; }
.hero-meta {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  margin-top: 8px;
}

/* === SERVICES === */
.services h2 { margin-bottom: 16px; }
.cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-svc {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  background: var(--bg);
  position: relative;
}
.card-svc .num {
  position: absolute;
  top: 14px; right: 16px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--muted);
}
.card-svc h3 { margin: 0 0 6px; padding-right: 40px; }
.card-svc p { color: var(--fg-soft); font-size: 14px; margin: 0; }

/* === CTA === */
.cta {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  background: var(--bg);
}
.cta p { color: var(--fg-soft); margin-bottom: 16px; }

/* === FOOTER === */
.footer {
  border-top: 1px solid var(--line-soft);
  padding-top: 18px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
  align-items: center;
}
.footer .contacts a { color: var(--fg); text-decoration: none; border-bottom: 1px solid var(--line); }

/* === BUTTONS === */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  padding: 14px 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  transition: transform .05s ease, background .15s, color .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--bg-inv); color: var(--fg-inv); }
.btn-primary:hover { background: #1a1a1a; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === OVERLAY (sheet) === */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: stretch;
  justify-content: center;
  z-index: 50;
  animation: fadeIn .18s ease;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.sheet {
   width: 100%;
   max-width: var(--maxw);
  background: var(--bg);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
   animation: slideUp .22s cubic-bezier(.2,.8,.2,1);
}
.sheet.sheet-compact {
  align-self: flex-end;
  height: auto;
  max-height: 100dvh;
}
@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-step {
  display: flex;
  flex-direction: column;
  padding: 16px 16px calc(16px + var(--safe-bot));
  gap: 8px;
  height: 100%;
  min-height: 0;
  flex: 1;
}
.sheet-step[hidden] { display: none; }

.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.icon-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  width: 36px; height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  text-align: center;
  color: var(--fg);
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-glyph {
  display: block;
  transform: translateY(-2px);
}

#nameForm, #messageForm, .chat-input {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 0;
}
#nameInput, #messageInput {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 16px;
  outline: none;
}
#nameInput:focus, #messageInput:focus {
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.08);
}
#messageInput { min-height: 88px; }

.err {
  color: var(--fg);
  background: #eee;
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

/* === CHAT === */
.sheet-chat {
  padding: 0;
  gap: 0;
  min-height: 100dvh;
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
.chat-title { flex: 1; min-width: 0; }
.chat-name { font-weight: 700; font-size: 15px; }
.chat-status { font-size: 12px; color: var(--muted); }
.lock {
  font-size: 10px;
  color: var(--fg);
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  line-height: 1;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.msg.me {
  align-self: flex-end;
  background: var(--bubble-me);
  color: var(--bubble-me-fg);
  border-bottom-right-radius: 4px;
}
.msg.them {
  align-self: flex-start;
  background: var(--bubble-them);
  color: var(--bubble-them-fg);
  border-bottom-left-radius: 4px;
}
.msg.me a {
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg.them a {
  color: #000000;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 4px 0;
  max-width: 100%;
}
.msg .time {
  display: block;
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}
.msg-image {
  display: block;
  max-width: min(100%, 360px);
  max-height: 320px;
  border-radius: 10px;
  object-fit: contain;
  cursor: zoom-in;
}
.image-preview {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.86);
  cursor: zoom-out;
}
.image-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.image-preview-close {
  position: absolute;
  top: max(16px, var(--safe-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border: 1px solid #fff;
  border-radius: 999px;
  background: #000;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.chat-input {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bot));
  border-top: 1px solid var(--line-soft);
  background: var(--bg);
  position: sticky;
  bottom: 0;
}
.chat-input textarea {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 15px;
  max-height: 120px;
  outline: none;
  background: var(--bg);
}
.chat-input textarea:focus { box-shadow: 0 0 0 3px rgba(0,0,0,0.08); }
.chat-input .btn-send {
  width: 44px; height: 44px;
  padding: 0;
  border-radius: 999px;
  font-size: 20px;
  flex: 0 0 44px;
}
.chat-input .btn-photo {
  padding: 10px 12px;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* === CHAT MODE (after first message) === */
body.in-chat { background: var(--bg); }
body.in-chat .app > .hero,
body.in-chat .app > .services,
body.in-chat .app > .cta,
body.in-chat .app > .footer { display: none; }
body.in-chat .app { padding: 0; max-width: var(--maxw); }

.overlay.fullscreen {
  background: var(--bg);
  position: fixed;
  inset: 0;
  display: block;
  z-index: 1;
}
.overlay.fullscreen .sheet {
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  border: 0;
  border-radius: 0;
  animation: none;
  background: var(--bg);
}
.overlay.fullscreen .sheet-chat { min-height: 100dvh; }
.overlay.fullscreen .sheet-step:not(.sheet-chat) { display: none !important; }
.overlay.fullscreen [data-back], .overlay.fullscreen [data-close] { display: none; }

/* === DESKTOP: enforce vertical layout, centered === */
@media (min-width: 700px) {
  body { background: #ededed; }
  .app { background: var(--bg); min-height: 100vh; box-shadow: 0 0 0 1px var(--line-soft); }
  body.in-chat { background: #ededed; }
  body.in-chat .app { background: transparent; box-shadow: none; min-height: 0; }
  body.in-chat .overlay.fullscreen .sheet {
    margin-top: 0;
    height: 100dvh;
    max-height: 100dvh;
    max-width: var(--maxw);
    width: 100%;
    background: var(--bg);
  }
  .overlay { align-items: center; background: rgba(0,0,0,0.5); }
  .sheet {
    max-width: var(--maxw);
    max-height: 86vh;
    border-radius: 20px;
    border: 1px solid var(--line);
    overflow: hidden;
  }
  .sheet.sheet-compact { align-self: center; }
}
