/* KinPro Chat — Complete Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700&family=DM+Sans:wght@400;500&display=swap');

*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
  --primary:#6366f1; --secondary:#8b5cf6;
  --bg:#0f0f1a; --surface:#12121e; --surface2:#1a1a2e; --surface3:#1e1e35;
  --border:rgba(255,255,255,.06); --border-hi:rgba(255,255,255,.12);
  --text:#e8e8f0; --text-muted:#6b7280; --text-dim:#9ca3af;
  --bubble-out:#6366f1; --bubble-in:#1e1e35;
  --online:#34d399; --offline:#374151; --danger:#f87171;
  --sidebar:280px; --header:62px;
}

html,body{height:100%;overflow:hidden;background:var(--bg);color:var(--text);font-family:'DM Sans',sans-serif;font-size:15px}
a{color:var(--primary);text-decoration:none}
button{cursor:pointer;font-family:inherit}
input,textarea,select{font-family:inherit}
::-webkit-scrollbar{width:4px}
::-webkit-scrollbar-thumb{background:rgba(255,255,255,.1);border-radius:9px}

/* ── LOGIN ── */
.login-page{min-height:100vh;display:flex;align-items:center;justify-content:center;background:var(--bg);overflow-y:auto;position:relative}
.login-glow{position:absolute;width:700px;height:700px;border-radius:50%;pointer-events:none;background:radial-gradient(circle,rgba(99,102,241,.18) 0%,transparent 65%);top:-200px;left:-200px}
.login-glow2{position:absolute;width:500px;height:500px;border-radius:50%;pointer-events:none;background:radial-gradient(circle,rgba(139,92,246,.13) 0%,transparent 65%);bottom:-150px;right:-150px}
.login-card{position:relative;z-index:1;background:var(--surface);border:1px solid var(--border-hi);border-radius:28px;padding:52px 44px;width:100%;max-width:430px;box-shadow:0 40px 100px rgba(0,0,0,.6)}
.login-brand{font-family:'Sora',sans-serif;font-size:30px;font-weight:700;text-align:center;margin-bottom:8px;background:linear-gradient(135deg,#818cf8,#a78bfa);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text}
.login-sub{text-align:center;color:var(--text-muted);font-size:13.5px;margin-bottom:36px}
.field{margin-bottom:16px}
.field label{display:block;font-size:12.5px;font-weight:500;color:var(--text-dim);margin-bottom:7px}
.field input{width:100%;padding:13px 16px;background:var(--surface2);border:1px solid var(--border-hi);border-radius:12px;color:var(--text);font-size:14.5px;outline:none;transition:border-color .2s,box-shadow .2s}
.field input:focus{border-color:var(--primary);box-shadow:0 0 0 3px rgba(99,102,241,.18)}
.btn-primary{width:100%;padding:14px;cursor:pointer;background:linear-gradient(135deg,var(--primary),var(--secondary));color:#fff;border:none;border-radius:12px;font-size:15px;font-weight:600;font-family:'Sora',sans-serif;transition:opacity .18s,transform .15s;box-shadow:0 8px 24px rgba(99,102,241,.35)}
.btn-primary:hover{opacity:.9;transform:translateY(-1px)}
.alert-error{background:rgba(248,113,113,.12);border:1px solid rgba(248,113,113,.3);color:#f87171;border-radius:10px;padding:11px 14px;font-size:13.5px;margin-bottom:14px}
.alert-success{background:rgba(52,211,153,.1);border:1px solid rgba(52,211,153,.3);color:#6ee7b7;border-radius:10px;padding:11px 14px;font-size:13.5px;margin-bottom:14px}

/* ══════════════════════════════════════════════════
   CORE LAYOUT
   The entire app is position:fixed filling the screen.
   Sidebar is a flex column on the left.
   chat-area fills the rest and uses position:absolute
   children — this is the ONLY reliable way to get
   "fixed header + scrollable middle + fixed input"
   on all mobile browsers.
   ══════════════════════════════════════════════════ */

/* Root container — fixed to viewport, never scrolls */
body > aside,
body > .chat-area {
  position: fixed;
  top: 0; bottom: 0;
}

/* SIDEBAR — left side */
.sidebar {
  left: 0;
  width: var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
  transition: transform .28s ease;
}
.sidebar.hidden { transform: translateX(-100%); }

/* CHAT AREA — fills rest of screen */
.chat-area {
  left: var(--sidebar);
  right: 0;
  top: 0;
  bottom: 0;
  background: var(--bg);
  overflow: hidden;
  transition: left .28s ease;
}

/* All children of chat-area use absolute positioning */
.chat-area > * {
  position: absolute;
  left: 0; right: 0;
}

/* EMPTY STATE — fills whole chat area */
.empty-state {
  top: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}
.empty-icon{width:80px;height:80px;border-radius:24px;background:var(--surface2);display:flex;align-items:center;justify-content:center;font-size:36px;margin-bottom:8px}
.empty-state h3{font-family:'Sora',sans-serif;font-size:20px;color:var(--text-dim);font-weight:600}
.empty-state p{font-size:14px;max-width:260px;line-height:1.6}
.btn-back-mobile{display:none;margin-top:16px;padding:12px 28px;font-size:14px;width:auto;cursor:pointer;background:linear-gradient(135deg,var(--primary),var(--secondary));color:#fff;border:none;border-radius:12px;font-family:'Sora',sans-serif;font-weight:600}

/* CHAT HEADER — pinned to top */
.chat-header {
  top: 0;
  height: var(--header);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(12,12,22,.97);
  backdrop-filter: blur(12px);
}
.chat-header-left{display:flex;align-items:center;gap:12px}
.chat-header-name{font-family:'Sora',sans-serif;font-size:15.5px;font-weight:600}
.chat-header-status{font-size:12px;color:var(--text-muted)}
.chat-header-status.on{color:var(--online)}

/* MESSAGES WRAP — top/bottom set by reflow() in JS */
.messages-wrap {
  top: var(--header); /* overridden by JS reflow */
  bottom: 70px;       /* overridden by JS reflow */
  overflow-x: visible;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1;
}

/* TYPING WRAP — just above input bar, set by JS */
.typing-wrap {
  bottom: 70px; /* overridden by JS reflow */
  z-index: 5;
  padding: 0 14px 4px;
  pointer-events: none;
}

/* INPUT BAR — pinned to bottom */
.input-bar {
  bottom: 0;
  z-index: 20;
  background: rgba(12,12,22,.97);
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* ── SIDEBAR INTERNALS ── */
.sidebar-header{height:var(--header);display:flex;align-items:center;justify-content:space-between;padding:0 18px;border-bottom:1px solid var(--border);flex-shrink:0}
.sidebar-brand{font-family:'Sora',sans-serif;font-size:18px;font-weight:700;background:linear-gradient(135deg,#818cf8,#a78bfa);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text}
.header-actions{display:flex;gap:6px;align-items:center}
.icon-btn{width:34px;height:34px;border-radius:10px;background:transparent;border:1px solid var(--border);color:var(--text-dim);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:16px;transition:background .18s,color .18s;text-decoration:none}
.icon-btn:hover{background:var(--surface2);color:var(--text)}
.icon-btn.pagal-btn{border-color:rgba(99,102,241,.4);color:#818cf8}
.icon-btn.pagal-btn:hover{background:rgba(99,102,241,.12)}

.sidebar-search{padding:14px 14px 10px;flex-shrink:0;position:relative}
.search-wrap{position:relative}
.search-wrap svg{position:absolute;left:11px;top:50%;transform:translateY(-50%);color:var(--text-muted);pointer-events:none}
.search-wrap input{width:100%;padding:9px 12px 9px 34px;background:var(--surface2);border:1px solid var(--border);border-radius:10px;color:var(--text);font-size:13.5px;outline:none}
.search-wrap input::placeholder{color:var(--text-muted)}
.search-wrap input:focus{border-color:rgba(99,102,241,.5)}

#search-results{display:none;position:absolute;top:calc(100% + 4px);left:0;right:0;background:var(--surface);border:1px solid var(--border-hi);border-radius:14px;box-shadow:0 16px 48px rgba(0,0,0,.6);z-index:200;max-height:320px;overflow-y:auto}
.search-result-item{padding:12px 14px;cursor:pointer;border-bottom:1px solid var(--border);transition:background .14s}
.search-result-item:last-child{border-bottom:none}
.search-result-item:hover{background:var(--surface2)}
.search-result-top{display:flex;justify-content:space-between;margin-bottom:4px}
.search-result-conv{font-size:12.5px;font-weight:600;color:#a5b4fc}
.search-result-time{font-size:11px;color:var(--text-muted)}
.search-result-body{font-size:13px;color:var(--text-dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.search-result-body mark{background:rgba(99,102,241,.3);color:var(--text);border-radius:3px;padding:0 2px}
.search-empty{padding:16px;text-align:center;color:var(--text-muted);font-size:13.5px}

.section-label{padding:10px 18px 6px;font-size:10.5px;font-weight:600;letter-spacing:.08em;color:var(--text-muted);text-transform:uppercase;flex-shrink:0}
.users-list{flex:1;overflow-y:auto;padding:4px 8px 12px;min-height:0}
.user-item{display:flex;align-items:center;gap:11px;padding:10px;border-radius:13px;cursor:pointer;transition:background .15s;position:relative;margin-bottom:2px;color:inherit;text-decoration:none}
.user-item:hover{background:var(--surface2)}
.user-item.active{background:rgba(99,102,241,.15)}
.user-item.active .user-name{color:#a5b4fc}

.avatar{width:40px;height:40px;border-radius:13px;flex-shrink:0;display:flex;align-items:center;justify-content:center;font-family:'Sora',sans-serif;font-weight:700;font-size:15px;position:relative;color:#fff}
.avatar-sm{width:34px;height:34px;font-size:13px;border-radius:10px}
.avatar-lg{width:46px;height:46px;font-size:17px;border-radius:15px}
.online-dot{position:absolute;bottom:-1px;right:-1px;width:11px;height:11px;border-radius:50%;border:2px solid var(--surface)}
.online-dot.on{background:var(--online)}
.online-dot.off{background:var(--offline)}
.user-info{flex:1;min-width:0}
.user-name{font-size:13.5px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-sub{font-size:11.5px;color:var(--text-muted);margin-top:1px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-sub.on{color:var(--online)}
.unread-badge{background:var(--primary);color:#fff;font-size:10.5px;font-weight:700;min-width:18px;height:18px;border-radius:9px;display:flex;align-items:center;justify-content:center;padding:0 5px;flex-shrink:0}

.sidebar-footer{padding:12px 14px;border-top:1px solid var(--border);flex-shrink:0}
.me-card{display:flex;align-items:center;gap:10px;padding:9px 10px;border-radius:12px;background:var(--surface2)}
.me-info{flex:1;min-width:0}
.me-name{font-size:13px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.me-role{font-size:11px;color:var(--text-muted)}
.logout-btn{flex-shrink:0;background:rgba(248,113,113,.08);border:1px solid rgba(248,113,113,.2);color:#f87171;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:6px;font-size:12.5px;font-weight:600;padding:7px 12px;border-radius:10px;transition:background .18s;text-decoration:none;white-space:nowrap}
.logout-btn:hover{background:rgba(248,113,113,.18)}
.logout-icon{font-size:14px;line-height:1}

/* ── MESSAGE BUBBLES ── */
.msg-group{display:flex;flex-direction:column;position:relative;overflow:visible}
.msg-group.out{align-items:flex-end}
.msg-group.in{align-items:flex-start}
.msg-bubble-wrap{display:flex;align-items:flex-end;gap:4px;max-width:65%;position:relative;overflow:visible}
.msg-group.out .msg-bubble-wrap{flex-direction:row-reverse}
.msg-bubble{padding:10px 14px;border-radius:18px;font-size:14.5px;line-height:1.55;word-break:break-word;animation:popIn .18s ease}
@keyframes popIn{from{opacity:0;transform:scale(.94) translateY(4px)}to{opacity:1;transform:scale(1) translateY(0)}}
.msg-group.out .msg-bubble{background:var(--bubble-out);color:#fff;border-bottom-right-radius:5px}
.msg-group.in .msg-bubble{background:var(--bubble-in);color:var(--text);border:1px solid var(--border);border-bottom-left-radius:5px}
.msg-bubble.highlight{animation:hl .4s ease 2}

/* Image messages — transparent, no border, no padding */
.msg-group.out .msg-bubble.img-bubble { background:transparent; padding:0; border:none; box-shadow:none; }
.msg-group.in  .msg-bubble.img-bubble { background:transparent; padding:0; border:none; box-shadow:none; }
.img-bubble .msg-image { border-radius:14px; }
.img-bubble .msg-meta  { padding:4px 4px 0; }
.img-bubble .msg-time  { color:var(--text-muted); text-shadow:none; }
@keyframes hl{0%,100%{opacity:1}50%{opacity:.5}}
.msg-meta{display:flex;align-items:center;gap:5px;margin-top:4px;justify-content:flex-end;flex-wrap:wrap}
.msg-group.in .msg-meta{justify-content:flex-start}
.msg-time{font-size:10.5px;color:rgba(255,255,255,.45)}
.msg-group.in .msg-time{color:var(--text-muted)}
.msg-receipt{font-size:11px;line-height:1}
.edited-label{font-size:10px;color:rgba(255,255,255,.4);font-style:italic}
.msg-group.in .edited-label{color:var(--text-muted)}
.deleted-msg{font-size:13px;color:rgba(255,255,255,.4);font-style:italic}
.msg-group.in .deleted-msg{color:var(--text-muted)}
.deleted-tag{display:inline-block;margin-top:5px;font-size:10.5px;background:rgba(248,113,113,.18);color:#f87171;border-radius:6px;padding:2px 8px;font-style:italic}
.msg-image{max-width:100%;max-height:260px;border-radius:12px;display:block;cursor:pointer;object-fit:cover}
.date-divider{display:flex;align-items:center;gap:10px;margin:12px 0;color:var(--text-muted);font-size:11.5px}
.date-divider::before,.date-divider::after{content:'';flex:1;height:1px;background:var(--border)}

/* Reply preview in bubble */
.reply-preview{background:rgba(255,255,255,.08);border-left:3px solid rgba(255,255,255,.4);border-radius:8px;padding:6px 10px;margin-bottom:8px;cursor:pointer}
.msg-group.out .reply-preview{background:rgba(255,255,255,.12)}
.reply-preview-name{display:block;font-size:11.5px;font-weight:600;color:rgba(255,255,255,.7);margin-bottom:2px}
.msg-group.in .reply-preview-name{color:#a5b4fc}
.reply-preview-body{display:block;font-size:12.5px;color:rgba(255,255,255,.55);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.msg-group.in .reply-preview-body{color:var(--text-dim)}

/* Message menu */
.msg-menu-btn {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; flex-shrink: 0;
  cursor: pointer;
  transition: background .15s;
  /* Always visible — tap to open action sheet */
}
.msg-menu-btn:hover, .msg-menu-btn:active { background: rgba(255,255,255,.15); color: var(--text); }
@keyframes fadeUp{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}
@keyframes fadeDown{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:translateY(0)}}

/* Reactions */
.reactions-row{display:flex;flex-wrap:wrap;gap:4px;margin-top:5px;position:relative;z-index:1}
.reaction-pill{padding:3px 8px;border-radius:20px;background:var(--surface);border:1px solid var(--border-hi);font-size:13px;cursor:pointer;line-height:1.4;box-shadow:0 2px 6px rgba(0,0,0,.3)}
.reaction-pill:hover{background:var(--surface2)}
.reaction-pill.mine{background:rgba(99,102,241,.2);border-color:rgba(99,102,241,.5)}
/* reaction picker replaced by react-sheet */

/* Typing */
#typing-indicator{display:none;align-items:center;gap:4px;padding:8px 12px;background:var(--bubble-in);border:1px solid var(--border);border-radius:18px;border-bottom-left-radius:5px;width:fit-content}
.typing-dot{width:6px;height:6px;background:var(--text-muted);border-radius:50%;animation:bounce .9s infinite}
.typing-dot:nth-child(2){animation-delay:.15s}
.typing-dot:nth-child(3){animation-delay:.3s}
@keyframes bounce{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-5px)}}

/* INPUT BAR INTERNALS */
.input-row{display:flex;align-items:flex-end;gap:8px}
.input-tools{display:flex;gap:6px;flex-shrink:0}
.tool-btn{width:40px;height:40px;border-radius:12px;background:var(--surface2);border:1px solid var(--border);color:var(--text-dim);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:20px;transition:all .16s;flex-shrink:0}
.tool-btn:hover{background:var(--surface3);color:var(--text)}
.msg-input-wrap{flex:1;position:relative;min-width:0}
.msg-input{width:100%;padding:10px 14px;background:var(--surface2);border:1px solid var(--border);border-radius:14px;color:var(--text);font-size:15px;outline:none;resize:none;max-height:120px;line-height:1.5;transition:border-color .18s;display:block}
.msg-input:focus{border-color:rgba(99,102,241,.5);box-shadow:0 0 0 3px rgba(99,102,241,.1)}
.msg-input::placeholder{color:var(--text-muted)}
.send-btn{width:44px;height:44px;border-radius:13px;flex-shrink:0;background:linear-gradient(135deg,var(--primary),var(--secondary));border:none;color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:20px;box-shadow:0 4px 16px rgba(99,102,241,.4);transition:opacity .18s,transform .15s}
.send-btn:hover{opacity:.9;transform:scale(1.05)}
.send-btn:active{transform:scale(.96)}
.reply-bar{display:none;align-items:center;gap:10px;padding:8px 12px;background:rgba(99,102,241,.1);border:1px solid rgba(99,102,241,.25);border-radius:10px;margin-bottom:10px}
.reply-bar-content{flex:1;min-width:0}
.reply-bar-sender{font-size:12px;font-weight:600;color:#a5b4fc;margin-bottom:2px}
.reply-bar-body{font-size:12.5px;color:var(--text-dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.reply-bar-close{width:24px;height:24px;border-radius:7px;background:transparent;border:none;color:var(--text-muted);font-size:16px;flex-shrink:0;display:flex;align-items:center;justify-content:center}
.img-preview-bar{display:none;align-items:center;gap:10px;padding:10px 14px;background:var(--surface2);border:1px solid var(--border);border-radius:12px;margin-bottom:10px}
.img-preview-bar.show{display:flex}
.img-preview-bar img{width:60px;height:50px;border-radius:8px;object-fit:cover}
.img-preview-info{flex:1;font-size:12.5px;color:var(--text-dim)}
.img-remove-btn{width:26px;height:26px;border-radius:8px;flex-shrink:0;background:rgba(248,113,113,.15);border:none;color:var(--danger);cursor:pointer;font-size:15px}
.emoji-picker{position:absolute;bottom:calc(100% + 8px);left:0;background:var(--surface);border:1px solid var(--border-hi);border-radius:16px;padding:12px;display:none;grid-template-columns:repeat(8,34px);gap:3px;box-shadow:0 16px 48px rgba(0,0,0,.7);z-index:150;max-height:200px;overflow-y:auto}
.emoji-picker.open{display:grid;animation:fadeUp .18s ease}
.emoji-btn{width:34px;height:34px;border-radius:8px;border:none;background:transparent;cursor:pointer;font-size:19px;display:flex;align-items:center;justify-content:center}
.emoji-btn:hover{background:var(--surface2)}

/* MODALS */
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.75);backdrop-filter:blur(6px);z-index:500;display:flex;align-items:center;justify-content:center;padding:20px;animation:fadeIn .2s ease}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.modal{background:var(--surface);border:1px solid var(--border-hi);border-radius:22px;width:100%;max-width:580px;max-height:88vh;overflow:hidden;display:flex;flex-direction:column;box-shadow:0 40px 100px rgba(0,0,0,.8);animation:slideUp .22s ease}
@keyframes slideUp{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:translateY(0)}}
.modal-header{padding:22px 24px 0;display:flex;align-items:center;justify-content:space-between;flex-shrink:0}
.modal-title{font-family:'Sora',sans-serif;font-size:18px;font-weight:700}
.modal-close{width:34px;height:34px;border-radius:10px;background:var(--surface2);border:1px solid var(--border);color:var(--text-dim);cursor:pointer;font-size:18px;display:flex;align-items:center;justify-content:center}
.modal-close:hover{background:rgba(248,113,113,.12);color:var(--danger)}
.modal-tabs{display:flex;padding:18px 24px 0;border-bottom:1px solid var(--border);flex-shrink:0}
.modal-tab{padding:8px 16px;font-size:13.5px;font-weight:500;cursor:pointer;border:none;background:transparent;color:var(--text-muted);border-bottom:2px solid transparent;margin-bottom:-1px;transition:color .16s,border-color .16s}
.modal-tab.active{color:#818cf8;border-bottom-color:#818cf8}
.modal-body{flex:1;overflow-y:auto;padding:20px 24px 24px}
.tab-panel{display:none}
.tab-panel.active{display:block}

/* PAGAL TABLES */
.admin-table{width:100%;border-collapse:collapse}
.admin-table th{text-align:left;font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:var(--text-muted);padding:0 10px 10px;font-weight:600}
.admin-table td{padding:10px;border-top:1px solid var(--border);font-size:13.5px;vertical-align:middle}
.role-badge{display:inline-flex;align-items:center;padding:3px 10px;border-radius:20px;font-size:11px;font-weight:600}
.role-badge.pagal{background:rgba(99,102,241,.18);color:#a5b4fc;border:1px solid rgba(99,102,241,.3)}
.role-badge.user{background:rgba(52,211,153,.10);color:#6ee7b7;border:1px solid rgba(52,211,153,.25)}
.btn-danger-sm{padding:5px 12px;border-radius:8px;background:rgba(248,113,113,.12);border:1px solid rgba(248,113,113,.3);color:var(--danger);font-size:12px;font-weight:500;cursor:pointer}
.btn-danger-sm:hover{background:rgba(248,113,113,.2)}
.btn-sm{padding:5px 12px;border-radius:8px;background:rgba(99,102,241,.12);border:1px solid rgba(99,102,241,.3);color:#818cf8;font-size:12px;font-weight:500;cursor:pointer}
.btn-sm:hover{background:rgba(99,102,241,.2)}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.form-grid .span2{grid-column:span 2}
.fg{display:flex;flex-direction:column;gap:6px}
.fg label{font-size:12px;font-weight:500;color:var(--text-dim)}
.fg input,.fg select{padding:10px 13px;background:var(--surface2);border:1px solid var(--border);border-radius:10px;color:var(--text);font-size:13.5px;outline:none;transition:border-color .18s}
.fg input:focus,.fg select:focus{border-color:rgba(99,102,241,.5)}
.fg select option{background:var(--surface2)}
.theme-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.theme-item{display:flex;flex-direction:column;gap:7px}
.theme-item label{font-size:12.5px;color:var(--text-dim);font-weight:500}
.theme-item input[type="color"]{width:100%;height:44px;border:1px solid var(--border);border-radius:10px;background:var(--surface2);cursor:pointer;padding:4px 6px}
.theme-preview{height:36px;border-radius:10px;margin-top:14px;display:flex;align-items:center;justify-content:center;font-size:13px;font-weight:600;color:#fff;font-family:'Sora',sans-serif}
.conv-item{display:flex;align-items:center;justify-content:space-between;padding:12px 14px;background:var(--surface2);border-radius:12px;margin-bottom:8px}
.conv-item-info strong{color:var(--text);font-size:13.5px}
.conv-item-info span{font-size:12px;color:var(--text-muted);display:block;margin-top:2px}
.btn-row{display:flex;gap:10px}
.btn-delete{flex:1;padding:11px;font-size:14px;font-weight:600;font-family:'Sora',sans-serif;cursor:pointer;background:linear-gradient(135deg,#ef4444,#dc2626);color:#fff;border:none;border-radius:12px}
.btn-cancel{flex:1;padding:11px;font-size:14px;font-weight:600;cursor:pointer;background:var(--surface2);border:1px solid var(--border);border-radius:12px;color:var(--text);font-family:inherit}

.lightbox{position:fixed;inset:0;background:rgba(0,0,0,.92);z-index:600;display:none;align-items:center;justify-content:center}
.lightbox.open{display:flex}
.lightbox img{max-width:92vw;max-height:88vh;border-radius:12px;object-fit:contain}
.lightbox-close{position:absolute;top:20px;right:20px;width:42px;height:42px;border-radius:12px;background:rgba(255,255,255,.12);border:none;color:#fff;cursor:pointer;font-size:22px;display:flex;align-items:center;justify-content:center}
.toast-wrap{position:fixed;top:18px;right:18px;z-index:999;display:flex;flex-direction:column;gap:8px;pointer-events:none}
.toast{padding:12px 18px;border-radius:12px;font-size:13.5px;font-weight:500;background:var(--surface);border:1px solid var(--border-hi);box-shadow:0 8px 24px rgba(0,0,0,.5);animation:slideRight .22s ease;max-width:300px}
.toast.ok{border-color:rgba(52,211,153,.4);color:#6ee7b7}
.toast.err{border-color:rgba(248,113,113,.4);color:#f87171}
@keyframes slideRight{from{opacity:0;transform:translateX(16px)}to{opacity:1;transform:translateX(0)}}

/* PAGAL PAGES */
.pagal-wrap{padding:32px;max-width:900px;margin:0 auto}
.pagal-wrap h1{font-family:'Sora',sans-serif;font-size:22px;font-weight:700;margin-bottom:24px}
.pagal-nav{display:flex;gap:10px;margin-bottom:28px;flex-wrap:wrap}
.pagal-nav a{padding:9px 18px;border-radius:10px;background:var(--surface2);border:1px solid var(--border);color:var(--text-dim);font-size:13.5px;font-weight:500;transition:all .16s;text-decoration:none}
.pagal-nav a:hover,.pagal-nav a.active{background:rgba(99,102,241,.15);color:#a5b4fc;border-color:rgba(99,102,241,.4)}
.card{background:var(--surface);border:1px solid var(--border-hi);border-radius:18px;padding:24px;margin-bottom:20px}
.card h2{font-family:'Sora',sans-serif;font-size:16px;font-weight:600;margin-bottom:18px;color:var(--text)}

/* ══════════════════════════════════════════════════
   MOBILE
   ══════════════════════════════════════════════════ */
@media (max-width:700px) {
  :root { --sidebar:100vw; }

  /* On mobile, sidebar is a full-screen overlay */
  .sidebar {
    width: 100vw;
    z-index: 100;
  }
  .sidebar.hidden { transform: translateX(-100%); }

  /* Chat area fills full screen on mobile */
  .chat-area { left: 0; }

  /* Show back button on mobile */
  .btn-back-mobile { display: block; }

  /* Bigger touch targets */
  .tool-btn  { width:42px; height:42px; font-size:20px; }
  .send-btn  { width:46px; height:46px; font-size:20px; }
  .msg-input { font-size:16px; } /* prevents iOS zoom on focus */

  /* Smaller bubbles */
  .msg-bubble-wrap { max-width:86%; }
  .msg-bubble      { font-size:14px; padding:9px 12px; }
  .messages-wrap   { padding:12px 10px 8px; }

  /* Reaction picker centered fixed on mobile */
  .reaction-picker {
    position: fixed !important;
    bottom: 90px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    top: auto !important;
    z-index: 600 !important;
  }

  .login-card { padding:32px 20px; }
  .form-grid  { grid-template-columns:1fr; }
  .form-grid .span2 { grid-column:span 1; }
  .theme-grid { grid-template-columns:1fr; }
  .pagal-wrap { padding:16px; }
  .pagal-nav  { gap:6px; }
  .pagal-nav a { padding:8px 12px; font-size:12.5px; }
}

/* Desktop: sidebar always visible by default, toggle button always shown */
@media (min-width:701px) {
  .btn-back-mobile { display:none !important; }
  /* sidebar-toggle-btn always visible on desktop too */
  #sidebar-toggle-btn { display:flex; }
}

/* ── ACTION SHEET ── */
.as-btn {
  display: block;
  width: 100%;
  padding: 16px 24px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.as-btn:active { background: var(--surface2); }
.as-danger { color: var(--danger) !important; }
.as-cancel {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-muted) !important;
  text-align: center !important;
  font-size: 15px;
}

/* ── AUDIO BUBBLE ── */
.audio-bubble { background: var(--surface2) !important; padding: 10px 12px !important; border: 1px solid var(--border) !important; }
.msg-group.out .audio-bubble { background: rgba(99,102,241,.25) !important; border-color: rgba(99,102,241,.4) !important; }

.audio-player-wrap { display:flex; align-items:center; gap:10px; min-width:200px; max-width:260px; }
.audio-play-btn { width:36px; height:36px; border-radius:50%; background:var(--primary); border:none; color:#fff; font-size:13px; display:flex; align-items:center; justify-content:center; cursor:pointer; flex-shrink:0; transition:opacity .15s; }
.audio-play-btn:hover { opacity:.85; }
.msg-group.out .audio-play-btn { background:rgba(255,255,255,.25); }
.audio-progress-wrap { flex:1; display:flex; flex-direction:column; gap:4px; }
.audio-progress-bar { height:4px; background:rgba(255,255,255,.15); border-radius:9px; overflow:hidden; cursor:pointer; }
.msg-group.out .audio-progress-bar { background:rgba(255,255,255,.2); }
.audio-progress-fill { height:100%; background:var(--primary); border-radius:9px; width:0%; transition:width .1s linear; }
.msg-group.out .audio-progress-fill { background:rgba(255,255,255,.7); }
.audio-duration { font-size:10.5px; color:var(--text-muted); }
.msg-group.out .audio-duration { color:rgba(255,255,255,.6); }

/* Voice recording pulse */
@keyframes recPulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(1.3)} }

/* ── GALLERY ── */
.gallery-item { position:relative; border-radius:10px; overflow:hidden; cursor:pointer; aspect-ratio:1; background:var(--surface2); }
.gallery-item img { width:100%; height:100%; object-fit:cover; display:block; transition:transform .2s; }
.gallery-item:hover img { transform:scale(1.04); }
.gallery-item-meta { position:absolute; bottom:0; left:0; right:0; padding:4px 7px; background:linear-gradient(transparent,rgba(0,0,0,.6)); font-size:10.5px; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* ── ATTACHMENT TRAY ── */
#attach-tray {
  display: none;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.tray-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 22px;
  background: var(--surface2);
  border: 1px solid var(--border-hi);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.tray-btn:hover, .tray-btn:active { background: var(--surface3); }
/* + button rotates to × when tray open */
#attach-btn { transition: transform .2s ease, background .15s; font-size: 22px; font-weight: 300; }
#attach-btn.open { transform: rotate(45deg); background: rgba(99,102,241,.15); border-color: rgba(99,102,241,.4); color: #818cf8; }
