:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 12px;
  --tap: 44px;
  --app-height: 100dvh;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

.screen { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.screen-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.hidden { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.prose { padding: 24px 18px calc(24px + env(safe-area-inset-bottom)); }
.prose h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 12px; }
.lead { font-size: 18px; margin: 0 0 18px; }
.muted { color: var(--muted); font-size: 15px; }

.facts { list-style: none; margin: 0 0 20px; padding: 0; }
.facts li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

#access-form { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
#access-form label { font-weight: 600; }

input, textarea {
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: var(--tap);
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button[disabled] { opacity: .55; cursor: default; }
.btn-secondary:hover { background: var(--accent-soft); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
/* Powrót ze strony o danych: wygląda jak odnośnik, ale jest przyciskiem, bo
   href="javascript:…" nie przechodzi przez CSP (spec §6). */
.btn-link { background: transparent; color: var(--accent); border-color: transparent; padding: 10px 0; text-decoration: underline; }

.error { color: var(--danger); margin: 0; }

#stage-bar {
  display: flex; gap: 6px;
  padding: 12px 12px calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.stage { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.stage i { display: block; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.stage.is-done i { background: var(--muted); }
.stage.is-active { color: var(--ink); font-weight: 600; }
.stage.is-active i { background: var(--accent); transform: scale(1.35); transition: transform .2s ease; }

#messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 11px 14px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); }
.msg-user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.is-streaming .msg-text::after { content: "▍"; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

#thinking { display: flex; align-items: center; gap: 6px; padding: 0 18px 8px; color: var(--muted); font-size: 14px; }
#thinking .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite ease-in-out; }
#thinking .dot:nth-child(2) { animation-delay: .18s; }
#thinking .dot:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

#chat-error { margin: 0 14px 10px; padding: 12px 14px; border: 1px solid var(--danger); border-radius: var(--radius); }
#chat-error p { margin: 0 0 10px; color: var(--danger); }
#retry-turn { margin: 0 14px 10px; }

#composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
#composer-input { flex: 1 1 auto; max-height: 40vh; resize: none; }

#session-actions { display: flex; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
#session-actions button { flex: 1 1 0; font-size: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 16px 14px calc(16px + env(safe-area-inset-bottom)); padding: 18px; }
.card h2 { margin: 0 0 8px; font-size: 22px; }
#summary-fields { margin: 16px 0 0; }
#summary-fields dt { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-top: 14px; }
#summary-fields dd { margin: 4px 0 0; overflow-wrap: anywhere; }
#summary-fields ul { margin: 4px 0 0; padding-left: 20px; }
.reveal { animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }

/* --- Ekran powitalny i strona główna ------------------------------------ */
.welcome { width: 100%; max-width: 560px; margin: 0 auto; padding: 20px 20px calc(32px + env(safe-area-inset-bottom)); }
.welcome > * { animation: rise .4s ease both; }
.welcome > :nth-child(2) { animation-delay: .04s; }
.welcome > :nth-child(3) { animation-delay: .08s; }
.welcome > :nth-child(4) { animation-delay: .12s; }
.welcome > :nth-child(n+5) { animation-delay: .16s; }

.topbar { display: flex; align-items: center; gap: 10px; margin: 0 0 26px; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 17px;
}
.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.pill {
  margin-left: auto; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.headline { font-size: clamp(28px, 7.5vw, 36px); line-height: 1.15; letter-spacing: -.02em; font-weight: 700; margin: 0 0 10px; }
.welcome .lead { font-size: 16px; color: var(--muted); margin: 0 0 20px; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 20px;
}
.access { display: flex; flex-direction: column; gap: 10px; margin: 0 0 28px; }
.access label, .access > strong { font-weight: 600; font-size: 15px; }
.access-label { font-weight: 600; font-size: 15px; }
.code-boxes { display: flex; align-items: center; gap: 6px; }
.code-box {
  flex: 1 1 0; min-width: 0; width: auto; height: 52px; padding: 0;
  font-size: 22px; font-weight: 600; text-align: center; text-transform: uppercase;
  border-radius: 10px; border-width: 1.5px; caret-color: var(--accent);
}
.code-box:focus { border-color: var(--accent); }
.code-dash { flex: 0 0 auto; color: var(--muted); font-weight: 600; padding: 0 2px; }
@media (max-width: 360px) { .code-boxes { gap: 4px; } .code-box { font-size: 19px; height: 46px; } }
.access .btn-primary { font-size: 16px; font-weight: 600; border-radius: 10px; }
.note { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.choice { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 10px; background: var(--accent-soft); }
.choice p { margin: 0 0 4px; font-size: 14px; }

.section-title { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }

/* Etapy rozmowy: te same cztery, które w oknie czatu pokazuje pasek etapów. */
.route { list-style: none; margin: 0 0 28px; padding: 0; display: grid; gap: 8px; }
.route li {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.route li > div { display: flex; flex-direction: column; gap: 1px; }
.step {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; font-size: 13px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
}
.route strong { font-size: 15px; }
.route li > div > span { color: var(--muted); font-size: 14px; }

.facts { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 8px; }
.facts li {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.facts strong { display: block; font-size: 15px; margin-bottom: 2px; }
.check {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; font-size: 13px; font-weight: 700;
  background: #dcfce7; color: var(--success);
}

.more { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.more summary { display: flex; align-items: center; min-height: var(--tap); cursor: pointer; font-weight: 600; color: var(--accent); }
.more p { margin: 8px 0; }
.more a, .welcome .muted a { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

#mic-btn { min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; padding: 0; }
#mic-btn svg { display: block; }
#mic-btn.is-recording { background: var(--danger); color: #fff; border-color: var(--danger); }
#mic-panel {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  border-top: 1px solid var(--line); background: var(--surface); font-size: 15px; color: var(--muted);
}
#mic-wave { width: 240px; max-width: 50%; height: 36px; }

/* Głosówki: odtwarzacz pod transkryptem w dymku (spec §13). */
.msg-voice { min-width: 220px; }
.msg-voice .msg-text { display: block; font-size: 15px; }
.msg-bot.msg-voice .msg-text { color: var(--ink); }
.voice-player { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.voice-play {
  flex: 0 0 auto; width: 36px; height: 36px; min-height: 0; margin: 0; padding: 0;
  border-radius: 50%; border: 0; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-ink);
}
.msg-user .voice-play { background: rgba(255, 255, 255, .22); color: #fff; }
.voice-bar { flex: 1 1 auto; height: 4px; border-radius: 999px; background: var(--line); overflow: hidden; }
.msg-user .voice-bar { background: rgba(255, 255, 255, .35); }
.voice-fill { display: block; width: 0; height: 100%; background: var(--accent); }
.msg-user .voice-fill { background: #fff; }
.voice-time { flex: 0 0 auto; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.msg-user .voice-time { color: rgba(255, 255, 255, .85); }
.is-voicing .msg-text::after { content: " 🔊"; opacity: .6; }
#mic-btn:disabled { opacity: .5; cursor: default; }
