/* =========================================================================
   Halo — arkusz stylów
   Sygnatura: koncentryczne pierścienie "halo". Kolor marki: indygo #6759FF.
   ========================================================================= */

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

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  /* Bez niebieskiej/szarej poświaty przy dotknięciu (Android/iOS). */
  -webkit-tap-highlight-color: transparent;
  /* Domyślnie wyłączamy zaznaczanie (interfejs czatu, długie przytrzymanie =
     menu kontekstowe). Pola tekstowe i treść wiadomości — wyjątki niżej. */
  -webkit-user-select: none;
  user-select: none;
}

/* Pola do wpisywania pozostają zaznaczalne. */
input,
textarea,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}

/* Na urządzeniach ze wskaźnikiem (desktop) treść wiadomości można zaznaczać
   i kopiować; na dotyku służy do tego „Kopiuj" z menu. */
@media (pointer: fine) {
  .bubble-text {
    -webkit-user-select: text;
    user-select: text;
  }
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* Atrybut `hidden` musi ukrywać element nawet gdy reguła autorska ustawia
   display (np. .reply-bar { display: flex }). Bez tego pusty pasek byłby
   widoczny mimo hidden=true. */
[hidden] {
  display: none !important;
}

/* --- Tokeny: motyw jasny -------------------------------------------------- */
:root {
  --bg: #ffffff;
  --bg-chat: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f4f5f7;
  --surface-hover: #f0f1f4;
  --border: #e6e8ec;
  --border-strong: #d6d9df;

  --text: #0f1419;
  --text-muted: #6a7480;
  --text-faint: #9aa3ad;

  --brand: #6759ff;
  --brand-strong: #5a4bea;
  --brand-soft: #eceaff;
  --brand-contrast: #ffffff;

  --sent-bg: linear-gradient(135deg, #6759ff 0%, #7d6fff 100%);
  --sent-text: #ffffff;
  --sent-meta: rgba(255, 255, 255, 0.78);
  --recv-bg: #ffffff;
  --recv-text: #0f1419;
  --recv-meta: #98a1ab;

  --online: #2dc587;
  --status-available: #2dc587;
  --status-away: #f5a623;
  --status-busy: #e0405a;
  --status-invisible: #9aa3ad;
  --danger: #e0405a;

  --shadow-md: 0 6px 24px rgba(15, 20, 25, 0.12);
  --shadow-bubble: 0 1px 1px rgba(15, 20, 25, 0.06);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-bubble: 18px;

  --header-h: 64px;
  --sidebar-w: 360px;
}

/* --- Tokeny: motyw ciemny ------------------------------------------------- */
[data-theme="dark"] {
  --bg: #0e0f1a;
  --bg-chat: #0b0c14;
  --surface: #14151f;
  --surface-2: #1a1c28;
  --surface-hover: #1e2030;
  --border: #262838;
  --border-strong: #313348;

  --text: #e8eaef;
  --text-muted: #9298a6;
  --text-faint: #6b7180;

  --brand: #6759ff;
  --brand-strong: #7568ff;
  --brand-soft: #20223a;
  --brand-contrast: #ffffff;

  --sent-bg: linear-gradient(135deg, #6759ff 0%, #8174ff 100%);
  --sent-text: #ffffff;
  --sent-meta: rgba(255, 255, 255, 0.72);
  --recv-bg: #20222e;
  --recv-text: #e8eaef;
  --recv-meta: #7c8390;

  --online: #2dc587;
  --status-available: #2dc587;
  --status-away: #f5a623;
  --status-busy: #ff5a72;
  --status-invisible: #6b7180;
  --danger: #ff5a72;

  --shadow-md: 0 10px 34px rgba(0, 0, 0, 0.5);
  --shadow-bubble: 0 1px 1px rgba(0, 0, 0, 0.2);
}

/* --- Pierścienie "halo" (sygnatura, używane w logo i pustym stanie) ------- */
.halo-rings {
  position: relative;
  display: inline-block;
}
.halo-rings span {
  position: absolute;
  top: 50%;
  left: 50%;
  border: 2px solid var(--brand);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.halo-rings span:nth-child(1) {
  width: 100%;
  height: 100%;
  opacity: 0.35;
  border-width: 1.5px;
}
.halo-rings span:nth-child(2) {
  width: 66%;
  height: 66%;
  opacity: 0.6;
  border-width: 3px;
}
.halo-rings span:nth-child(3) {
  width: 32%;
  height: 32%;
  opacity: 1;
  background: var(--brand);
}

/* Pulsacja pierścieni w pustym stanie — fala emanuje ze środka: zaczyna mała
   i gruba, rośnie i cienieje, zanikając. */
@keyframes halo-pulse {
  0% {
    transform: translate(-50%, -50%) scale(0.4);
    opacity: 0.85;
    border-width: 5px;
  }
  60% {
    opacity: 0.25;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.55);
    opacity: 0;
    border-width: 1px;
  }
}

/* =========================================================================
   Wspólne kontrolki (przyciski, pola)
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active {
  transform: scale(0.985);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--brand);
  color: var(--brand-contrast);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-strong);
}
.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding-left: 2px;
}
.input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.input::placeholder {
  color: var(--text-faint);
}
.input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}

/* Widoczny fokus klawiaturowy w całej aplikacji. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* --- Awatar -------------------------------------------------------------- */
.avatar {
  position: relative;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  user-select: none;
  background: hsl(var(--hue, 250), 62%, 56%);
}
.avatar img.avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.avatar[data-status]::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 28%;
  height: 28%;
  min-width: 10px;
  min-height: 10px;
  border: 2.5px solid var(--surface);
  border-radius: 50%;
  background: var(--status-available);
}
.avatar[data-status="offline"]::after,
.avatar[data-status="none"]::after {
  display: none;
}
.avatar[data-status="available"]::after {
  background: var(--status-available);
}
.avatar[data-status="away"]::after {
  background: var(--status-away);
}
.avatar[data-status="busy"]::after {
  background: var(--status-busy);
}
.avatar[data-status="invisible"]::after {
  background: var(--status-invisible);
}

/* =========================================================================
   Ekran logowania / rejestracji
   ========================================================================= */
.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(
      1200px 600px at 50% -10%,
      var(--brand-soft),
      transparent 60%
    ),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}
.auth-brand .halo-rings {
  width: 64px;
  height: 64px;
}
.auth-brand h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.auth-brand p {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}
.auth form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth .btn-primary {
  margin-top: 4px;
}
.auth-switch {
  margin-top: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}
.auth-switch button {
  color: var(--brand);
  font-weight: 600;
  padding: 4px;
}
.auth-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 500;
  display: none;
}
.auth-error.show {
  display: block;
}

