/* Gadaj Gadaj – wersja przeglądarkowa. Paleta jak w aplikacji Android (kontrast tekstu ≥ 4.5:1). */
:root {
  --violet: #5B33C9;
  --violet-deep: #3B1E8F;
  --raspberry: #B3245B;
  --teal: #00696B;
  --ink: #1C1B1F;
  --muted: #49454F;
  --bg: #FFFBFF;
  --surface: #FFFFFF;
  --tint: #F3EDF7;
  --line: #E7E0EC;
  --primary-container: #E9DDFF;
  --theirs: #FFD9E2;
  --on-theirs: #3E001D;
  --error: #BA1A1A;
  --error-container: #FFDAD6;
  --on-error-container: #410002;
  --info-container: #B1F0EF;
  --on-info-container: #002020;
  --hero: linear-gradient(150deg, #3B1E8F 0%, #5B33C9 50%, #B3245B 100%);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #E6E1E5;
    --muted: #CAC4D0;
    --bg: #141218;
    --surface: #1D1B20;
    --tint: #211F26;
    --line: #36343B;
    --primary-container: #4A2AB0;
    --theirs: #7B2949;
    --on-theirs: #FFD9E2;
    --error: #FFB4AB;
    --error-container: #93000A;
    --on-error-container: #FFDAD6;
    --info-container: #004F50;
    --on-info-container: #B1F0EF;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
#app, .view { min-height: 100%; }
a { color: var(--violet); }
@media (prefers-color-scheme: dark) { a { color: #CFBCFF; } }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #FF8FB1; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.noscript { padding: 24px; }

/* Przyciski – obszar dotyku min. 48 px */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 22px; border-radius: 999px; border: 0;
  font-weight: 700; text-decoration: none; cursor: pointer; background: none;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-block { width: 100%; }
.btn-primary { background: var(--violet); color: #fff; }
.btn-light { background: #fff; color: var(--violet-deep); }
.btn-ghost { border: 2px solid #fff; color: #fff; }
.btn-outline { border: 2px solid var(--violet); color: var(--violet); background: transparent; }
.btn-text { color: var(--violet); }
.btn-tonal { background: var(--theirs); color: var(--on-theirs); }
.btn-danger { background: var(--raspberry); color: #fff; }
.btn-small { min-height: 48px; padding: 8px 14px; }
.danger { color: var(--raspberry); }
@media (prefers-color-scheme: dark) {
  .btn-outline, .btn-text { color: #CFBCFF; border-color: #CFBCFF; }
  .btn-primary { background: #CFBCFF; color: #381E72; }
  .danger { color: #FFB1C8; }
}
.icon-btn {
  display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(127, 127, 127, .14); }

/* Ekran: górny pasek, treść, dolna nawigacja */
.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: calc(8px + var(--safe-top)) 8px 8px; background: var(--bg); border-bottom: 1px solid var(--line); min-height: 64px;
}
.topbar-brand { background: var(--violet); color: #fff; border-bottom: 0; }
.topbar-title { flex: 1; margin: 0 8px; font-size: 1.25rem; font-weight: 800; display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-person { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar-person span, .topbar-person small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-person small { font-weight: 500; font-size: .8rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; }
.content { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; outline: none; }
.with-nav .content { padding-bottom: calc(96px + var(--safe-bottom)); }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: space-around;
  background: var(--tint); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-bottom));
}
.tab {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px; padding: 6px; color: var(--muted); text-decoration: none; font-size: .8rem; font-weight: 600; border-radius: 16px;
}
.tab svg { padding: 2px 18px; border-radius: 999px; box-sizing: content-box; }
.tab.active { color: var(--ink); }
.tab.active svg { background: var(--theirs); color: var(--on-theirs); }

.fab {
  position: fixed; right: 16px; bottom: calc(88px + var(--safe-bottom)); z-index: 6;
  display: inline-flex; align-items: center; gap: 8px; min-height: 56px; padding: 0 22px; border-radius: 18px;
  background: var(--raspberry); color: #fff; font-weight: 700; text-decoration: none; box-shadow: 0 8px 20px rgba(179, 36, 91, .35);
}

.offline {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  background: var(--info-container); color: var(--on-info-container); font-size: .92rem;
}
.offline[hidden] { display: none; }

/* Stany: ładowanie, pusto, błąd */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 48px 24px; }
.state h2 { margin: 4px 0 0; font-size: 1.3rem; }
.state p { margin: 0; max-width: 32em; }
.state-icon.error { color: var(--error); }
.state-mark { width: 88px; height: 88px; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--primary-container); border-top-color: var(--violet); animation: spin 1s linear infinite; }
.spinner.light { border-color: rgba(255,255,255,.35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* Powitanie i ekran startowy */
.splash, .welcome {
  min-height: 100vh; min-height: 100dvh; background: var(--hero); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom)); gap: 14px;
}
.splash-mark, .welcome-mark { width: 120px; height: 120px; }
.splash-title { font-size: 2rem; font-weight: 900; margin: 0; }
.welcome-inner { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 14px; outline: none; }
.welcome h1 { font-size: 2.4rem; font-weight: 900; margin: 0; }
.welcome-lead { margin: 0 0 12px; font-size: 1.1rem; }
.welcome-actions { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.link-light { color: #fff; font-weight: 700; padding: 12px; }
.disclaimer { font-size: .85rem; margin: 0; }
.install-tip { background: rgba(255,255,255,.14); border-radius: 18px; padding: 14px 16px; text-align: left; font-size: .95rem; }
.install-tip p { margin: 4px 0 0; }

/* Formularze */
.form { display: flex; flex-direction: column; gap: 14px; padding: 20px 16px 40px; max-width: 480px; margin: 0 auto; }
.form-title { font-size: 1.6rem; font-weight: 800; margin: 0; }
.form-title-sm { font-weight: 700; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; }
.field input, .field textarea {
  width: 100%; min-height: 52px; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid #79747E; background: var(--surface); font-size: 17px;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--violet); outline: 2px solid var(--violet); outline-offset: 0; }
.field.has-error input, .field.has-error textarea { border-color: var(--error); }
.field-hint, .field-error { margin: 0; font-size: .88rem; color: var(--muted); }
.field-error { color: var(--error); }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--violet); flex: none; }
.link { align-self: flex-start; padding: 10px 0; font-weight: 600; }
.inline-error { background: var(--error-container); color: var(--on-error-container); padding: 12px 14px; border-radius: 12px; }
.inline-error[hidden] { display: none; }

/* Listy osób i rozmów */
.list { list-style: none; margin: 0; padding: 0; }
.person { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.person-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; min-height: 72px; padding: 10px 16px;
  color: inherit; text-decoration: none;
}
a.person-main:hover { background: var(--tint); }
.person-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.person-nick { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-sub { color: var(--muted); font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-time { color: var(--muted); font-size: .8rem; flex: none; }
.person-actions { display: flex; align-items: center; gap: 4px; padding-right: 10px; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-grid; place-items: center; width: 48px; height: 48px; color: var(--teal); }
.avatar {
  width: var(--size); height: var(--size); flex: none; border-radius: 50%; background: var(--avatar-bg, #5B33C9);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: calc(var(--size) * .38);
}
@media (max-width: 380px) {
  .person { flex-wrap: wrap; }
  .person-actions { width: 100%; padding: 0 16px 10px 78px; }
}

/* Profil */
.profile { display: flex; flex-direction: column; gap: 12px; padding: 20px 16px 24px; max-width: 480px; margin: 0 auto; }
.profile-card { background: var(--primary-container); border-radius: 24px; padding: 24px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; }
.profile-card h2 { margin: 6px 0 0; font-size: 1.7rem; overflow-wrap: anywhere; }
.profile-number { font-weight: 700; margin: 0; }

/* Wyszukiwanie */
.searchbar {
  display: flex; align-items: center; gap: 8px; margin: 12px 16px; padding: 0 6px 0 14px;
  border: 2px solid var(--violet); border-radius: 16px; background: var(--surface);
}
.searchbar input { flex: 1; min-height: 52px; border: 0; background: transparent; font-size: 17px; outline: none; }
.searchbar input::-webkit-search-cancel-button { display: none; }

/* Czat */
.chat-screen { height: 100vh; height: 100dvh; }
.chat-screen .content { display: flex; flex-direction: column; min-height: 0; max-width: none; }
.chat-area { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column-reverse; gap: 6px; padding: 12px;
  outline: none; overscroll-behavior: contain;
}
.messages .state { margin: auto 0; }
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble { max-width: min(78%, 520px); padding: 10px 14px; border-radius: 20px 20px 20px 6px; background: var(--theirs); color: var(--on-theirs); }
.mine .bubble { background: var(--violet); color: #fff; border-radius: 20px 20px 6px 20px; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-time { display: block; text-align: right; font-size: .75rem; margin-top: 2px; }
.older { display: flex; justify-content: center; }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line); background: var(--tint);
}
.composer[hidden] { display: none; }
.composer textarea {
  flex: 1; min-height: 52px; max-height: 160px; padding: 13px 16px; border-radius: 26px; border: 1.5px solid #79747E;
  background: var(--surface); resize: none; font-size: 17px; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--violet); outline: none; }
.counter { align-self: center; font-size: .8rem; color: var(--muted); }
.counter:empty { display: none; }
.counter.over { color: var(--error); font-weight: 700; }
.send-btn {
  width: 52px; height: 52px; flex: none; border-radius: 50%; border: 0; background: var(--violet); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.send-btn:disabled { background: var(--line); color: var(--muted); cursor: default; }
.blocked-notice {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px calc(14px + var(--safe-bottom));
  background: var(--error-container); color: var(--on-error-container);
}
.blocked-notice[hidden] { display: none; }
.blocked-notice span { flex: 1; }

/* Menu, okna dialogowe, komunikaty */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 52px; min-width: 220px; z-index: 10; padding: 6px 0;
  background: var(--surface); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.menu[hidden] { display: none; }
.menu button { display: block; width: 100%; min-height: 48px; padding: 10px 16px; text-align: left; border: 0; background: none; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--tint); }
.dialog { border: 0; border-radius: 24px; padding: 24px; max-width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); }
.dialog::backdrop { background: rgba(20, 10, 40, .45); }
.dialog h2 { margin: 0 0 8px; font-size: 1.25rem; }
.dialog p { margin: 0 0 16px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + var(--safe-bottom)); z-index: 20;
  display: flex; flex-direction: column; gap: 8px; width: min(520px, calc(100vw - 32px)); pointer-events: none;
}
.toast { background: #322F35; color: #F5EFF7; padding: 14px 16px; border-radius: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.3); transition: opacity .4s; }
.toast.out { opacity: 0; }

/* Tajne czaty i samozniszczenie */
.choice-list { display: grid; gap: 6px; margin: 8px 0; }
.choice { min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line, #d9d2ec); background: none; color: inherit; text-align: left; font: inherit; cursor: pointer; }
.choice.selected { border-color: var(--violet); background: var(--tint); font-weight: 600; }
.safety-code { font: 600 1.25rem/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; text-align: center; padding: 12px; border-radius: 12px; background: var(--tint); word-spacing: .4em; }
.chat-badges { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px 0; justify-content: center; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--tint); }
.badge.secret { background: #1e7d47; color: #fff; }
.badge svg { width: 16px; height: 16px; }
.system-row { display: flex; justify-content: center; }
.system-msg { margin: 4px 16px; padding: 4px 12px; border-radius: 999px; font-size: .8rem; text-align: center; color: var(--muted); background: var(--tint); }
.bubble.undecryptable p { font-style: italic; opacity: .85; }
.bubble-time .left { margin-left: 6px; font-weight: 600; }
.lock-prefix { display: inline-flex; vertical-align: -3px; margin-right: 4px; color: #1e7d47; }
.secret-screen .topbar { background: #14532d; color: #fff; }
.secret-screen .topbar .icon-btn, .secret-screen .topbar-person small { color: #e6f4ea; }

/* Nieprzeczytane wiadomości */
.tab { position: relative; }
.tab-badge {
  position: absolute; top: 2px; left: calc(50% + 10px); min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--raspberry); color: #fff; font-size: .72rem; font-weight: 800; line-height: 20px; text-align: center;
}
.unread-badge {
  flex: none; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px; margin-left: 8px;
  background: var(--violet); color: #fff; font-size: .8rem; font-weight: 800; line-height: 24px; text-align: center;
}
.has-unread .person-nick, .has-unread .person-sub { font-weight: 800; color: var(--ink); }
.settings { display: grid; gap: 8px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .unread-badge { background: #CFBCFF; color: #21005D; } }

/* Puste komunikaty (np. przed wysłaniem kodu) nie zajmują miejsca */
.form > p:empty, .form > .inline-error[hidden] { display: none; }
.form.form-head { padding-bottom: 0; }
.form-head ~ .form { padding-top: 0; }

/* 0.6.0 – statusy dostępności */
.avatar-wrap { position: relative; display: inline-flex; flex: none; }
.presence-dot {
  position: absolute; right: -1px; bottom: -1px; width: 14px; height: 14px; border-radius: 50%;
  border: 2.5px solid var(--bg); background: #2e9d4f;
}
.presence-dot.away { background: #e0a100; }
.presence-dot.dnd { background: #d93025; }
.presence-dot.invisible { background: #8d8a93; }
.presence-dot.inline { position: static; display: inline-block; width: 12px; height: 12px; border: 0; margin-right: 8px; vertical-align: -1px; }
.topbar .presence-dot { border-color: var(--bg); }
.presence-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.presence-choice {
  min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: none; color: inherit;
  font: inherit; text-align: left; cursor: pointer;
}
.presence-choice.selected { border-color: var(--violet); background: var(--tint); font-weight: 700; }
.status-form { display: flex; gap: 8px; align-items: center; }
.status-form input { flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1.5px solid #79747E; background: var(--surface); color: var(--ink); font-size: 16px; }

/* Grupy */
.group-avatar { --avatar-bg: #00696B !important; }
.group-prefix { color: var(--teal); }
.topbar-person { color: inherit; text-decoration: none; display: flex; flex-direction: column; min-width: 0; }
a.topbar-person:hover span { text-decoration: underline; }
.bubble-sender { display: block; font-size: .8rem; font-weight: 800; color: var(--sender, var(--violet)); margin-bottom: 2px; }
@media (prefers-color-scheme: dark) { .bubble-sender { filter: brightness(1.8); } }
.role-badge { margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--primary-container); font-size: .72rem; font-weight: 700; vertical-align: 2px; }
.group-head { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px 16px 4px; text-align: center; }
.group-head h2 { margin: 0; overflow-wrap: anywhere; }
.group-actions { gap: 8px; }
.pick { cursor: pointer; }
.pick input[type="checkbox"] { width: 22px; height: 22px; flex: none; accent-color: var(--violet); }
.dialog-wide { width: min(520px, calc(100vw - 32px)); }
.dialog-wide .list-area { max-height: 50vh; overflow-y: auto; margin: 0 -24px 12px; border-top: 1px solid var(--line); }
.dialog-form { display: grid; gap: 12px; }

/* Archiwum i wyszukiwanie */
.archive-icon { --size: 48px; background: var(--tint); color: var(--violet); }
.snippet mark { background: #ffe08a; color: #1c1b1f; border-radius: 3px; padding: 0 1px; }

/* Zdjęcia i wiadomości głosowe */
.bubble.has-media { padding: 6px; }
.bubble.has-media p, .bubble.has-media .bubble-time, .bubble.has-media .bubble-sender { padding: 0 8px; }
.photo-msg { display: block; width: min(280px, 62vw); max-width: 100%; padding: 0; border: 0; border-radius: 14px; overflow: hidden; background: rgba(0,0,0,.08); cursor: zoom-in; }
.photo-msg img { display: block; width: 100%; height: 100%; object-fit: cover; }
.voice-msg { display: flex; align-items: center; gap: 6px; padding: 4px 6px; min-width: min(260px, 60vw); }
.voice-msg audio { flex: 1; min-width: 0; height: 40px; }
.voice-len { font-size: .8rem; font-weight: 700; }
.media-missing { display: block; padding: 10px; font-style: italic; opacity: .8; }
.composer-icon { flex: none; align-self: center; color: var(--violet); }
.composer-icon:disabled { color: var(--muted); }
.send-btn[hidden], .composer-icon[hidden] { display: none; }
.mic-btn { background: var(--raspberry); }
.uploading { padding: 6px 16px; font-size: .85rem; color: var(--muted); text-align: center; background: var(--tint); }
.uploading[hidden] { display: none; }
.recorder {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line); background: var(--tint);
}
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #d93025; animation: pulse 1s ease-in-out infinite; }
.rec-time { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.rec-max { flex: 1; }
@keyframes pulse { 50% { opacity: .3; } }
.photo-dialog { width: min(520px, calc(100vw - 32px)); }
.photo-preview { display: block; max-width: 100%; max-height: 55vh; margin: 0 auto 12px; border-radius: 12px; }
.photo-dialog input { min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1.5px solid #79747E; background: var(--surface); color: var(--ink); font-size: 16px; }
.photo-full { padding: 12px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
.photo-full img { display: block; max-width: 100%; max-height: calc(100vh - 120px); margin: 0 auto 8px; border-radius: 8px; }
