/* PIX-Hi Chat — Modern mobile-first (EN / LTR / Profiles / Lightbox) */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --crimson: #dc143c;
  --burgundy: #800020;
  --deep: #4a0e1c;
  --bg: #0d0709;
  --panel: #171013;
  --panel-2: #1f1418;
  --theirs: #26222a;
  --text: #f5f0f1;
  --muted: #9a8a8e;
  --green: #22c55e;
  --blue: #6ab7ff;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(128,0,32,.25), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(220,20,60,.12), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid #35222a; border-radius: 12px; padding: 14px 16px; outline: none; width: 100%; }
input:focus, select:focus { border-color: var(--crimson); box-shadow: 0 0 0 3px rgba(220,20,60,.15); }
::placeholder { color: #6d5f63; }
.muted { color: var(--muted); font-size: .85rem; }
.small { font-size: .75rem; }
.center { text-align: center; }
.error { color: #ff6b6b; font-size: .85rem; min-height: 1.2em; }
.new-chat-error { padding: 0 14px; }
.pad { padding: 30px 20px; }

/* ===== Buttons ===== */
.btn-primary {
  min-height: 50px; border-radius: 14px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--burgundy), var(--crimson));
  box-shadow: 0 6px 18px rgba(220,20,60,.25);
  transition: transform .12s ease, filter .12s ease;
}
.btn-primary:active { transform: scale(.98); filter: brightness(1.1); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--muted);
  border: 1px solid #35222a; background: rgba(255,255,255,.03);
  font-size: 1.2rem; line-height: 1;
}
.icon-btn:hover { color: #ff8fa3; border-color: var(--crimson); }

/* ===== Avatars ===== */
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--deep), var(--crimson));
  border: 1px solid rgba(220,20,60,.4);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar-sm { width: 36px; height: 36px; font-size: .95rem; }
.avatar-xl { width: 110px; height: 110px; font-size: 2.6rem; }

/* ===== Login ===== */
#view-login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: min(92vw, 380px);
  background: linear-gradient(180deg, rgba(31,20,24,.9), rgba(23,16,19,.9));
  border: 1px solid #3a2028; border-radius: 24px;
  padding: 34px 26px; display: flex; flex-direction: column; gap: 14px; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.5), 0 0 40px rgba(128,0,32,.15);
  backdrop-filter: blur(8px);
}
.logo {
  width: 72px; height: 72px; margin: 0 auto; border-radius: 22px;
  display: grid; place-items: center; font-size: 34px;
  background: linear-gradient(135deg, var(--burgundy), var(--crimson));
  box-shadow: 0 10px 26px rgba(220,20,60,.35);
}
.login-card h1 { font-size: 1.6rem; letter-spacing: .3px; }
.login-card .tag { color: var(--muted); font-size: .9rem; margin-top: -6px; }

/* ===== App shell ===== */
#view-app { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(23,16,19,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid #2c1a20;
}
.brand { font-weight: 800; margin-right: auto; }
.peer { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; text-align: left; }
.peer-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#peer-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { display: flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; flex: none; }
.dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ===== Conversations list ===== */
.new-chat { display: flex; gap: 8px; padding: 12px 14px 4px; }
.new-chat input { flex: 1; }
.small-btn { width: 52px; min-height: 48px; border-radius: 12px; font-size: 1.3rem; line-height: 1; flex: none; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border-bottom: 1px solid #241418; border-radius: 0;
}
.conv-row:hover, .conv-row:active { background: rgba(220,20,60,.05); }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name { font-weight: 700; }
.conv-time { font-size: .68rem; color: var(--muted); flex: none; }
.conv-bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conv-preview { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--crimson); color: #fff; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center; flex: none;
}

