:root {
  --bg: #f6f4f1;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #7a7670;
  --line: #e7e2db;
  --her: #ffffff;
  --her-text: #1d1d1f;
  --me: #2f6f62;
  --me-text: #ffffff;
  --accent: #2f6f62;
  --danger: #b3261e;
  --shadow: 0 1px 1px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a20; --text: #ecebe8; --muted: #8d8a85; --line: #262a31;
    --her: #1e222a; --her-text: #ecebe8; --me: #3d8b7b; --me-text: #fff; --accent: #5fb3a1;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a20; --text: #ecebe8; --muted: #8d8a85; --line: #262a31;
  --her: #1e222a; --her-text: #ecebe8; --me: #3d8b7b; --me-text: #fff; --accent: #5fb3a1; --shadow: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { overscroll-behavior-x: none; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

.screen { height: 100dvh; display: flex; flex-direction: column; }
/* tastatura ca pe WhatsApp: ecranul se strânge deasupra ei (pe iPhone, după visualViewport), antetul rămâne sus */
#chat { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); }

/* login */
#login { align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { font-size: 22px; font-weight: 600; margin: 4px 0 8px; }
.login-dot { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto;
  background: radial-gradient(circle at 35% 35%, #8fd3c3, var(--accent)); }
.login-card input { padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font-size: 17px; }
.login-card button { padding: 14px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }

/* header */
header { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--bg); }
.who { display: flex; align-items: center; gap: 10px; text-align: left; padding: 4px; min-width: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 35%, #8fd3c3, var(--accent)); }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.name { font-weight: 600; font-size: 17px; }
.status { font-size: 13px; color: var(--muted); min-height: 1.2em; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; font-size: 20px; color: var(--muted); }
.banner { padding: 10px 16px; font-size: 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.banner button { color: var(--accent); font-weight: 600; margin-left: 6px; }

/* listă */
main { flex: 1; overflow-y: auto; padding: 12px 16px 8px; overscroll-behavior: contain; }
.older { text-align: center; margin-bottom: 8px; }
.older button { color: var(--muted); font-size: 13px; padding: 6px 10px; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 8px; }
.msg { display: flex; flex-direction: column; margin: 2px 0; max-width: 100%; }
.msg.me { align-items: flex-end; }
.msg.her { align-items: flex-start; }
.bubble { position: relative; max-width: min(78%, 560px); padding: 8px 12px; border-radius: 18px; white-space: pre-wrap;
  overflow-wrap: anywhere; box-shadow: var(--shadow); user-select: text; -webkit-touch-callout: none; }
.her .bubble { background: var(--her); color: var(--her-text); border-bottom-left-radius: 6px; }
.me .bubble { background: var(--me); color: var(--me-text); border-bottom-right-radius: 6px; }
.msg.cont.her .bubble { border-top-left-radius: 6px; }
.msg.cont.me .bubble { border-top-right-radius: 6px; }
.msg.gap { margin-top: 10px; }
.bubble img.drawing { display: block; width: 220px; max-width: 100%; height: auto; border-radius: 12px; background: #fff; }
.bubble.svg { padding: 6px; }
.meta { font-size: 11px; color: var(--muted); margin: 2px 6px 0; }
.pending .bubble { opacity: .6; }
.failed .bubble { outline: 1px solid var(--danger); }
.meta button.inline { font-size: 11px; color: var(--accent); font-weight: 600; padding: 2px 0; text-decoration: underline; }
.offline { position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 30;
  padding: 6px 14px; border-radius: 14px; font-size: 13px; background: var(--panel); color: var(--muted); box-shadow: var(--shadow); }
.reaction { position: absolute; bottom: -10px; font-size: 14px; background: var(--panel); border-radius: 12px;
  padding: 0 4px; box-shadow: var(--shadow); line-height: 20px; }
.her .reaction { right: -8px; }
.me .reaction { left: -8px; }
.msg.has-reaction { margin-bottom: 12px; }

.typing { display: inline-flex; gap: 4px; padding: 12px 14px; background: var(--her); border-radius: 18px;
  border-bottom-left-radius: 6px; margin: 4px 0; box-shadow: var(--shadow); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
.typing.thinking span { animation-duration: 2.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
/* „↓ N mesaje noi” cât el e sus în conversație: lipită de marginea de jos, fără să ocupe loc în listă */
.newmsgs-dock { position: sticky; bottom: 0; height: 0; z-index: 2; }
.newmsgs { position: absolute; right: 0; bottom: 8px; padding: 6px 12px; border-radius: 16px; font-size: 13px;
  font-weight: 600; background: var(--panel); color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.18); }

/* compunere */
#composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
/* cu tastatura deschisă (iPhone), marginea de jos a ecranului e sub ea: fără golul de ~34 px */
.kb #composer { padding-bottom: 8px; }
#input { flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-size: 16px; line-height: 1.35; }
#input:focus { outline: none; border-color: var(--accent); }
#send { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 17px; flex: none; }

/* panou */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; z-index: 10; }
.sheet-card { width: 100%; max-height: 88dvh; background: var(--panel); border-radius: 18px 18px 0 0; display: flex;
  flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.tabs { display: flex; align-items: center; gap: 4px; padding: 8px 8px 0 12px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 10px; color: var(--muted); border-bottom: 2px solid transparent; font-size: 15px; }
.tab.active { color: var(--text); border-color: var(--accent); }
#sheet-close { margin-left: auto; }
.tab-body { overflow-y: auto; padding: 14px 16px 24px; font-size: 15px; }
.tab-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
.tab-body p { margin: 6px 0; white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 14px 0 6px; }
.wide { width: 100%; padding: 12px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; margin: 4px 0; }
.wide.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
a.link-btn { display: block; text-align: center; text-decoration: none; }
.dec { border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.dec .t { color: var(--muted); font-size: 12px; }
.dec .a { font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv span:nth-child(odd) { color: var(--muted); }

.picker { position: fixed; z-index: 20; display: flex; gap: 2px; background: var(--panel); border-radius: 24px; padding: 4px;
  box-shadow: 0 4px 18px rgba(0,0,0,.18); }
.picker button { font-size: 24px; width: 42px; height: 42px; border-radius: 50%; }
.picker button:active { background: var(--line); }

/* swipe to reply (cercetarea: docs/pagini/2026-11-15-swipe-to-reply.html din mira; cifrele din Signal și Telegram) */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body.swiping #list { overflow-x: clip; overflow-clip-margin: 8px; }
#list .msg[data-id] { position: relative; touch-action: pan-y pinch-zoom; }
.msg > .bubble { z-index: 1; }
.msg.swiping > .bubble, .msg.swiping > .meta,
.msg.settling > .bubble, .msg.settling > .meta { transform: translateX(var(--sx, 0px)); }
.msg.swiping > .bubble, .msg.swiping > .meta { will-change: transform; }
.msg.settling > .bubble, .msg.settling > .meta { transition: transform .2s cubic-bezier(.25,1,.5,1); }
.msg.swiping::before, .msg.settling::before {
  content: "↩"; position: absolute; z-index: 0; pointer-events: none;
  left: var(--ix, 8px); top: calc(50% - 16px); width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; background: var(--panel); color: var(--muted); box-shadow: var(--shadow);
  opacity: var(--sp, 0); font-size: 16px;
  transform: translateX(calc(var(--sx, 0px) / 8)) scale(calc(.6 + .4 * var(--sp, 0)));
}
.msg.settling::before { transition: opacity .2s; }
.msg.armed::before { color: var(--accent); animation: reply-pop .2s ease-out; }
@keyframes reply-pop { 50% { transform: translateX(calc(var(--sx, 0px) / 8)) scale(1.25); } }
body.swiping { -webkit-user-select: none; user-select: none; }
.msg.flash { animation: row-flash 1.5s ease-out; border-radius: 12px; }
@keyframes row-flash { 0%, 25% { background: color-mix(in srgb, var(--accent) 18%, transparent); } to { background: transparent; } }

/* citatul din bulă */
.bubble .quote { display: block; width: 100%; text-align: left; margin: 0 0 6px; padding: 4px 8px; border-radius: 8px;
  border-left: 3px solid var(--accent); background: rgba(0,0,0,.06); white-space: normal; min-width: 120px; }
.me .bubble .quote { background: rgba(255,255,255,.16); border-left-color: rgba(255,255,255,.75); color: var(--me-text); }
.bubble .quote.mine { border-left-color: var(--me); }
.me .bubble .quote.mine { border-left-color: rgba(255,255,255,.75); }
.quote .q-name { display: block; font-size: 12.5px; font-weight: 600; color: var(--accent); }
.me .quote .q-name { color: var(--me-text); }
.quote .q-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 13.5px; opacity: .85; overflow-wrap: anywhere; }

/* bara de deasupra compunerii */
.replybar { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-top: 1px solid var(--line);
  background: var(--bg); }
.rb-body { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 4px 10px; border-left: 4px solid var(--accent);
  border-radius: 6px; background: var(--panel); }
.replybar.me .rb-body { border-left-color: var(--me); }
.rb-name { font-size: 13px; font-weight: 600; color: var(--accent); }
.replybar.me .rb-name { color: var(--me); }
.rb-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.replybar:not([hidden]) + .sr-only + #composer { border-top: 0; }

/* desktop: ↩ la hover, pe partea liberă */
.reply-btn { display: none; }
@media (hover: hover) and (pointer: fine) {
  .reply-btn { display: grid; place-items: center; position: absolute; top: 50%; transform: translateY(-50%);
    width: 28px; height: 28px; border-radius: 50%; color: var(--muted); background: var(--panel); box-shadow: var(--shadow);
    opacity: 0; transition: opacity .12s; font-size: 14px; }
  .her .reply-btn { right: -36px; }
  .me .reply-btn { left: -36px; }
  .msg:hover .reply-btn, .msg:focus-within .reply-btn { opacity: 1; }
}
.picker .pk-reply { font-size: 20px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  .msg.settling > *, .msg.settling::before { transition: none; }
  .msg.armed::before, .msg.flash { animation: none; }
}
