:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-light: #273549;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --danger: #ef4444;
  --bubble-me: #6366f1;
  --bubble-other: #334155;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Ekran logowania / rejestracji ---- */
.auth-box {
  background: var(--panel);
  padding: 40px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

.auth-box h1 {
  margin: 0 0 4px;
  font-size: 24px;
  text-align: center;
}

.auth-box p.subtitle {
  color: var(--muted);
  text-align: center;
  margin: 0 0 28px;
  font-size: 14px;
}

.field { margin-bottom: 16px; }
.field label { display:block; margin-bottom:6px; font-size:13px; color:var(--muted); }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: var(--panel-light);
  color: var(--text);
  font-size: 14px;
}
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }

button.primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
button.primary:hover { background: var(--accent-hover); }

.switch-link {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}
.switch-link a { color: var(--accent); text-decoration: none; cursor: pointer; }

.error-msg {
  background: rgba(239,68,68,.15);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.error-msg.show { display: block; }

.success-msg {
  background: rgba(34,197,94,.15);
  color: #86efac;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.success-msg.show { display: block; }

/* ---- Czat ---- */
.app-shell {
  width: 100%;
  height: 100vh;
  display: flex;
  overflow: hidden;
}

.chat-app {
  flex: 1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid #334155;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-header h1 { margin:0; font-size: 17px; }
.chat-header .user-info { display:flex; align-items:center; gap:14px; font-size: 13px; color: var(--muted); }
.chat-header a { color: var(--muted); text-decoration:none; }
.chat-header button.logout {
  background: none; border: 1px solid #334155; color: var(--muted);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { max-width: 60%; display: flex; flex-direction: column; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.other { align-self: flex-start; align-items: flex-start; }

.msg .author { font-size: 11px; color: var(--muted); margin-bottom: 3px; padding: 0 4px; }
.msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.me .bubble { background: var(--bubble-me); color: white; border-bottom-right-radius: 4px; }
.msg.other .bubble { background: var(--bubble-other); border-bottom-left-radius: 4px; }
.msg .time { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 4px; }

.composer {
  padding: 16px 20px;
  background: var(--panel);
  border-top: 1px solid #334155;
  display: flex;
  gap: 10px;
}
.composer textarea {
  flex: 1;
  resize: none;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #334155;
  background: var(--panel-light);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  max-height: 100px;
}
.composer textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.composer button {
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.composer button:hover { background: var(--accent-hover); }
.composer button:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Panel znajomych ---- */
.friends-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.friends-overlay.show { display: flex; }

.friends-panel {
  background: var(--panel);
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  border-radius: 16px;
  padding: 24px;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.friends-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.friends-panel-header h2 { margin: 0; font-size: 18px; }
.close-btn {
  background: none; border: none; color: var(--muted); font-size: 18px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.close-btn:hover { background: var(--panel-light); color: var(--text); }

.my-id-box {
  background: var(--panel-light);
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 14px;
}
.my-id-box strong { color: var(--accent); font-size: 16px; }
.my-id-hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

.add-friend-form { display: flex; gap: 8px; margin-bottom: 8px; }
.add-friend-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: var(--panel-light);
  color: var(--text);
  font-size: 14px;
}
.add-friend-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.add-friend-form button {
  padding: 0 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.add-friend-form button:hover { background: var(--accent-hover); }

.friends-error {
  color: #fca5a5;
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 12px;
}

.friends-section { margin-top: 20px; }
.friends-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
  letter-spacing: .03em;
}

.friend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--panel-light);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 14px;
}
.friend-row .friend-name { font-weight: 500; }
.friend-row .friend-id { color: var(--muted); font-size: 12px; margin-left: 6px; }
.friend-row .row-actions { display: flex; gap: 6px; }
.friend-row button {
  border: none; border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.btn-accept { background: rgba(34,197,94,.15); color: #86efac; }
.btn-decline, .btn-remove { background: rgba(239,68,68,.15); color: #fca5a5; }

.empty-hint { color: var(--muted); font-size: 13px; margin: 0; }

/* ---- Sidebar (lista czatów) ---- */
.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid #334155;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-top { padding: 16px 16px 12px; border-bottom: 1px solid #334155; }
.whoami-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.whoami-row #whoami { font-size: 14px; font-weight: 600; }
.icon-btn {
  background: none; border: 1px solid #334155; color: var(--muted);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.sidebar-top a {
  display: block; color: var(--muted); text-decoration: none; font-size: 13px; margin-top: 4px;
}
.sidebar-top a:hover { color: var(--text); }

.sidebar-search { padding: 12px 16px; }
.sidebar-search input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: var(--panel-light);
  color: var(--text);
  font-size: 13px;
}
.sidebar-search input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.new-chat-btn {
  margin: 0 16px 12px;
  padding: 9px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.new-chat-btn:hover { background: var(--accent-hover); }
.new-chat-btn.secondary {
  background: var(--panel-light);
  color: var(--text);
  border: 1px solid #334155;
  margin-top: -4px;
}
.new-chat-btn.secondary:hover { background: #334155; }

.account-msg { font-size: 13px; min-height: 18px; margin-bottom: 10px; }
.account-msg.error { color: #fca5a5; }
.account-msg.success { color: #86efac; }

.conversation-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
}
.conv-item:hover { background: var(--panel-light); }
.conv-item.active { background: var(--panel-light); }

.conv-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: white; flex-shrink: 0;
}
.conv-avatar.global { background: #334155; }

.conv-info { flex: 1; min-width: 0; }
.conv-name-row { display: flex; align-items: center; gap: 5px; }
.conv-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.pin-btn {
  background: none; border: none; cursor: pointer; font-size: 15px;
  color: #475569; flex-shrink: 0; padding: 4px;
}
.pin-btn.pinned { color: #facc15; }
.pin-btn:hover { color: #facc15; }

.role-icon { font-size: 12px; }

/* ---- Reakcje i kasowanie wiadomości ---- */
.msg { position: relative; max-width: 70%; }
.msg.me .msg-with-avatar { flex-direction: row-reverse; }
.msg.me .author, .msg.me .time { text-align: right; }
.msg .bubble-row { display: flex; align-items: flex-end; gap: 6px; }
.msg.me .bubble-row { flex-direction: row-reverse; }

.msg-actions {
  display: flex; gap: 2px; opacity: 0; transition: opacity .1s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  background: var(--panel-light); border: 1px solid #334155; color: var(--muted);
  border-radius: 6px; width: 24px; height: 24px; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.msg-actions button:hover { color: var(--text); }
.msg-actions .delete-btn:hover { color: #fca5a5; border-color: #ef4444; }

.reaction-picker {
  position: absolute;
  bottom: 100%;
  background: var(--panel);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 6px;
  display: none;
  gap: 2px;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.reaction-picker.show { display: flex; }
.reaction-picker button {
  background: none; border: none; font-size: 17px; cursor: pointer;
  padding: 4px 6px; border-radius: 6px;
}
.reaction-picker button:hover { background: var(--panel-light); }

.reactions-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.msg.me .reactions-row { justify-content: flex-end; }
.reaction-chip {
  background: var(--panel-light);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1px 8px;
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; gap: 4px;
}
.reaction-chip.mine { border-color: var(--accent); background: rgba(99,102,241,.15); }
.reaction-chip:hover { border-color: var(--accent); }

/* ---- Awatar przy wiadomości ---- */
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white;
  cursor: pointer; margin-top: 2px;
}
.msg-avatar:hover { outline: 2px solid var(--accent); }
.msg-with-avatar { display: flex; gap: 8px; align-items: flex-start; }
.msg-with-avatar .msg-body { flex: 1; min-width: 0; }

/* ---- Popup profilu użytkownika ---- */
.profile-panel { max-width: 340px; }
.profile-avatar-big {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700; color: white;
  margin: 0 auto 14px;
}
.profile-name { text-align: center; font-size: 17px; font-weight: 700; margin-bottom: 2px; }
.profile-username { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.profile-role-line { text-align: center; margin-bottom: 16px; font-size: 13px; }
.profile-fields { display: flex; flex-direction: column; gap: 10px; }
.profile-field {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel-light); padding: 10px 12px; border-radius: 10px; font-size: 13px;
}
.profile-field .label { color: var(--muted); }
.profile-field .value { font-weight: 600; }
.profile-actions { display: flex; gap: 8px; margin-top: 14px; }
.profile-actions button {
  flex: 1; border: none; border-radius: 8px; padding: 9px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.btn-block { background: rgba(239,68,68,.15); color: #fca5a5; }
.btn-message { background: var(--accent); color: white; }

/* ---- Kategorie w liście czatów ---- */
.conv-category-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 14px 10px 6px; font-weight: 700;
}
.conv-category-label:first-child { padding-top: 6px; }

.conv-avatar-img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.msg-avatar-img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; cursor: pointer; margin-top: 2px; flex-shrink: 0; }

.badge-18 { background: rgba(239,68,68,.2); color: #fca5a5; font-size: 10px; padding: 1px 6px; border-radius: 5px; margin-left: 4px; }
.badge-group { background: rgba(99,102,241,.2); color: #a5b4fc; font-size: 10px; padding: 1px 6px; border-radius: 5px; margin-left: 4px; }

/* ---- Załączniki ---- */
.attach-btn {
  background: none; border: none; color: var(--muted); font-size: 20px;
  cursor: pointer; padding: 0 4px; flex-shrink: 0;
}
.attach-btn:hover { color: var(--text); }

.attachment-preview {
  margin: 0 20px; padding: 8px 12px; background: var(--panel-light);
  border-radius: 10px; display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.attachment-preview .remove-att { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; }
.attachment-preview img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }

.msg-attachment-img {
  max-width: 260px; max-height: 260px; border-radius: 12px; cursor: pointer; display: block;
}
.msg-attachment-file {
  display: flex; align-items: center; gap: 8px; background: var(--panel-light);
  border: 1px solid #334155; border-radius: 10px; padding: 10px 14px; text-decoration: none; color: var(--text); font-size: 13px;
}
.msg-attachment-file .file-icon { font-size: 20px; }

/* ---- Edycja wiadomości ---- */
.edit-btn:hover { color: #a5b4fc; border-color: var(--accent); }
.edited-tag { color: var(--muted); font-size: 10px; margin-left: 4px; }
.edit-textarea {
  width: 100%; min-width: 200px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--accent); background: var(--panel-light); color: var(--text);
  font-family: inherit; font-size: 14px; resize: vertical;
}
.edit-actions { display: flex; gap: 6px; margin-top: 6px; }
.edit-actions button { border: none; border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.edit-save { background: var(--accent); color: white; }
.edit-cancel { background: var(--panel-light); color: var(--muted); }

.premium-lock-hint {
  font-size: 11px; color: #7dd3fc; margin-top: 2px; cursor: default;
}

/* ---- Awatar w koncie + cropper ---- */
.avatar-editor { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.avatar-current {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: white;
}
img.avatar-current { background: none; }

.crop-stage { display: flex; justify-content: center; margin: 12px 0; }
#cropCanvas { border-radius: 50%; background: #000; cursor: grab; touch-action: none; }
#zoomSlider { width: 100%; margin: 10px 0; }

.blocked-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--panel-light); border-radius: 10px; margin-bottom: 6px; font-size: 13px;
}