/* =========================================================================
   Powłoka aplikacji (układ)
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
  background: var(--bg);
}

/* --- Pasek boczny -------------------------------------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 14px 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-header .me {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.sidebar-header .avatar {
  width: 40px;
  height: 40px;
  font-size: 15px;
}
.sidebar-header .me-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.icon-btn svg {
  width: 21px;
  height: 21px;
}

.search-wrap {
  padding: 10px 14px;
  flex-shrink: 0;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box svg {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--text-faint);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 38px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 999px;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.search-box input::placeholder {
  color: var(--text-faint);
}
.search-box input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}

/* --- Lista rozmów -------------------------------------------------------- */
.conversations {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px 12px;
}
.conv {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s ease;
}
.conv:hover {
  background: var(--surface-hover);
}
.conv.active {
  background: var(--brand-soft);
}
.conv .avatar {
  width: 50px;
  height: 50px;
  font-size: 18px;
}
.conv-main {
  flex: 1;
  min-width: 0;
}
.conv-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.conv-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time {
  font-size: 12px;
  color: var(--text-faint);
  flex-shrink: 0;
}
.conv-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}
.conv-preview {
  font-size: 13.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.conv.unread .conv-preview {
  color: var(--text);
  font-weight: 500;
}
.badge {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
}

/* --- Stan pusty/ładowanie listy ------------------------------------------ */
.list-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* =========================================================================
   Panel rozmowy
   ========================================================================= */
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-chat);
  position: relative;
}

