:root {
  --bg: #f4f5f9; --card: #ffffff; --text: #1d2133; --muted: #6b7189; --line: #e3e5ee;
  --primary: #3b4a8c; --primary-2: #5566b0; --danger: #c8443b; --ok: #2f8a5b; --warn: #c88a1b;
  --bot: #eef0f8; --me: #3b4a8c; --me-text: #fff; --chip: #e8eaf5;
  --shadow: 0 1px 3px rgba(20, 25, 50, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141c; --card: #1c1f2b; --text: #e8eaf3; --muted: #9aa0b8; --line: #2c3042;
    --primary: #7d8fe0; --primary-2: #95a4ec; --danger: #e0675e; --ok: #4fbf85; --warn: #e3ad47;
    --bot: #262a3a; --me: #4c5cab; --me-text: #fff; --chip: #2a2f44; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 5; background: var(--primary); color: #fff; padding: 12px 16px; font-weight: 600; padding-top: calc(12px + env(safe-area-inset-top)); }
.logo { margin-right: 6px; }
main { max-width: 720px; margin: 0 auto; padding: 16px; }
.view { display: none; } .view.active { display: block; }
h2 { margin: 4px 0 12px; font-size: 1.4rem; } h3 { margin: 0 0 8px; font-size: 1.05rem; }
.card { background: var(--card); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.hero h2 { margin-top: 2px; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px; padding: 10px 14px; font-size: 1rem; cursor: pointer; text-decoration: none; margin: 4px 4px 4px 0; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { width: 100%; padding: 16px; font-size: 1.1rem; font-weight: 600; margin: 8px 0; }
.btn.link { background: none; border: none; color: var(--primary); padding: 8px 0; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; }
.wx { font-size: .95rem; margin-top: 4px; }
.wx b { font-size: 1.3rem; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .8rem; background: var(--chip); }
.badge.bad { background: var(--danger); color: #fff; } .badge.warn { background: var(--warn); color: #fff; } .badge.ok { background: var(--ok); color: #fff; }
.alert { border-left: 4px solid var(--warn); } .alert.bad { border-left-color: var(--danger); }

/* chat */
#chat-log { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.bot { background: var(--bot); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--me); color: var(--me-text); align-self: flex-end; border-bottom-right-radius: 4px; }
.typing { display: inline-flex; gap: 4px; margin-top: 10px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2 } 40% { opacity: 1 } }
.hidden { display: none !important; }
.chat-input { margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { background: var(--chip); border: 2px solid transparent; color: var(--text); border-radius: 99px; padding: 9px 14px; font-size: .98rem; cursor: pointer; }
.chip.sel { border-color: var(--primary); background: var(--card); }
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; margin-bottom: 10px; }
.scale button { padding: 10px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: .95rem; }
.compose { display: flex; gap: 8px; align-items: flex-end; }
.compose textarea, .compose input, #pw { flex: 1; width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); resize: none; }
.compose .btn { margin: 0; }
.chat-actions { text-align: center; margin-top: 6px; }
.summary-card { border-left: 4px solid var(--ok); }

/* history */
.hist-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.dot { flex: 0 0 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .9rem; color: #fff; background: var(--ok); }
.dot.h { background: var(--danger); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 14px; }
.cal div { aspect-ratio: 1; border-radius: 6px; background: var(--chip); font-size: .7rem; display: grid; place-items: center; color: var(--muted); }
.cal .h { background: var(--danger); color: #fff; } .cal .n { background: var(--ok); color: #fff; opacity: .7; }
.cal .lbl { background: none; font-weight: 600; }

/* factors */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
td, th { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
.v-prawdopodobny { color: var(--danger); font-weight: 600; } .v-sygnal { color: var(--warn); font-weight: 600; } .v-slaby { color: var(--muted); }
.hyp { padding: 8px 0; border-bottom: 1px solid var(--line); }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: .95rem; }
dt { color: var(--muted); } dd { margin: 0; }

/* nav + modal */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tabs button { flex: 1; background: none; border: none; color: var(--muted); padding: 8px 0 10px; font-size: .78rem; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabs button span { font-size: 1.3rem; }
.tabs button.active { color: var(--primary); font-weight: 600; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.modal-box { background: var(--card); width: 100%; max-width: 720px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); position: relative; }
.close { position: absolute; right: 10px; top: 6px; background: none; border: none; font-size: 1.8rem; color: var(--muted); cursor: pointer; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 12px; z-index: 20; text-align: center; }
.err { color: var(--danger); }
.disclaimer { margin-top: 18px; }

/* questionnaires */
.q-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.q-item p { margin: 0 0 8px; }
.q-item input[type=number] { width: 110px; font: inherit; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.q-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.q-opts .chip.sel { border-color: var(--primary); background: var(--card); font-weight: 600; }

/* login gate: nothing of the app is shown until the session is confirmed */
body.locked .top, body.locked main, body.locked .tabs { display: none !important; }
body.locked { padding-bottom: 0; }
.login-screen { display: none; }
body.locked .login-screen { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 18px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 2rem; }
.login-box input { width: 100%; font: inherit; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); margin-top: 8px; }
body.checking .login-screen { visibility: hidden; }
