:root {
  --bg: #f4f1ec; --panel: #ffffff; --ink: #0c1114; --muted: #6b7178; --line: #e6e1d9;
  --gold: #b88a00; --mine: #e8f3e4; --theirs: #ffffff; --accent: #0c1114;
  --wa: #25a35a; --tg: #2a8bd8; --max: #6b4cf0; --luna: #7a5cff;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
button { font: inherit; cursor: pointer; }
.link { background: none; border: 0; color: var(--muted); padding: 4px 6px; }
.link:hover { color: var(--ink); }

.app { display: grid; grid-template-columns: 360px 1fr; height: 100dvh; }
.side { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
.side__top { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.brand { font-weight: 600; font-size: 16px; }
.brand__sub { color: var(--muted); font-weight: 400; }
.filters { padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
.search { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #faf8f5; font: inherit; }
.tabs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 13px; color: var(--muted); }
.tab.is-on { background: var(--ink); color: #fff; border-color: var(--ink); }

.chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid #f1ede7; cursor: pointer; }
.chat-row:hover { background: #faf8f5; }
.chat-row.is-on { background: #f1ede6; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot--whatsapp { background: var(--wa); } .dot--telegram { background: var(--tg); } .dot--max { background: var(--max); }
.chat-row__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row__last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row__side { text-align: right; font-size: 12px; color: var(--muted); }
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; margin-top: 4px; border-radius: 10px; background: var(--wa); color: #fff; font-weight: 600; text-align: center; }
.luna { padding: 10px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.luna b { color: var(--luna); }

.main { position: relative; min-height: 0; display: flex; }
.empty { margin: auto; color: var(--muted); }
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat__top { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat__name { font-weight: 600; }
.chat__meta { color: var(--muted); font-size: 13px; }
.back { display: none; background: none; border: 0; font-size: 20px; padding: 0 6px; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 18px 8px; }
.older { display: block; margin: 0 auto 12px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; color: var(--muted); font-size: 13px; }
.day { text-align: center; margin: 14px 0 8px; font-size: 12px; color: var(--muted); }
.msg { display: flex; margin: 4px 0; }
.msg.me { justify-content: flex-end; }
.bubble { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 12px; background: var(--theirs); box-shadow: 0 1px 0 rgba(0,0,0,.06); overflow-wrap: anywhere; }
.me .bubble { background: var(--mine); }
.msg.luna .bubble { background: #efeaff; }
.bubble__who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.luna .bubble__who { color: var(--luna); font-weight: 600; }
.bubble__text { white-space: pre-wrap; }
.bubble__time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble img.media { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; margin-bottom: 4px; cursor: zoom-in; }
.bubble video { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; margin-bottom: 4px; }
.bubble audio { display: block; width: 260px; max-width: 100%; margin: 2px 0 4px; }
.file { display: inline-block; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); text-decoration: none; margin-bottom: 4px; }
.compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.compose textarea { flex: 1; resize: none; max-height: 160px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: #faf8f5; }
.attach { font-size: 20px; padding: 6px; cursor: pointer; }
.send { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--ink); color: #fff; font-size: 16px; }
.send:disabled { opacity: .4; }
.sending { padding: 4px 18px 8px; font-size: 12px; color: var(--muted); background: var(--panel); }
.error { color: #b3261e; }

.login-page { display: flex; align-items: center; justify-content: center; }
.login { width: min(340px, 92vw); background: #fff; padding: 24px; border-radius: 14px; box-shadow: 0 6px 30px rgba(0,0,0,.08); display: grid; gap: 14px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--ink); }
.login button { padding: 11px; border: 0; border-radius: 8px; background: var(--ink); color: #fff; font-weight: 600; }
.err { color: #b3261e; margin: 0; min-height: 1em; font-size: 13px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .main { display: none; }
  .app.in-chat .side { display: none; }
  .app.in-chat .main { display: flex; }
  .back { display: block; }
  .bubble { max-width: 88%; }
}