/* Subtelny wzór tła czatu (delikatne kropki) */
.chat::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(
    var(--border) 1px,
    transparent 1px
  );
  background-size: 22px 22px;
  opacity: 0.4;
  pointer-events: none;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 12px 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 2;
}
.chat-back {
  display: none;
}
.chat-header .avatar {
  width: 42px;
  height: 42px;
  font-size: 16px;
}
.chat-peer {
  flex: 1;
  min-width: 0;
}
.chat-peer .name {
  font-weight: 700;
  font-size: 15.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-peer .status {
  font-size: 12.5px;
  color: var(--text-muted);
}
.chat-peer .status.online {
  color: var(--online);
}

/* --- Obszar wiadomości --------------------------------------------------- */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  z-index: 1;
}
.messages-inner {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.load-more {
  align-self: center;
  margin: 6px 0 12px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.load-more:hover {
  background: var(--surface-hover);
  border-color: var(--brand);
}

.day-sep {
  align-self: center;
  margin: 14px 0 10px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow-bubble);
}

/* --- Dymki --------------------------------------------------------------- */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  position: relative;
}
.msg.in {
  align-self: flex-start;
  align-items: flex-start;
}
.msg.out {
  align-self: flex-end;
  align-items: flex-end;
}
.bubble {
  position: relative;
  padding: 8px 12px 7px;
  border-radius: var(--radius-bubble);
  box-shadow: var(--shadow-bubble);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.in .bubble {
  background: var(--recv-bg);
  color: var(--recv-text);
  border-bottom-left-radius: 6px;
}
.msg.out .bubble {
  background: var(--sent-bg);
  color: var(--sent-text);
  border-bottom-right-radius: 6px;
}
/* Łączenie kolejnych dymków od tej samej osoby. */
.msg.grouped {
  margin-top: 1px;
}
.msg:not(.grouped) {
  margin-top: 8px;
}
.bubble-text {
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.4;
}
.bubble-meta {
  display: inline-flex;
  align-items: center;
  vertical-align: baseline;
  gap: 4px;
  margin-left: 8px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  /* Lekkie obniżenie, by czas siadł równo z linią bazową tekstu. */
  position: relative;
  top: 1px;
}
/* Bez tekstu (same media/plik) — czas jako osobny pasek dosunięty w prawo. */
.bubble-meta.meta-standalone {
  display: flex;
  justify-content: flex-end;
  margin: 4px 2px 0 0;
  top: 0;
}
.msg.in .bubble-meta {
  color: var(--recv-meta);
}
.msg.out .bubble-meta {
  color: var(--sent-meta);
}
/* Znaczniki odczytu (ptaszki) */
.ticks {
  display: inline-flex;
  width: 16px;
  height: 11px;
}
.ticks svg {
  width: 16px;
  height: 11px;
}
.ticks.read {
  color: #6fe3ff;
}

/* --- Wskaźnik pisania ---------------------------------------------------- */
.typing {
  align-self: flex-start;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  margin-top: 8px;
  background: var(--recv-bg);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-bubble);
}
.typing.show {
  display: inline-flex;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing-bounce 1.3s infinite ease-in-out;
}
.typing span:nth-child(2) {
  animation-delay: 0.18s;
}
.typing span:nth-child(3) {
  animation-delay: 0.36s;
}
@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* --- Pasek wprowadzania -------------------------------------------------- */
.composer {
  flex-shrink: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 2;
}
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  min-height: 46px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 23px;
  color: var(--text);
  line-height: 1.4;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.composer textarea::placeholder {
  color: var(--text-faint);
}
.composer textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}
/* Przycisk wysyłania — sygnaturowy pierścień halo. */
.send-btn {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}
.send-btn:hover:not(:disabled) {
  background: var(--brand-strong);
}
.send-btn:active:not(:disabled) {
  transform: scale(0.92);
}
.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.send-btn svg {
  width: 22px;
  height: 22px;
}

/* =========================================================================
   Załączniki
   ========================================================================= */
.attach-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  align-self: flex-end;
}
.attach-btn svg {
  width: 22px;
  height: 22px;
}

