/* BYekan */
@font-face{
  font-family: "BYekan";
  src: url("/static/fonts/BYekan.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root{
  --tg-blue:#5682a3;
  --tg-blue2:#4a7699;
  --bg:#e7eef5;
  --card:#ffffff;
  --text:#1b1f24;
  --muted:#6b7785;
  --line:rgba(0,0,0,.08);
  --shadow:0 8px 24px rgba(0,0,0,.12);
  --radius:14px;
}

*{ box-sizing:border-box; }

html, body{
  height:100%;
  margin:0;
  font-family: "BYekan", system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a{ color:inherit; text-decoration:none; }
.app{ min-height:100%; display:flex; flex-direction:column; }
/* buttons */
.icon-btn{
  border:0;
  background:transparent;
  color:#fff;
  font-size:20px;
  padding:10px 12px;
  border-radius:10px;
  cursor:pointer;
}
.icon-btn:active{ transform:scale(.98); }

.btn{
  border:0;
  border-radius:12px;
  padding:12px 14px;
  cursor:pointer;
  font-weight:700;
}
.btn.primary{ background: var(--tg-blue); color:#fff; }

/* AUTH */
.auth-wrap{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
}
.auth-card{
  width:min(420px, 100%);
  background:var(--card);
  border-radius:18px;
  box-shadow: var(--shadow);
  padding:18px;
}
.brand{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  margin-bottom:14px;
}
.brand-logo{
  width:56px;height:56px;
  border-radius:16px;
  background:linear-gradient(180deg, var(--tg-blue), var(--tg-blue2));
  display:flex;align-items:center;justify-content:center;
  color:#fff;font-size:24px;
}
.brand-title{ font-weight:900; font-size:18px; }
.brand-sub{ color:var(--muted); font-size:13px; }
.form{ display:flex; flex-direction:column; gap:10px; }
.form label{ font-size:13px; color:var(--muted); }
.form input{
  width:100%;
  padding:12px 12px;
  border:1px solid var(--line);
  border-radius:12px;
  outline:none;
  background:#fbfdff;
}
.form input:focus{ border-color: rgba(86,130,163,.55); }
.flash{
  background: rgba(255, 140, 140, .18);
  border:1px solid rgba(255, 140, 140, .30);
  color:#8a1f1f;
  border-radius:12px;
  padding:10px;
  margin:10px 0 12px;
  font-size:13px;
}
.flash-item + .flash-item{ margin-top:6px; }
.auth-links{
  margin-top:14px;
  text-align:center;
  color: var(--tg-blue);
  font-weight:700;
}

/* HOME topbar */
.topbar{
  height:56px;
  background: var(--tg-blue);
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 6px;
  box-shadow: 0 2px 0 rgba(0,0,0,.06);
}
.topbar-left{ display:flex; align-items:center; gap:6px; }
.topbar-title{ color:#fff; font-weight:900; font-size:18px; }

/* list */
.list{ flex:1; padding-bottom:80px; }
.list-head{ display:flex; gap:10px; padding:10px 12px; overflow:auto; }
.pill{
  padding:8px 12px;
  border-radius:999px;
  background: rgba(255,255,255,.7);
  border:1px solid var(--line);
  font-weight:800;
  font-size:13px;
  color: #2c3e50;
  white-space:nowrap;
}
.pill.active{
  background: rgba(86,130,163,.18);
  border-color: rgba(86,130,163,.35);
  color: var(--tg-blue);
}

/* chat rows */
.chat-row{
  display:flex;
  align-items:center;
  gap:10px;
  padding:12px 12px;
  border-top:1px solid var(--line);
  background: rgba(255,255,255,.72);
}
.chat-row:active{ background: rgba(255,255,255,.92); }
.avatar{
  width:44px;height:44px;
  border-radius:999px;
  background: linear-gradient(180deg, #8fb3cc, #6f9ab7);
  color:#fff;
  display:flex;align-items:center;justify-content:center;
  font-weight:900;
}
.avatar.big{ width:56px;height:56px; border-radius:18px; }
.chat-meta{ flex:1; min-width:0; }
.chat-title{ font-weight:900; }
.chat-sub{
  color: var(--muted);
  font-size:13px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  margin-top:2px;
}

/* drawer */
.drawer{
  position:fixed;
  top:0;
  right:-320px;
  width:300px;
  max-width:92vw;
  height:100%;
  background:#fff;
  box-shadow: var(--shadow);
  z-index:50;
  transition:right .22s ease;
}
.drawer.open{ right:0; }
.drawer-backdrop{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.28);
  opacity:0;
  pointer-events:none;
  transition:opacity .22s ease;
  z-index:49;
}
.drawer-backdrop.open{ opacity:1; pointer-events:auto; }
.drawer-head{
  background: var(--tg-blue);
  padding:16px;
  color:#fff;
  display:flex;
  align-items:center;
  gap:10px;
}
.drawer-user .du-name{ font-weight:900; }
.drawer-user .du-id{ font-size:12px; opacity:.9; margin-top:2px; }
.drawer-items{ padding:10px; }
.drawer-item{
  display:block;
  padding:12px 12px;
  border-radius:12px;
  font-weight:800;
  color:#263645;
}
.drawer-item:active{ background: rgba(0,0,0,.06); }

.empty{ padding:22px 14px; color:#2c3e50; font-weight:800; }
.hint{ margin-top:8px; color: var(--muted); font-weight:600; font-size:13px; }

/* FAB */
.fab{
  position:fixed;
  right:16px;
  bottom:16px;
  width:56px;height:56px;
  border-radius:18px;
  border:0;
  background: #4ea1d3;
  color:#fff;
  font-size:24px;
  box-shadow: var(--shadow);
}

/* chat screen */
.chatbar{
  height:56px;
  background: var(--tg-blue);
  display:flex;
  align-items:center;
  padding:0 6px;
  color:#fff;
}
.chatbar-mid{ flex:1; min-width:0; padding:0 4px; }
.chatbar-title{ font-weight:900; }
.chatbar-sub{ font-size:12px; opacity:.85; margin-top:2px; }

.chat-body{ position:relative; flex:1; overflow:hidden; }
.chat-bg{
  position:absolute;
  inset:0;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.55), transparent 45%),
    radial-gradient(circle at 80% 30%, rgba(255,255,255,.45), transparent 48%),
    linear-gradient(180deg, #dfeaf3, #cfe0ec);
  filter:saturate(1.05);
}
.msgs{
  position:absolute;
  inset:0;
  overflow:auto;
  padding:14px 12px 88px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.msg{ display:flex; }
.msg.mine{ justify-content:flex-start; }
.msg.theirs{ justify-content:flex-end; }
.bubble{
  max-width:min(78%, 520px);
  border-radius:16px;
  padding:10px 12px;
  box-shadow: 0 2px 0 rgba(0,0,0,.05);
}
.msg.mine .bubble{
  background:#ffffff;
  border:1px solid rgba(0,0,0,.06);
}
.msg.theirs .bubble{
  background:#d2f0c9;
  border:1px solid rgba(0,0,0,.06);
}
.text{
  white-space:pre-wrap;
  word-break:break-word;
  font-weight:700;
}

/* composer */
.composer{
  position:fixed;
  left:0; right:0; bottom:0;
  padding:10px 10px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.92);
  border-top:1px solid var(--line);
  display:flex;
  align-items:center;
  gap:8px;
}
.composer .icon-btn{
  color:#3d4b57;
  background: rgba(0,0,0,.04);
}
.composer-input{
  flex:1;
  border:1px solid var(--line);
  background:#fff;
  border-radius:999px;
  padding:12px 14px;
  outline:none;
  font-weight:800;
}
.send-btn{
  width:44px;height:44px;
  border-radius:999px;
  border:0;
  background: var(--tg-blue);
  color:#fff;
  font-size:18px;
  font-weight:900;
  cursor:pointer;
}


/* --- Fix: make buttons visible + better contrast --- */
.btn{
  display:block;
  width:100%;
  border:0;
  border-radius:14px;
  padding:14px 14px;
  cursor:pointer;
  font-weight:900;
  font-size:15px;
  box-shadow: 0 10px 18px rgba(0,0,0,.10);
}
.btn.primary{
  background: linear-gradient(180deg, #5c93b7, #4b7ea1);
  color:#fff;
}
.btn.primary:active{ transform: scale(.99); }

/* --- Make auth page Telegram-ish --- */
.auth-wrap{
  background: radial-gradient(circle at 20% 10%, rgba(255,255,255,.55), transparent 45%),
              radial-gradient(circle at 85% 25%, rgba(255,255,255,.45), transparent 48%),
              linear-gradient(180deg, #dfeaf3, #cfe0ec);
}

.auth-card{
  border: 1px solid rgba(0,0,0,.06);
  background: rgba(255,255,255,.86);
  backdrop-filter: blur(10px);
}

/* inputs visible */
.form input{
  background: rgba(255,255,255,.95);
  border: 1px solid rgba(86,130,163,.22);
  box-shadow: 0 6px 16px rgba(0,0,0,.06);
}
.form input:focus{
  border-color: rgba(86,130,163,.60);
  box-shadow: 0 10px 20px rgba(86,130,163,.15);
}

/* spacing */
.form{ gap:12px; }
.form label{ font-weight:800; }

/* make link nicer */
.auth-links{
  margin-top:16px;
  padding-top:10px;
  border-top: 1px dashed rgba(0,0,0,.10);
}

/* --- Fix composer layout on RTL + Android keyboard --- */
.composer{
  direction: ltr;          /* icons order + layout stable */
  align-items: center;
  z-index: 1000;           /* above chat background */
}

.composer-input{
  direction: rtl;          /* user typing Persian ok */
  min-width: 0;
}

.send-btn{
  flex: 0 0 46px;          /* never shrink to zero */
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 18px rgba(0,0,0,.14);
}

/* make attach/emoji visible like Telegram */
.composer .icon-btn{
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}


/* =========================
   CHAT FINAL LAYOUT (keyboard-safe)
========================= */

/* full height on modern mobile browsers */
.chat-screen{
  height: 100dvh;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

/* chat body scrolls, not absolute layers */
.chat-body{
  flex: 1;
  overflow:auto;
  padding: 14px 12px;
  padding-bottom: calc(var(--composer-h, 64px) + 14px);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.55), transparent 45%),
    radial-gradient(circle at 80% 30%, rgba(255,255,255,.45), transparent 48%),
    linear-gradient(180deg, #dfeaf3, #cfe0ec);
}

/* msgs list */
.msgs{
  display:flex;
  flex-direction:column;
  gap:10px;
}

/* mine right / theirs left */
.msg{ display:flex; }
.msg.mine{ justify-content:flex-end; }
.msg.theirs{ justify-content:flex-start; }

/* bubble styles (mine green, theirs white) */
.bubble{
  max-width: min(78%, 520px);
  border-radius:16px;
  padding:10px 12px;
  box-shadow: 0 2px 0 rgba(0,0,0,.05);
  border: 1px solid rgba(0,0,0,.06);
}
.msg.mine .bubble{ background:#d2f0c9; }
.msg.theirs .bubble{ background:#ffffff; }

.text{
  white-space:pre-wrap;
  word-break:break-word;
  font-weight:700;
}

.meta{
  margin-top:6px;
  display:flex;
  justify-content:flex-end;
  align-items:center;
  font-size:12px;
  color: rgba(0,0,0,.45);
}
.ticks{ font-weight:900; letter-spacing:-2px; }
.ticks.s0{ color: rgba(0,0,0,.45); }
.ticks.s1{ color: rgba(0,0,0,.45); }
.ticks.s2{ color: #2f8de4; }

/* images/files */
.img-wrap{ display:block; }
.img-msg{
  max-width: 100%;
  border-radius:14px;
  display:block;
}
.file-msg{
  display:flex;
  align-items:center;
  gap:10px;
  text-decoration:none;
  color: inherit;
}
.file-ic{
  width:42px;height:42px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:14px;
  background: rgba(86,130,163,.14);
}
.file-name{
  font-weight:900;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  max-width: 240px;
}

/* composer: NOT fixed -> sticky (so keyboard pushes it naturally) */
.composer{
  position: sticky;
  bottom: 0;
  display:flex;
  align-items:center;
  gap:8px;
  padding:10px 10px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(0,0,0,.08);
  direction:ltr;
}

/* input RTL but icons stable */
.composer-input{
  flex:1;
  direction:rtl;
  border: 1px solid rgba(0,0,0,.10);
  background:#fff;
  border-radius:999px;
  padding:12px 14px;
  outline:none;
  font-weight:800;
  min-width:0;
}

/* icon buttons */
.composer .icon-btn{
  width:44px;height:44px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:14px;
  border:0;
  background: rgba(0,0,0,.04);
  cursor:pointer;
}

/* send button (paper plane) */
.send-btn{
  width:46px;height:46px;
  border-radius:999px;
  border:0;
  background: linear-gradient(180deg, #5c93b7, #4b7ea1);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:0;
  box-shadow: 0 10px 18px rgba(0,0,0,.14);
  cursor:pointer;
}
.send-btn::before{
  content:"";
  width:0;height:0;
  border-left:12px solid #fff;
  border-top:7px solid transparent;
  border-bottom:7px solid transparent;
  transform: translateX(2px);
}

/* Emoji popover */
.pop-backdrop{
  position:fixed; inset:0;
  background: rgba(0,0,0,.18);
  opacity:0; pointer-events:none;
  transition: opacity .15s ease;
  z-index: 1800;
}
.pop-backdrop.open{ opacity:1; pointer-events:auto; }

/* Emoji popover (DEFAULT: fully hidden) */
.emoji-pop{
  position:fixed;
  left:12px; right:12px;
  bottom: calc(var(--composer-h, 64px) + 16px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0,0,0,.14);
  padding: 10px;

  display:grid;
  grid-template-columns: repeat(5, 1fr);
  gap:10px;

  /* CLOSED (important) */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(140%);
  transition: transform .18s ease, opacity .12s ease, visibility 0s linear .18s;

  z-index: 1801;
}

/* OPEN */
.emoji-pop.open{
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  transition: transform .18s ease, opacity .12s ease;
}
.emoji-pop.open{ transform: translateY(0); }

.emoji-btn{
  border:0;
  background:#fff;
  border-radius:14px;
  height:46px;
  font-size:22px;
  cursor:pointer;
  box-shadow: 0 10px 18px rgba(0,0,0,.08);
}

/* Attach Sheet */
.sheet-backdrop{
  position:fixed; inset:0;
  background: rgba(0,0,0,.28);
  opacity:0; pointer-events:none;
  transition: opacity .18s ease;
  z-index: 2000;
}
.sheet-backdrop.open{ opacity:1; pointer-events:auto; }

.sheet{
  position:fixed;
  left:10px; right:10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0,0,0,.18);
  transform: translateY(140%);
  transition: transform .20s ease;
  z-index: 2001;
  padding: 10px;
}
.sheet.open{ transform: translateY(0); }

.sheet-handle{
  width:46px;height:5px;
  border-radius:999px;
  background: rgba(0,0,0,.15);
  margin: 4px auto 10px;
}
.sheet-title{
  text-align:center;
  font-weight:900;
  margin-bottom: 10px;
}
.sheet-item{
  width:100%;
  display:flex;
  align-items:center;
  gap:12px;
  border:0;
  background: #fff;
  border-radius:14px;
  padding:14px 12px;
  margin-bottom:10px;
  font-weight:900;
  cursor:pointer;
  box-shadow: 0 10px 20px rgba(0,0,0,.08);
}
.sheet-ic{
  width:42px;height:42px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:14px;
  background: rgba(86,130,163,.14);
  font-size:20px;
}
.sheet-tx{ flex:1; text-align:right; }
.sheet-cancel{
  width:100%;
  border:0;
  background: rgba(255,255,255,.75);
  border-radius:14px;
  padding:14px 12px;
  font-weight:900;
  cursor:pointer;
}
/* =========================
   FINAL: swap sides only
   mine -> LEFT
   theirs -> RIGHT
   colors stay:
     mine = green
     theirs = white
========================= */

.msg{ display:flex !important; position:relative; }

.msg.mine{ justify-content:flex-start !important; }     /* mine left */
.msg.theirs{ justify-content:flex-end !important; }    /* theirs right */

.msg.mine .bubble{
  background:#d2f0c9 !important;
  border:1px solid rgba(0,0,0,.06) !important;
}
.msg.theirs .bubble{
  background:#ffffff !important;
  border:1px solid rgba(0,0,0,.06) !important;
}

.msg.mine .meta{ justify-content:flex-start !important; }
.msg.theirs .meta{ justify-content:flex-end !important; }

/* =========================
   Telegram-like bubble tail
========================= */

.bubble{ position:relative; }
:root{ --tail: 10px; }

.msg.mine .bubble::after{
  content:"";
  position:absolute;
  left:-6px;                 /* چون mine سمت چپ است */
  bottom:10px;
  width:var(--tail);
  height:var(--tail);
  background:inherit;
  transform: rotate(45deg);
  border-radius: 0 0 0 10px;
  box-shadow: -1px 1px 0 rgba(0,0,0,.06);
}

.msg.theirs .bubble::after{
  content:"";
  position:absolute;
  right:-6px;                /* چون theirs سمت راست است */
  bottom:10px;
  width:var(--tail);
  height:var(--tail);
  background:inherit;
  transform: rotate(45deg);
  border-radius: 0 0 10px 0;
  box-shadow: 1px 1px 0 rgba(0,0,0,.06);
}

/* =========================
   Long-press Action Sheet
========================= */

.msg-backdrop{
  position:fixed; inset:0;
  background: rgba(0,0,0,.28);
  opacity:0; pointer-events:none;
  transition: opacity .18s ease;
  z-index: 3000;
}
.msg-backdrop.open{ opacity:1; pointer-events:auto; }

.msg-sheet{
  position:fixed;
  left:10px; right:10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0,0,0,.18);
  transform: translateY(140%);
  transition: transform .20s ease;
  z-index: 3001;
  padding: 10px;
}
.msg-sheet.open{ transform: translateY(0); }

.msg-sheet-handle{
  width:46px;height:5px;
  border-radius:999px;
  background: rgba(0,0,0,.15);
  margin: 4px auto 10px;
}
.msg-sheet-title{
  text-align:center;
  font-weight:900;
  margin-bottom: 10px;
}

.msg-act{
  width:100%;
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:10px;
  border:0;
  background:#fff;
  border-radius:14px;
  padding:14px 12px;
  margin-bottom:10px;
  font-weight:900;
  cursor:pointer;
  box-shadow: 0 10px 20px rgba(0,0,0,.08);
}
.msg-act.danger{ color:#b00020; }
.msg-act.cancel{
  background: rgba(255,255,255,.75);
  box-shadow:none;
  border: 1px solid rgba(0,0,0,.08);
}
.msg-act.only-mine{ display:none; }
.msg-sheet.mine .msg-act.only-mine{ display:flex; }

/* =========================
   Multi-select mode
========================= */

.selbar{
  position:fixed;
  top:0; left:0; right:0;
  height:56px;
  background: rgba(86,130,163,.98);
  color:#fff;
  display:none;
  align-items:center;
  gap:10px;
  padding:0 10px;
  z-index: 3100;
}
.selbar.open{ display:flex; }

.selbtn{
  border:0;
  background: rgba(255,255,255,.18);
  color:#fff;
  border-radius:12px;
  padding:10px 12px;
  font-weight:900;
  cursor:pointer;
}
.selbtn.danger{ background: rgba(176,0,32,.28); }
.selcount{ font-weight:900; }
.selsp{ flex:1; }

/* selection circle */
.msg::before{
  content:"";
  position:absolute;
  left:10px;
  top:50%;
  width:22px;height:22px;
  transform: translateY(-50%);
  border-radius:999px;
  border:2px solid rgba(255,255,255,.85);
  background: rgba(255,255,255,.25);
  box-shadow: 0 6px 14px rgba(0,0,0,.12);
  opacity:0;
  pointer-events:none;
}

.chat-body.selecting .msg{ padding-left:42px; }
.chat-body.selecting .msg::before{ opacity:1; }

.msg.selected::before{
  background: rgba(46, 204, 113, .95);
  border-color: rgba(255,255,255,.95);
}

.msg.selected .bubble{
  outline: 2px solid rgba(46,204,113,.25);
}

/* prevent native text selection / callout on messages (we will provide Copy via our menu) */
.msg, .msg *{
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* allow normal scroll on chat */
.chat-body{
  touch-action: pan-y;
}