/* ============================================================
 *  WhatsApp-style dark theme.
 * ============================================================ */

:root{
  --bg:#0b141a;
  --panel:#202c33;
  --panel-2:#111b21;
  --bubble-me:#005c4b;
  --bubble-them:#202c33;
  --text:#e9edef;
  --text-dim:#8696a0;
  --accent:#00a884;
  --danger:#ea6c6c;
  --divider:rgba(134,150,160,.15);
}

*{ box-sizing:border-box; }

html{ -webkit-text-size-adjust:100%; text-size-adjust:100%; }

html,body{
  margin:0; padding:0;
  height:100%;
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  /* Kill double-tap-to-zoom & the 300ms tap delay everywhere. */
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
  overscroll-behavior:none;
}

button,input{ font-family:inherit; }
img,video{ display:block; max-width:100%; }

/* ---------- Buttons ---------- */
.btn{
  border:0; border-radius:8px; padding:10px 16px;
  font-size:15px; font-weight:600; cursor:pointer;
  touch-action:manipulation;
}
.btn.primary{ background:var(--accent); color:#04231c; }
.btn.ghost{ background:transparent; color:var(--text-dim); }
.btn.block{ width:100%; }

/* ============================================================
 *  Login page
 * ============================================================ */
.login-page{
  display:flex; align-items:center; justify-content:center;
  min-height:100dvh; padding:20px;
  background:linear-gradient(180deg,#0b141a 0%,#111b21 100%);
}
.login-card{
  width:100%; max-width:360px;
  background:var(--panel); border-radius:16px;
  padding:32px 24px;
  box-shadow:0 12px 40px rgba(0,0,0,.4);
  text-align:center;
}
.login-logo{ font-size:44px; }
.login-card h1{ margin:8px 0 2px; font-size:22px; }
.login-sub{ margin:0 0 20px; color:var(--text-dim); font-size:14px; }
.field{ display:block; text-align:left; margin-bottom:14px; }
.field span{ display:block; font-size:12px; color:var(--text-dim); margin-bottom:6px; }
.field input{
  width:100%; padding:12px 14px;
  background:var(--panel-2); border:1px solid var(--divider);
  border-radius:10px; color:var(--text); font-size:16px; outline:none;
}
.field input:focus{ border-color:var(--accent); }
.login-error{
  background:rgba(234,108,108,.12); color:var(--danger);
  border-radius:8px; padding:10px 12px; margin-bottom:14px; font-size:14px;
}
.remember{
  display:flex; align-items:center; gap:10px;
  text-align:left; color:var(--text-dim); font-size:14px;
  margin:2px 0 18px; cursor:pointer;
}
.remember input{ width:18px; height:18px; accent-color:var(--accent); }

/* ============================================================
 *  Chat layout
 * ============================================================ */
.chat-page{ overflow:hidden; }
#app{
  display:flex; flex-direction:column;
  height:100dvh;
}

/* ---------- Top bar ---------- */
.topbar{
  flex:0 0 auto;
  display:flex; align-items:center; justify-content:space-between;
  background:var(--panel);
  padding:8px 12px; padding-top:calc(8px + env(safe-area-inset-top));
  border-bottom:1px solid var(--divider);
}
.peer{ display:flex; align-items:center; gap:12px; min-width:0; }
.avatar{
  width:40px; height:40px; border-radius:50%;
  background:#6a7175; color:#fff;
  display:flex; align-items:center; justify-content:center;
  font-weight:600; font-size:18px; text-transform:uppercase;
}
.peer-meta{ min-width:0; }
.peer-name{ font-size:16px; font-weight:600; line-height:1.2; }
.peer-status{ font-size:12px; color:var(--text-dim); transition:color .2s; }
.peer-status.online{ color:var(--accent); }
.peer-status.offline{ color:var(--text-dim); }
.topbar-actions{ display:flex; align-items:center; gap:4px; }
.icon-btn{
  display:flex; align-items:center; justify-content:center;
  width:40px; height:40px; border-radius:50%;
  background:transparent; border:0; color:var(--text-dim);
  cursor:pointer; text-decoration:none;
}
.icon-btn:active{ background:rgba(255,255,255,.06); }

/* ---------- Disappearing banner ---------- */
.dis-banner{
  flex:0 0 auto;
  background:#182229; color:var(--text-dim);
  font-size:12.5px; text-align:center;
  padding:7px 12px; border-bottom:1px solid var(--divider);
}

/* ---------- Messages ---------- */
.messages{
  flex:1 1 auto;
  overflow-y:auto; overflow-x:hidden;
  padding:14px 8px 18px;
  display:flex; flex-direction:column; gap:2px;
  background:
    linear-gradient(rgba(11,20,26,.94),rgba(11,20,26,.94));
  background-color:#0b141a;
  -webkit-overflow-scrolling:touch;
}

.day-sep{ align-self:center; margin:12px 0; }
.day-sep span{
  background:#182229; color:var(--text-dim);
  font-size:12px; padding:5px 12px; border-radius:8px;
}

.row{ display:flex; align-items:center; padding:1px 6px; gap:4px; }
.row.me{ justify-content:flex-end; }
.row.them{ justify-content:flex-start; }

/* small reply control next to each message */
.reply-btn{
  flex:0 0 auto;
  width:26px; height:26px; border-radius:50%;
  border:0; background:transparent; color:var(--text-dim);
  font-size:15px; line-height:1; cursor:pointer;
  opacity:.35; transition:opacity .15s, background .15s;
}
.reply-btn:hover,.reply-btn:active{ opacity:1; background:rgba(255,255,255,.08); }
.row.me .reply-btn{ order:-1; }   /* place it to the LEFT of my bubbles */

/* quoted (replied-to) block inside a bubble */
.quote{
  display:block; margin-bottom:4px; padding:5px 8px;
  border-left:3px solid var(--accent);
  background:rgba(0,0,0,.22); border-radius:5px;
  cursor:pointer; max-width:100%;
}
.quote-name{ font-size:12.5px; font-weight:600; color:var(--accent); margin-bottom:1px; }
.quote-text{
  font-size:13px; color:var(--text-dim);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:240px;
}

/* flash highlight when jumping to / selecting a message */
@keyframes flashbg {
  0%   { box-shadow:0 0 0 3px rgba(0,168,132,.75); }
  100% { box-shadow:0 0 0 3px rgba(0,168,132,0); }
}
.bubble.flash{ animation:flashbg 1.1s ease-out; }

.bubble{
  max-width:min(78%,520px);
  padding:6px 9px 8px;
  border-radius:10px;
  position:relative;
  font-size:15px; line-height:1.35;
  word-wrap:break-word; overflow-wrap:anywhere; white-space:pre-wrap;
  box-shadow:0 1px .5px rgba(0,0,0,.15);
}
.row.me   .bubble{ background:var(--bubble-me);   border-top-right-radius:2px; }
.row.them .bubble{ background:var(--bubble-them); border-top-left-radius:2px; }

.bubble.has-media{ padding:4px 4px 6px; }
.bubble .media{
  border-radius:7px; overflow:hidden; cursor:pointer;
  max-width:280px;
}
.bubble .media img,
.bubble .media video{ width:100%; height:auto; border-radius:7px; max-height:60vh; object-fit:cover; }
.bubble .caption{ padding:5px 5px 0; }

.meta{
  display:block; text-align:right;
  font-size:11px; color:var(--text-dim);
  margin-top:2px; user-select:none;
}
.row.me .meta{ color:rgba(233,237,239,.6); }
.tick{ margin-left:4px; font-size:11px; letter-spacing:-2px; }
.tick.read{ color:#53bdeb; letter-spacing:-2px; }

.empty-hint{
  margin:auto; color:var(--text-dim); font-size:14px; text-align:center;
  background:#182229; padding:10px 16px; border-radius:10px;
}

/* ---------- Reply preview bar (above composer) ---------- */
.reply-bar{
  flex:0 0 auto;
  display:flex; align-items:center; gap:10px;
  background:#1b262c;
  padding:8px 12px;
  border-top:1px solid var(--divider);
}
.reply-bar-strip{ width:3px; align-self:stretch; background:var(--accent); border-radius:3px; }
.reply-bar-content{ flex:1 1 auto; min-width:0; }
.reply-bar-name{ font-size:13px; font-weight:600; color:var(--accent); }
.reply-bar-text{
  font-size:13px; color:var(--text-dim);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.reply-bar-close{
  flex:0 0 auto; width:32px; height:32px; border-radius:50%;
  background:transparent; border:0; color:var(--text-dim);
  font-size:15px; cursor:pointer;
}
.reply-bar-close:active{ background:rgba(255,255,255,.06); }

/* ---------- Composer ---------- */
.composer{
  flex:0 0 auto;
  display:flex; align-items:center; gap:6px;
  background:var(--panel);
  padding:8px 10px; padding-bottom:calc(8px + env(safe-area-inset-bottom));
  border-top:1px solid var(--divider);
}
.attach-btn,.send-btn{
  flex:0 0 auto;
  display:flex; align-items:center; justify-content:center;
  width:44px; height:44px; border-radius:50%;
  border:0; cursor:pointer; color:var(--text-dim);
  background:transparent;
}
.send-btn{ background:var(--accent); color:#04231c; }
.attach-btn:active{ background:rgba(255,255,255,.06); }
.text-input{
  flex:1 1 auto; min-width:0;
  background:var(--panel-2); border:0; outline:none;
  color:var(--text); font-size:16px;
  padding:11px 14px; border-radius:22px;
}

/* ============================================================
 *  Modals
 * ============================================================ */
.modal{
  position:fixed; inset:0; z-index:40;
  display:flex; align-items:center; justify-content:center;
  background:rgba(0,0,0,.6); padding:20px;
}
.modal.hidden,.viewer.hidden,.hidden{ display:none !important; }
.modal-card{
  width:100%; max-width:360px;
  background:var(--panel); border-radius:14px; padding:20px;
  box-shadow:0 12px 40px rgba(0,0,0,.5);
}
.modal-card h3{ margin:0 0 6px; font-size:18px; }
.modal-sub{ margin:0 0 16px; color:var(--text-dim); font-size:13.5px; line-height:1.4; }
.opt{
  display:flex; align-items:center; gap:12px;
  padding:12px 8px; border-radius:8px; cursor:pointer; font-size:16px;
}
.opt:active{ background:rgba(255,255,255,.05); }
.opt input{ width:20px; height:20px; accent-color:var(--accent); }
.modal-actions{ display:flex; justify-content:flex-end; gap:8px; margin-top:14px; }

.preview-card{ max-width:420px; }
.preview-body{
  background:#000; border-radius:10px; overflow:hidden;
  display:flex; align-items:center; justify-content:center;
  max-height:55vh; margin-bottom:12px;
}
.preview-body img,.preview-body video{ max-height:55vh; width:auto; max-width:100%; }
.caption-input{ background:var(--panel-2); margin-bottom:4px; }

/* ---------- Full-screen viewer ---------- */
.viewer{
  position:fixed; inset:0; z-index:60;
  background:rgba(0,0,0,.95);
  display:flex; align-items:center; justify-content:center;
}
.viewer-body{ max-width:100vw; max-height:100vh; padding:16px; }
.viewer-body img,.viewer-body video{ max-width:96vw; max-height:92vh; width:auto; height:auto; }
.viewer-close{
  position:absolute; top:calc(12px + env(safe-area-inset-top)); right:16px;
  width:42px; height:42px; border-radius:50%;
  background:rgba(255,255,255,.12); color:#fff; border:0;
  font-size:20px; cursor:pointer; z-index:61;
}

/* uploading state */
.uploading .send-btn,.uploading .btn.primary{ opacity:.5; pointer-events:none; }