/* Podgląd wybranych plików nad polem pisania (jeden lub wiele). */
.attachment-pending {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}
.pending-card {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 260px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.pending-loading {
  color: var(--text-muted);
}
.pending-upload-progress {
  min-width: min(360px, 100%);
  max-width: min(520px, 100%);
  align-items: center;
}
.pending-progress-body {
  flex: 1;
  min-width: 0;
}
.pending-progress-label {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pending-progress-bar {
  height: 7px;
  margin: 6px 0 4px;
  overflow: hidden;
  background: var(--border);
  border-radius: 999px;
}
.pending-progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 0.12s ease;
}
.pending-progress-meta {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pending-cancel-upload {
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--surface);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.pending-cancel-upload:hover {
  background: var(--surface-hover);
}
.pending-cancel-upload:active {
  transform: scale(0.98);
}
.pending-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.pending-fileicon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  flex-shrink: 0;
}
.pending-fileicon svg {
  width: 22px;
  height: 22px;
}
.pending-meta {
  flex: 1;
  min-width: 0;
}
.pending-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pending-size {
  font-size: 12.5px;
  color: var(--text-muted);
}
.pending-remove {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.pending-remove:hover {
  background: var(--surface-hover);
  color: var(--danger);
}
.pending-remove svg {
  width: 18px;
  height: 18px;
}
.pending-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Media w dymku (zdjęcia i wideo). */
.bubble.has-media {
  padding: 4px 4px 6px;
}
.att-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.att-image {
  display: block;
}
.att-image img {
  display: block;
  max-width: 320px;
  width: 100%;
  max-height: 380px;
  object-fit: cover;
  border-radius: 12px;
}
.bubble.has-media .bubble-text {
  padding: 4px 8px 0;
}
.bubble.has-media .bubble-meta.meta-standalone {
  padding: 0 8px;
}

/* Wideo odtwarzane w wiadomości. */
.att-video {
  position: relative;
  display: block;
  max-width: 320px;
}
.att-video video {
  display: block;
  width: 100%;
  max-width: 320px;
  max-height: 380px;
  border-radius: 12px;
  background: #000;
}
.att-video-dl {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.att-video:hover .att-video-dl,
.att-video:focus-within .att-video-dl {
  opacity: 1;
}
.att-video-dl svg {
  width: 18px;
  height: 18px;
}

/* Siatka dla kilku zdjęć w jednej wiadomości. */
.att-group.att-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  width: 320px;
  max-width: 100%;
}
.att-grid .att-image {
  width: 100%;
  height: 100%;
}
.att-grid .att-image img {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
}
.att-grid[data-count="3"] > .att-image:first-child {
  grid-column: 1 / -1;
}
.att-grid[data-count="3"] > .att-image:first-child img {
  aspect-ratio: 16 / 9;
}

/* Karta pliku w dymku. */
.att-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: 300px;
  padding: 8px 4px;
  text-decoration: none;
  color: inherit;
}
.att-file-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.msg.in .att-file-icon {
  background: var(--brand-soft);
  color: var(--brand);
}
.msg.out .att-file-icon {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}
.att-file-icon svg {
  width: 22px;
  height: 22px;
}
.att-file-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.att-file-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-file-size {
  font-size: 12px;
  opacity: 0.8;
}
.att-file-dl {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  opacity: 0.85;
}
.att-file-dl svg {
  width: 20px;
  height: 20px;
}

/* =========================================================================
   Pusty stan panelu rozmowy
   ========================================================================= */

.chat-active {
  flex: 1;
  min-height: 0;
  display: none;
  flex-direction: column;
}
.chat-active.is-visible {
  display: flex;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px;
  text-align: center;
  z-index: 1;
}
.chat-empty .halo-rings {
  width: 120px;
  height: 120px;
}
/* Pulsujące pierścienie wokół godła w pustym stanie. */
.chat-empty .pulse,
.chat-empty .pulse::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border: 2px solid var(--brand);
  border-radius: 50%;
  /* Bazowe wyśrodkowanie — także podczas opóźnienia animacji (inaczej pierścień
     z samym top/left:50% „uciekał” w prawy dolny róg). */
  transform: translate(-50%, -50%);
  animation: halo-pulse 2.8s infinite ease-out backwards;
}
.chat-empty .pulse::before {
  content: "";
  animation-delay: 1.4s;
}
.chat-empty h2 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.chat-empty p {
  color: var(--text-muted);
  max-width: 320px;
}

/* =========================================================================
   Okno modalne (nowa rozmowa)
   ========================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 16, 0.5);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop.show {
  display: flex;
}
.modal {
  width: 100%;
  max-width: 440px;
  max-height: min(640px, 86vh);
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 0.18s ease;
}
@keyframes modal-in {
  from {
    transform: translateY(12px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
}
.modal-head h3 {
  font-size: 18px;
  font-weight: 700;
}
.modal .search-wrap {
  padding: 0 18px 12px;
}
.modal-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 10px 12px;
}
.result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s ease;
}
.result:hover {
  background: var(--surface-hover);
}
.result .avatar {
  width: 44px;
  height: 44px;
  font-size: 16px;
}
.result-name {
  font-weight: 600;
}
.result-handle {
  font-size: 13px;
  color: var(--text-muted);
}
.modal-hint {
  padding: 30px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* =========================================================================
   Powiadomienia (toast)
   ========================================================================= */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(720px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  z-index: 80;
  pointer-events: none;
}
.toast {
  box-sizing: border-box;
  max-width: 100%;
  background: var(--text);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* =========================================================================
   Pasek przewijania
   ========================================================================= */
.conversations::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.modal-results::-webkit-scrollbar {
  width: 9px;
}
.conversations::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.modal-results::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.conversations::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: padding-box;
}

/* =========================================================================
   Status własny (w nagłówku paska bocznego)
   ========================================================================= */