/* ===== Chat ===== */
.scroll-area { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; min-height: 0; overscroll-behavior: contain; }
.load-older { align-self: center; padding: 8px 16px; border-radius: 999px; border: 1px solid #3a2028; color: var(--muted); font-size: .78rem; flex: none; background: rgba(255,255,255,.02); }
#messages { display: flex; flex-direction: column; gap: 10px; }
.msg {
  max-width: 82%;
  width: fit-content;
  display: flex; flex-direction: column; gap: 4px;
}
.msg.mine { margin-left: auto; align-items: flex-end; }
.msg.theirs { margin-right: auto; align-items: flex-start; }

/* FIX: no pre-wrap here! pre-wrap moved to .cap only */
.bubble {
  padding: 10px 14px;
  line-height: 1.45;
  border-radius: 18px;
  font-size: .95rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  position: relative;
  max-width: 100%;
}
/* FIX: user text keeps its line breaks here only */
.cap {
  white-space: pre-wrap;
  word-break: break-word;
}
.mine .bubble { background: linear-gradient(135deg, var(--burgundy), var(--crimson)); border-bottom-right-radius: 6px; color: #fff; }
.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 6px; }
.msg.archived .bubble { opacity: .85; outline: 1px dashed #553a42; }
.meta { font-size: .68rem; color: var(--muted); display: flex; gap: 6px; align-items: center; padding: 0 4px; }
.ticks.read { color: var(--blue); }

/* Image messages */
.bubble.has-img { padding: 6px; }
.msg-img {
  display: block; width: 100%; max-width: 240px; border-radius: 12px;
  margin: 0 auto; cursor: zoom-in; background: #000;
}
.bubble.has-img .cap { display: block; padding: 6px 8px 4px; }

/* ===== Visual Reply Block (WhatsApp/Telegram style) ===== */
.reply-block {
  background: rgba(0,0,0,0.2);
  border-left: 3px solid rgba(255,255,255,0.5);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 0.82rem;
  line-height: 1.3;
  max-width: 100%;
  overflow: hidden;
  white-space: normal;
}
.mine .reply-block {
  background: rgba(0,0,0,0.25);
  border-left-color: rgba(255,255,255,0.7);
}
.theirs .reply-block {
  background: rgba(0,0,0,0.3);
  border-left-color: var(--crimson);
}
.reply-name {
  display: block;
  font-weight: 700;
  font-size: 0.75rem;
  margin-bottom: 2px;
}
.mine .reply-name { color: #ffd6e0; }
.theirs .reply-name { color: var(--crimson); }
.reply-text {
  display: block;
  color: var(--text);
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.send-bar {
  display: flex; gap: 8px; padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-b));
  background: rgba(23,16,19,.9); backdrop-filter: blur(10px);
  border-top: 1px solid #2c1a20;
}
.send-bar input { border-radius: 999px; padding: 13px 18px; flex: 1; }
.btn-attach {
  width: 50px; height: 50px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted);
  border: 1px solid #35222a; background: rgba(255,255,255,.03);
}
.btn-attach:hover { color: var(--crimson); border-color: var(--crimson); }
.btn-attach svg { width: 22px; height: 22px; }
.btn-send {
  width: 50px; height: 50px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--burgundy), var(--crimson));
  box-shadow: 0 6px 16px rgba(220,20,60,.3);
}
.btn-send:active { transform: scale(.94); }
.btn-send svg { width: 20px; height: 20px; }

/* ===== Profile ===== */
.profile-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 40px 20px; overflow-y: auto; text-align: center;
}
#prof-name { font-size: 1.4rem; }
.profile-actions { display: flex; flex-direction: column; gap: 10px; width: min(90%, 320px); margin-top: 14px; }

/* ===== Lightbox ===== */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5,2,3,.94); backdrop-filter: blur(6px);
  display: flex; flex-direction: column;
}
.lb-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.lb-actions { display: flex; align-items: center; gap: 8px; }
.lb-zoom-label { color: var(--muted); font-size: .8rem; min-width: 46px; text-align: center; }
.lb-stage {
  flex: 1; overflow: hidden; display: grid; place-items: center;
  touch-action: none; cursor: grab; min-height: 0;
}
.lb-stage.dragging { cursor: grabbing; }
.lb-img {
  max-width: 92%; max-height: 92%; border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  transform-origin: center center;
  user-select: none; -webkit-user-drag: none;
  will-change: transform;
}
.lb-hint { padding: 8px 12px calc(8px + var(--safe-b)); }

/* ===== Scrollbars ===== */
.scroll-area::-webkit-scrollbar, .conv-list::-webkit-scrollbar, .profile-card::-webkit-scrollbar { width: 6px; }
.scroll-area::-webkit-scrollbar-thumb, .conv-list::-webkit-scrollbar-thumb, .profile-card::-webkit-scrollbar-thumb { background: #3a2028; border-radius: 3px; }

/* ===== Reactions ===== */
.reaction {
  position: absolute;
  bottom: -8px;
  right: -4px;
  background: var(--panel-2);
  border: 1px solid var(--burgundy);
  border-radius: 12px;
  padding: 2px 6px;
  font-size: 14px;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  pointer-events: none;
}
.msg.mine .reaction {
  right: auto;
  left: -4px;
}

/* ===== Reply Preview (Above Input) ===== */
.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-2);
  border-left: 3px solid var(--crimson);
  margin: 0 12px 8px;
  padding: 8px 12px;
  border-radius: 8px;
  gap: 10px;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.reply-preview-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}
.reply-preview-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--crimson);
  margin-bottom: 2px;
}
.reply-preview-text {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-preview-close {
  color: var(--muted);
  font-size: 16px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.15s;
  flex: none;
}
.reply-preview-close:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

/* ===== Desktop ===== */
@media (min-width: 760px) {
  #view-app { border-left: 1px solid #2c1a20; border-right: 1px solid #2c1a20; }
  .msg { max-width: 65%; }
}
