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

:root {
  --bg:      #09090b;
  --bg2:     #111114;
  --surface: #17171b;
  --border:  rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.13);
  --accent:  #6366f1;
  --accent-l:#818cf8;
  --text:    #f4f4f6;
  --muted:   #71717a;
  --muted2:  #a1a1aa;
  --danger:  #ef4444;
  --tg-safe: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ── SCREENS ── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.screen.active {
  display: flex;
  transform: translateX(0);
}
.screen.slide-in {
  display: flex;
  animation: slideIn 0.24s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.screen.slide-out {
  display: flex;
  animation: slideOut 0.24s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
@keyframes slideOut {
  from { transform: translateX(0); }
  to   { transform: translateX(-30%); opacity: 0.6; }
}

/* ── LOADING ── */
#screen-loading {
  display: flex;
  align-items: center;
  justify-content: center;
}
.loader-wrap { text-align: center; }
.loader-dots {
  display: flex;
  gap: 7px;
  justify-content: center;
  margin-bottom: 16px;
}
.loader-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: dotPulse 1.4s infinite;
}
.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.3); }
}
.loader-wrap p {
  font-size: 0.82rem;
  color: var(--muted);
}

/* ── TOP BAR ── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  min-height: 52px;
}
.top-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text);
  flex: 1;
}
.back-btn, .icon-btn {
  background: none;
  border: none;
  color: var(--muted2);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.back-btn:active, .icon-btn:active {
  background: var(--border);
  color: var(--text);
}

/* ── SCROLL AREA ── */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 calc(16px + var(--tg-safe));
}
.form-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px calc(24px + var(--tg-safe));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── PROFILE CARD ── */
.profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
  color: var(--text);
}
.profile-card:active { background: var(--bg2); }
.profile-card:first-child { border-top: 1px solid var(--border); }

.profile-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-l);
  flex-shrink: 0;
}

.profile-info { flex: 1; min-width: 0; }
.profile-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-meta {
  font-size: 0.78rem;
  color: var(--muted2);
  margin-top: 1px;
}

.quality-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.quality-dot.low    { background: var(--muted); }
.quality-dot.medium { background: #f59e0b; }
.quality-dot.good   { background: #22c55e; }
.quality-dot.great  { background: var(--accent); }

/* ── EMPTY STATE ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 32px;
  text-align: center;
  flex: 1;
}
.empty-state.hidden { display: none; }
.empty-icon { color: var(--muted); opacity: 0.5; margin-bottom: 4px; }
.empty-state h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.empty-state p { font-size: 0.85rem; color: var(--muted2); line-height: 1.6; max-width: 260px; }

/* ── FORM ── */
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted2);
  letter-spacing: 0.2px;
  text-transform: uppercase;
}
.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-size: 0.75rem;
}
.form-group input,
.form-group textarea {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s;
  resize: none;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}
.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--muted);
}

.relation-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 2px;
}
.chip {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 100px;
  color: var(--muted2);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip.active,
.chip:active {
  background: rgba(99,102,241,0.15);
  border-color: var(--accent);
  color: var(--accent-l);
}
.form-hint {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.55;
}

/* ── BUTTONS ── */
.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 22px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  letter-spacing: -0.1px;
  text-align: center;
}
.btn-primary:active { background: var(--accent-l); }
.btn-primary.full { width: 100%; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── PROFILE DETAIL ── */
.profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.stat-cell {
  background: var(--bg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat-val {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}
.stat-lbl {
  font-size: 0.74rem;
  color: var(--muted2);
}

.action-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 16px;
}
.action-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.action-card:active { background: var(--surface); }
.action-card.primary-card { border-color: rgba(99,102,241,0.3); }
.action-card svg { color: var(--muted2); flex-shrink: 0; }
.action-card.primary-card svg { color: var(--accent-l); }
.action-card strong {
  display: block;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.2px;
}
.action-card span {
  display: block;
  font-size: 0.78rem;
  color: var(--muted2);
  margin-top: 2px;
}

.section-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 0 16px 10px;
}
.sessions-block { padding-bottom: 8px; }
.sessions-block.hidden { display: none; }

.session-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: none;
  border-left: none; border-right: none; border-top: none;
  width: 100%;
  text-align: left;
  color: var(--text);
  transition: background 0.12s;
}
.session-row:first-child { border-top: 1px solid var(--border); }
.session-row:active { background: var(--bg2); }
.session-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.session-info { flex: 1; min-width: 0; }
.session-date { font-size: 0.83rem; color: var(--muted2); }
.session-anchor {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── UPLOAD ZONE ── */
.upload-zone {
  border: 2px dashed var(--border2);
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:active, .upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,0.06);
  color: var(--accent-l);
}
.upload-zone p { font-size: 0.88rem; color: var(--muted2); }
.upload-zone span { font-size: 0.74rem; color: var(--muted); }