.me .me-id {
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

/* =========================================================================
   Panel profilu (klik w swój awatar)
   ========================================================================= */
.profile-body {
  padding: 8px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  min-height: 0;
}
.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.profile-avatar {
  width: 96px;
  height: 96px;
  font-size: 38px;
}
.avatar-edit {
  position: relative;
  border-radius: 50%;
  padding: 0;
  line-height: 0;
}
.avatar-edit-badge {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  border: 3px solid var(--surface);
  border-radius: 50%;
  transition: background 0.15s ease, transform 0.08s ease;
}
.avatar-edit:hover .avatar-edit-badge {
  background: var(--brand-strong);
}
.avatar-edit:active .avatar-edit-badge {
  transform: scale(0.92);
}
.avatar-edit-badge svg {
  width: 15px;
  height: 15px;
}
.avatar-remove {
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  padding: 2px 6px;
  border-radius: 8px;
}
.avatar-remove:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.hue-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 320px;
}
.hue-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.hue-swatch:hover {
  transform: scale(1.12);
}
.hue-swatch.selected {
  border-color: var(--text);
}
.profile-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding-left: 2px;
}
.profile-section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.profile-help {
  margin: -2px 0 12px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}
.password-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 2px;
}
.password-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 2px;
}
.password-actions .btn {
  min-height: 42px;
}
.profile-message {
  min-height: 18px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}
.profile-message.error {
  color: var(--danger);
}
.profile-message.success {
  color: var(--status-available);
}


.pwa-install-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(103, 89, 255, 0.10), rgba(34, 211, 238, 0.07));
}
.pwa-install-card[hidden] {
  display: none !important;
}
.pwa-install-card .profile-help {
  margin: -2px 0 0;
}
.pwa-install-card .btn {
  align-self: flex-start;
  min-height: 42px;
}

/* Lista wyboru statusu */
.status-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.status-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s ease;
  text-align: left;
  width: 100%;
}
.status-option:hover {
  background: var(--surface-hover);
}
.status-option.selected {
  background: var(--brand-soft);
}
.status-option .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-option .label {
  font-weight: 600;
  font-size: 14.5px;
}
.status-option .desc {
  font-size: 12.5px;
  color: var(--text-muted);
}
.status-option .check {
  margin-left: auto;
  color: var(--brand);
  display: none;
}
.status-option.selected .check {
  display: grid;
  place-items: center;
}
.dot.available {
  background: var(--status-available);
}
.dot.away {
  background: var(--status-away);
}
.dot.busy {
  background: var(--status-busy);
}
.dot.invisible {
  background: var(--status-invisible);
}

/* Status rozmówcy w nagłówku czatu — kolory wg stanu. */
.chat-peer .status.s-available {
  color: var(--status-available);
}
.chat-peer .status.s-away {
  color: var(--status-away);
}
.chat-peer .status.s-busy {
  color: var(--status-busy);
}

/* =========================================================================
   Akcje wiadomości (hover / menu kontekstowe)
   ========================================================================= */
.msg-actions {
  position: absolute;
  top: -10px;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 5;
}
.msg.out .msg-actions {
  right: 8px;
}
.msg.in .msg-actions {
  left: 8px;
}
.msg:hover .msg-actions {
  display: inline-flex;
}
.msg-act {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background 0.12s ease, color 0.12s ease;
}
.msg-act:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.msg-act svg {
  width: 17px;
  height: 17px;
}

/* Menu kontekstowe (Odpowiedz / Kopiuj / Edytuj / Usuń) */
.context-menu {
  position: fixed;
  min-width: 184px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 90;
  animation: modal-in 0.12s ease;
}
.context-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  color: var(--text);
  transition: background 0.12s ease;
  text-align: left;
}
.context-item:hover {
  background: var(--surface-hover);
}
.context-item svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.context-item.danger {
  color: var(--danger);
}
.context-item.danger svg {
  color: var(--danger);
}

/* =========================================================================
   Wybór reakcji (emoji)
   ========================================================================= */
.reaction-picker {
  position: fixed;
  display: flex;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  gap: 2px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 95;
  animation: modal-in 0.12s ease;
}
.reaction-pick {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  transition: transform 0.1s ease, background 0.12s ease;
}
.reaction-pick:hover {
  background: var(--surface-hover);
  transform: scale(1.2);
}

/* Naklejki reakcji pod dymkiem */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.msg.out .reactions {
  justify-content: flex-end;
}
.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  user-select: none;
}
.reaction-chip:hover {
  background: var(--surface-hover);
}
.reaction-chip .emo {
  font-size: 14px;
}
.reaction-chip.mine {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 40%, transparent);
  color: var(--brand);
}

/* =========================================================================
   Odpowiedzi (cytowanie)
   ========================================================================= */
