:root {
  --bg: var(--tg-theme-bg-color, #0c0c0d);
  --fg: var(--tg-theme-text-color, #f4f4f5);
  --muted: var(--tg-theme-hint-color, #8a8a93);
  --card: var(--tg-theme-secondary-bg-color, #18181b);
  --accent: var(--tg-theme-button-color, #e8e4dc);
  --accent-fg: var(--tg-theme-button-text-color, #111);
  --safe-b: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px 16px calc(72px + var(--safe-b));
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
}
.brand {
  font-size: 13px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-weight: 600;
}
.status {
  font-size: 12px;
  color: var(--muted);
}

.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hidden { display: none; }

.thread {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 12px;
}
.bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
}
.bubble.bot { background: var(--card); align-self: flex-start; }
.bubble.me { background: var(--accent); color: var(--accent-fg); align-self: flex-end; }
.bubble.wait { color: var(--muted); }

.composer {
  display: flex;
  gap: 8px;
}
.composer input {
  flex: 1;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--card);
  color: var(--fg);
  font-size: 16px;
  outline: none;
}
.composer button {
  width: 44px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 18px;
}

.lead { color: var(--muted); font-size: 15px; line-height: 1.45; }
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-top: 12px;
}
.label { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
code {
  display: block;
  font-size: 12px;
  word-break: break-all;
  line-height: 1.4;
  margin-bottom: 12px;
}
.devices { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.7; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

.btn {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-fg);
}
.btn.danger { background: #2a2220; color: #f0d9d4; }
.btn.ghost {
  background: rgba(255,255,255,0.06);
  color: var(--fg);
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.btn-row .btn { width: auto; flex: 1; min-width: 118px; }

.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.home-name { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; }
.hint.tight { margin-top: 4px; }
.pill {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.pill.ok { background: #1d3a2a; color: #b8e0c8; }
.pill.off { background: #2a2220; color: #f0d9d4; }
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin-top: 16px;
}
.stat-value { font-size: 15px; font-weight: 600; }
.qr-box {
  margin-top: 12px;
  padding: 14px;
  background: #fff;
  border-radius: 16px;
  text-align: center;
}
.qr-box.hidden { display: none; }
.qr-box img { width: 180px; height: 180px; display: block; margin: 0 auto; }
.qr-box .hint { color: #666; }
#app-row { margin-top: 10px; }
.chip.feat:not(.on) { box-shadow: inset 0 0 0 1px var(--accent); }
.guide-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.guide-block:first-child { margin-top: 12px; padding-top: 0; border-top: 0; }
.guide-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.guide-desc { font-size: 13px; color: var(--muted); line-height: 1.45; }
.wizard-kicker { font-size: 18px; font-weight: 700; letter-spacing: -0.03em; }
.wizard-steps {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.wizard-steps li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.wizard-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-fg);
  margin-top: 2px;
}
.wizard-body { min-width: 0; flex: 1; }
.wizard-body p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.photo-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--card);
  color: var(--fg);
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
}

#view-faq, #view-home { overflow-y: auto; }
.faq { padding-bottom: 8px; }
.faq-item {
  background: var(--card);
  border-radius: 16px;
  margin-top: 10px;
}
.faq-item summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  flex-shrink: 0;
  color: var(--muted);
  font-weight: 400;
  font-size: 18px;
  line-height: 1;
}
.faq-item[open] summary::after { content: "–"; }
.faq-item p {
  margin: 0;
  padding: 0 16px 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.faq-item p b { color: var(--fg); font-weight: 600; }
.faq-item ol, .faq-item ul {
  margin: 0;
  padding: 0 16px 16px 36px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.faq-item li + li { margin-top: 8px; }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 8px 4px calc(8px + var(--safe-b));
  background: var(--bg);
  border-top: 1px solid rgba(255,255,255,0.06);
}
.tabs button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  padding: 10px 0;
  white-space: nowrap;
}
.tabs button.on { color: var(--fg); font-weight: 600; }

.mode-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  background: rgba(255,255,255,0.06);
  color: var(--fg);
}
.chip.on {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.exit-row .chip { padding: 6px 10px; font-size: 12px; }