.or-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
}
.or-divider::before, .or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.upload-feedback {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.84rem;
  line-height: 1.55;
}
.upload-feedback.hidden { display: none; }
.upload-feedback.success {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.25);
  color: #86efac;
}
.upload-feedback.error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  color: #fca5a5;
}

/* ── CHAT ── */
#screen-chat { background: var(--bg); }
.messages-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-wrap: break-word;
}
.msg.bot {
  align-self: flex-start;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px 14px 14px 3px;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 14px 14px 3px 14px;
}
.msg.typing {
  align-self: flex-start;
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
  border-radius: 14px 14px 14px 3px;
}
.msg.typing span {
  width: 6px; height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: dotPulse 1.4s infinite;
}
.msg.typing span:nth-child(2) { animation-delay: 0.2s; }
.msg.typing span:nth-child(3) { animation-delay: 0.4s; }

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--tg-safe));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
#chat-input {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  padding: 9px 16px;
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
#chat-input:focus { border-color: rgba(99,102,241,0.4); }
#chat-input::placeholder { color: var(--muted); }

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #fff;
  width: 38px; height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn:active { background: var(--accent-l); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── ONBOARDING ── */
.ob-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0 24px;
  padding-bottom: calc(24px + var(--tg-safe));
}
.ob-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 48px;
}
.ob-eyebrow {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent-l);
  opacity: 0.75;
  margin-bottom: 20px;
}
.ob-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(2rem, 8vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1.1;
  color: var(--text);
  margin-bottom: 20px;
}
.ob-sub {
  font-size: 0.9rem;
  color: var(--muted2);
  line-height: 1.7;
  font-weight: 300;
  max-width: 320px;
}
.ob-steps {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 8px;
}
.ob-step {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.ob-step-num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent-l);
  letter-spacing: 0.5px;
  opacity: 0.7;
  min-width: 22px;
  padding-top: 3px;
}
.ob-step strong {
  display: block;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}
.ob-step p {
  font-size: 0.82rem;
  color: var(--muted2);
  line-height: 1.55;
}
.ob-hotline {
  margin-top: 24px;
  padding: 14px 16px;
  border: 1px solid var(--border2);
  border-radius: 10px;
  font-size: 0.83rem;
  color: var(--muted2);
  line-height: 1.5;
}
.ob-hotline strong { color: var(--text); font-weight: 600; }
.ob-hotline span { font-size: 0.75rem; color: var(--muted); }

.ob-bottom {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 4px;
}
.ob-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border2);
  transition: background 0.2s, transform 0.2s;
}
.dot.active {
  background: var(--accent);
  transform: scale(1.25);
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: calc(80px + var(--tg-safe));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 100px;
  padding: 8px 18px;
  font-size: 0.82rem;
  color: var(--muted2);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 999;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── End chat button ── */
.end-chat-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  margin-left: auto;
}
.end-chat-btn:hover { color: var(--accent); background: rgba(255,255,255,0.05); }