/* Pasek odpowiedzi nad polem pisania */
.reply-bar {
  max-width: 760px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm);
}
.reply-bar-body {
  flex: 1;
  min-width: 0;
}
.reply-bar-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--brand);
}
.reply-bar-text {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Edycja: ten sam pasek, inny akcent */
.reply-bar.editing {
  border-left-color: var(--status-away);
}
.reply-bar.editing .reply-bar-title {
  color: var(--status-away);
}

/* Cytat wewnątrz dymka */
.reply-quote {
  display: block;
  margin-bottom: 5px;
  padding: 5px 9px;
  border-radius: 9px;
  border-left: 3px solid currentColor;
  background: rgba(0, 0, 0, 0.05);
  cursor: pointer;
  max-width: 100%;
  transition: background 0.15s ease;
}
.reply-quote:hover {
  background: rgba(0, 0, 0, 0.09);
}
.msg.out .reply-quote {
  background: rgba(255, 255, 255, 0.16);
}
.msg.out .reply-quote:hover {
  background: rgba(255, 255, 255, 0.26);
}
.reply-quote .q-name {
  font-size: 12px;
  font-weight: 700;
  opacity: 0.95;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-quote .q-text {
  font-size: 12.5px;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Podświetlenie wiadomości po skoku do cytatu */
@keyframes flash-msg {
  0%,
  100% {
    background: transparent;
  }
  30% {
    background: color-mix(in srgb, var(--brand) 18%, transparent);
  }
}
.msg.flash .bubble {
  animation: flash-msg 1.4s ease;
}

/* Etykieta „edytowano” i wiadomość usunięta */
.edited-tag {
  opacity: 0.75;
  font-style: italic;
}
.bubble.deleted .bubble-text {
  color: var(--text-faint);
  font-style: italic;
}

/* =========================================================================
   Wersja mobilna — jeden panel na raz
   ========================================================================= */

/* =========================================================================
   Anty-overflow: długie nazwy i podglądy nie mogą poszerzać layoutu
   ========================================================================= */
.sidebar,
.chat,
.sidebar-header,
.sidebar-header .me,
.sidebar-header .me-id,
.conv,
.conv-main,
.conv-top,
.conv-bottom,
.chat-peer {
  min-width: 0;
}
.sidebar-header .me {
  width: 0;
  max-width: 100%;
  overflow: hidden;
}
.sidebar-header .me-id {
  flex: 1 1 0;
  width: 0;
}
.sidebar-header .me-name,
.conv-name,
.conv-preview,
.chat-peer .name {
  display: block;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}
.conv-main {
  flex: 1 1 0;
  width: 0;
  overflow: hidden;
}
.conv-top,
.conv-bottom {
  width: 100%;
  overflow: hidden;
}
.conv-name,
.conv-preview {
  flex: 1 1 0;
  width: 0;
}

@media (max-width: 768px) {
  .toasts {
    left: 12px;
    right: 12px;
    bottom: 12px;
    transform: none;
    width: auto;
    max-width: none;
  }
  .toast {
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 13px;
  }
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
  }
  /* Domyślnie widać listę; po wybraniu rozmowy aplikacja przełącza widok. */
  .app[data-view="list"] .chat {
    display: none;
  }
  .app[data-view="chat"] .sidebar {
    display: none;
  }
  .chat-back {
    display: grid;
  }
  .msg {
    max-width: 84%;
  }
  :root {
    --header-h: 58px;
  }

  /* Mobile: wymuszamy skracanie długich nazw i podglądów rozmów tak samo jak na desktopie. */
  html,
  body,
  .app,
  .sidebar,
  .chat,
  .conversations {
    max-width: 100%;
    overflow-x: hidden;
  }
  .sidebar-header {
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }
  .sidebar-header .me {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    max-width: 100%;
  }
  .sidebar-header .me-id {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    overflow: hidden;
  }
  .sidebar-header .me-name,
  .conv-name,
  .conv-preview {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .conv {
    width: 100%;
    max-width: 100%;
  }
  .conv-main {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
  }
  .conv-top,
  .conv-bottom {
    min-width: 0;
    width: 100%;
    overflow: hidden;
  }
  .conv-name,
  .conv-preview {
    flex: 1 1 0;
    width: 0;
  }
}

/* =========================================================================
   Dostępność: ograniczony ruch
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* --- 1.3.0: Znajomi i blokowanie -------------------------------------------- */
.icon-btn-badged {
  position: relative;
}
.icon-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border: 2px solid var(--surface);
}

/* Nagłówek czatu: menu po prawej */
.chat-menu-btn {
  margin-left: auto;
}

/* Baner blokady nad polem pisania */
.blocked-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
}
.blocked-banner .unblock {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--danger);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
}
.blocked-banner .unblock:hover {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

/* Zakładki w modalu znajomych */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.tab {
  position: relative;
  padding: 12px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.tab-badge {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  vertical-align: middle;
}
.tab-body {
  padding: 8px 10px 12px;
  overflow-y: auto;
  min-height: 0;
  max-height: min(440px, 60vh);
}

/* Wiersz znajomego / wyniku / zablokowanego */
.friend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.friend-row:hover {
  background: var(--surface-hover);
}
.friend-main {
  flex: 1;
  min-width: 0;
}
.friend-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.friend-handle {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.friend-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Mini-przyciski akcji */
.btn-mini {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  white-space: nowrap;
}
.btn-mini:hover {
  background: var(--surface-hover);
}
.btn-mini-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-mini-primary:hover {
  background: var(--brand-strong);
}
.btn-mini-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.btn-mini-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.btn-mini-muted {
  color: var(--text-muted);
  cursor: default;
}
.btn-mini-muted:hover {
  background: var(--surface);
}
.btn-mini[disabled] {
  opacity: 0.6;
  cursor: default;
}

/* Stan pusty i nagłówek sekcji w zakładce */
.tab-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.tab-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 10px 4px;
}
.friend-row .avatar {
  width: 44px;
  height: 44px;
  font-size: 16px;
}
.result-info {
  flex: 1;
  min-width: 0;
}

/* Strona błędu (404/403/500 itp.) — spójna z ekranem logowania. */
.error-card {
  text-align: center;
}
.error-code {
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--brand);
  margin: 10px 0 6px;
  letter-spacing: -0.02em;
}
.error-message {
  color: var(--text-muted);
  margin: 0;
}
.error-card .btn-primary {
  margin-top: 20px;
  width: 100%;
}

/* Lightbox obrazów (klik w obraz -> powiększenie na przyciemnionym tle). */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.82);
  animation: lightbox-in 0.15s ease;
}
@keyframes lightbox-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.lightbox-bar {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
}
.lightbox-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lightbox-btn:hover {
  background: rgba(255, 255, 255, 0.26);
}
.lightbox-btn svg {
  width: 20px;
  height: 20px;
}

/* Okno potwierdzenia (confirmDialog) — zastępuje natywny window.confirm. */
.confirm-modal {
  max-width: 380px;
}
.confirm-body {
  padding: 22px 22px 8px;
}
.confirm-body h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 6px;
}
.confirm-body p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 22px 20px;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 88%, black);
}

/* Wiadomość, której nie udało się wysłać (klasa .failed nadawana po błędzie ack). */
.msg.failed .bubble {
  opacity: 0.75;
  box-shadow: 0 0 0 1px var(--danger);
}
.msg.failed::after {
  content: "Nie udało się wysłać";
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--danger);
}

/* Subtelne wejście świeżo dochodzącej wiadomości (spójnie z animacjami modali
   itp.). Stosowane tylko do nowych wiadomości — przy pełnym renderze rozmowy
   nie ma kaskady. Pod prefers-reduced-motion wyłączane przez uniwersalny reset. */
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.msg-enter {
  animation: msg-in 0.18s ease;
}

@media (max-width: 560px) {

  .pwa-install-card .btn {
    width: 100%;
    align-self: stretch;
  }
  .password-actions {
    flex-direction: column-reverse;
  }
  .password-actions .btn {
    width: 100%;
  }
}

/* --- Strzałka nowych wiadomości ----------------------------------------- */
.new-messages-jump {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 8px auto 4px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-weight: 800;
  cursor: pointer;
  transform: translateX(-50%);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.new-messages-jump[hidden] {
  display: none !important;
}
.new-messages-jump:hover {
  background: var(--surface-hover);
  border-color: var(--brand);
  transform: translateX(-50%) translateY(-1px);
}
.new-messages-jump:active {
  transform: translateX(-50%) translateY(0);
}
.new-messages-arrow {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  line-height: 1;
}
.new-messages-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
}

/* =========================================================================
   Historia rozmowy
   ========================================================================= */
.modal.history-modal {
  max-width: 620px;
  width: min(620px, calc(100vw - 32px));
}
.modal-subtitle {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.35;
}
.history-search-wrap {
  padding-bottom: 10px !important;
}
.history-results {
  flex: 1;
  min-height: 220px;
  overflow-y: auto;
  padding: 0 10px 10px;
}
.history-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}
.history-item:hover,
.history-item:focus-visible {
  background: var(--surface-hover);
  outline: none;
}
.history-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.history-sender {
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-time {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 12px;
}
.history-snippet {
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.history-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
}
.history-actions {
  display: flex;
  justify-content: center;
  padding: 0 18px 16px;
}
.context-item.history svg {
  color: var(--brand);
}
@media (max-width: 720px) {
  .modal.history-modal {
    width: calc(100vw - 18px);
    max-height: 88vh;
  }
  .history-results {
    min-height: 260px;
  }
  .history-item {
    padding: 10px;
  }
}

/* =========================================================================
   Stage 7: responsywność i dostępność UI
   ========================================================================= */

/* Modale i nakładki są ukryte przed technologiami wspomagającymi, gdy nie są
   otwarte. JS przełącza aria-hidden razem z klasą .show. */
.modal-backdrop[aria-hidden="true"] {
  display: none !important;
}
.modal-backdrop.show[aria-hidden="false"] {
  display: flex;
}

/* Długie elementy w wynikach i zakładkach nie mogą poszerzać modali. */
.result-info,
.result-name,
.result-handle,
.friend-main,
.history-line {
  min-width: 0;
}
.result-name,
.result-handle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Przyciski akcji w małych modalach mogą się łamać, ale nie wychodzą poza ekran. */
.friend-actions,
.confirm-actions,
.password-actions {
  min-width: 0;
}

/* Na telefonach modale używają bezpiecznych odstępów i nie wychodzą poza viewport. */
@media (max-width: 768px) {
  .modal-backdrop {
    padding: max(10px, env(safe-area-inset-top, 0px))
      max(10px, env(safe-area-inset-right, 0px))
      max(10px, env(safe-area-inset-bottom, 0px))
      max(10px, env(safe-area-inset-left, 0px));
  }
  .modal {
    width: min(100%, calc(100vw - 20px));
    max-height: min(92dvh, 720px);
    border-radius: 18px;
  }
  .modal-head {
    gap: 12px;
  }
  .modal-head h3,
  .modal-subtitle {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .tabs {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }
  .tab {
    flex: 0 0 auto;
  }
  .friend-row {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px 12px;
  }
  .friend-row .friend-main {
    flex: 1 1 calc(100% - 56px);
  }
  .friend-row .friend-actions {
    width: 100%;
    max-width: none;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 8px;
    justify-content: stretch;
  }
  .friend-row .btn-mini {
    min-width: 0;
    min-height: 36px;
    white-space: nowrap;
    text-align: center;
    padding-left: 10px;
    padding-right: 10px;
  }
  .result .friend-actions {
    flex-wrap: nowrap;
    max-width: 42%;
  }
  .result .btn-mini {
    white-space: nowrap;
  }
  .confirm-actions {
    flex-direction: column-reverse;
  }
  .confirm-actions .btn {
    width: 100%;
  }
  .attachment-pending {
    max-height: min(35dvh, 260px);
    overflow-y: auto;
    padding-right: 2px;
  }
  .pending-card,
  .pending-upload-progress {
    max-width: 100%;
    width: 100%;
  }
  .att-image img,
  .att-video,
  .att-video video,
  .att-group.att-grid {
    max-width: min(100%, 82vw);
  }
  .att-file {
    min-width: 0;
    max-width: min(100%, 82vw);
  }
  .new-messages-jump {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 420px) {
  .sidebar-header {
    gap: 8px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .icon-btn {
    width: 38px;
    height: 38px;
  }
  .chat-header {
    gap: 8px;
  }
  .msg {
    max-width: 88%;
  }
  .composer {
    padding-left: 8px;
    padding-right: 8px;
  }
  .composer-inner {
    gap: 7px;
  }
  .composer textarea {
    padding-left: 13px;
    padding-right: 13px;
  }
  .attach-btn,
  .send-btn {
    width: 42px;
    height: 42px;
  }
  .history-time {
    width: 100%;
    margin-left: 0;
  }
  .history-line {
    flex-wrap: wrap;
  }
}


@media (max-width: 380px) {
  .friend-row .friend-actions {
    grid-auto-flow: row;
    grid-auto-rows: minmax(36px, auto);
  }
  .result .friend-actions {
    max-width: 38%;
  }
  .result .btn-mini {
    padding-left: 8px;
    padding-right: 8px;
  }
}

.pwa-install-card .btn {
  width: 100%;
}

.push-card {
  border: 1px solid rgba(124, 92, 255, 0.18);
  border-radius: 18px;
  padding: 16px;
  background: rgba(124, 92, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.push-card[hidden] {
  display: none !important;
}

.push-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.push-actions .btn {
  flex: 1 1 150px;
}
