/*
 * qk-base.css  —  Quickyla unified design system
 * Used by: dm_page, dm_inbox, dm_thread, chat_rooms, chat_room, chat_room_locked
 * Font: Inter (single font, all weights)
 * Theme: dark by default, .qk-light class for light mode
 */

/* ── Font ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

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

/* ── Hide base.html chrome on full-screen chat pages ── */
nav.navbar, footer, .tax-bar, #taxBar, .fbs-sidebar { display: none !important; }
body { padding-top: 0 !important; overflow: hidden !important; }
main { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }

/* ── Design tokens — dark default ── */
:root {
  /* Backgrounds */
  --bg:         #0b0d14;
  --bg2:        #12141f;
  --bg3:        #1a1c2a;
  --bg4:        #20223a;

  /* Borders */
  --border:     #252840;
  --border2:    #2e3150;

  /* Text */
  --text:       #eeeeff;
  --text2:      #8890bb;
  --text3:      #4a5080;

  /* Accent — purple */
  --accent:     #7c6fff;
  --accent2:    #6a5fe0;
  --accent3:    #a78bfa;
  --accent-g:   rgba(124,111,255,.16);
  --accent-g2:  rgba(124,111,255,.08);

  /* Sent bubble */
  --own-bg:     linear-gradient(135deg, #7c6fff 0%, #a78bfa 100%);
  --own-text:   #ffffff;

  /* Status */
  --green:      #22d3a0;
  --green-g:    rgba(34,211,160,.12);
  --red:        #f43f5e;
  --amber:      #fbbf24;

  /* Misc */
  --radius:     14px;
  --radius-sm:  9px;
  --radius-xs:  6px;
  --font:       'Inter', sans-serif;
  --shadow:     0 4px 20px rgba(0,0,0,.5);
  --shadow-lg:  0 8px 40px rgba(0,0,0,.7);
  --topbar-h:   60px;
  --sidebar-w:  300px;
}

/* ── Light mode ── */
body.qk-light {
  --bg:         #f0f2ff;
  --bg2:        #ffffff;
  --bg3:        #f4f5fe;
  --bg4:        #eaecf8;
  --border:     #dde0f5;
  --border2:    #c8cce8;
  --text:       #0f1133;
  --text2:      #6366a0;
  --text3:      #9ca3c8;
  --accent:     #7c6fff;
  --accent2:    #6a5fe0;
  --accent3:    #5a4fd0;
  --accent-g:   rgba(124,111,255,.1);
  --accent-g2:  rgba(124,111,255,.05);
  --own-bg:     linear-gradient(135deg, #7c6fff 0%, #a78bfa 100%);
  --green:      #16a37a;
  --green-g:    rgba(22,163,122,.12);
  --red:        #e11d48;
  --amber:      #d97706;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.14);
}

/* ── Base ── */
html, body { height: 100%; height: 100dvh; }
body { font-family: var(--font); background: var(--bg); color: var(--text); }

/* ── Shared components ── */

/* Icon buttons */
.qk-btn-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: var(--bg3);
  cursor: pointer; font-size: .9rem; color: var(--text2);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s; text-decoration: none; flex-shrink: 0;
}
.qk-btn-icon:hover { border-color: var(--accent); color: var(--accent3); background: var(--accent-g); }
.qk-btn-icon.active { border-color: var(--accent); color: var(--accent3); background: var(--accent-g); }

/* Primary button */
.qk-btn-primary {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1.2rem; background: var(--own-bg); color: white;
  border: none; border-radius: var(--radius-sm); font-family: var(--font);
  font-size: .85rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 14px rgba(124,111,255,.35); transition: all .18s;
}
.qk-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(124,111,255,.5); }

/* Ghost button */
.qk-btn-ghost {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1.1rem; background: var(--bg3); color: var(--text2);
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  font-family: var(--font); font-size: .85rem; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.qk-btn-ghost:hover { border-color: var(--accent); color: var(--accent3); }

/* Send button */
.qk-btn-send {
  width: 38px; height: 38px; background: var(--own-bg); border: none;
  border-radius: var(--radius-sm); color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem; flex-shrink: 0; transition: all .18s;
  box-shadow: 0 3px 10px rgba(124,111,255,.4);
}
.qk-btn-send:hover { transform: scale(1.07); }
.qk-btn-send:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* Search input */
.qk-search-wrap { position: relative; }
.qk-search-wrap i.icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--text3); font-size: .82rem; pointer-events: none; }
.qk-search {
  width: 100%; padding: .55rem .85rem .55rem 2.2rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg3); font-family: var(--font);
  font-size: .83rem; color: var(--text); outline: none; transition: border-color .2s;
}
.qk-search:focus { border-color: var(--accent); }
.qk-search::placeholder { color: var(--text3); }

/* Textarea input */
.qk-textarea {
  flex: 1; border: none; background: none; outline: none;
  font-family: var(--font); font-size: .9rem; color: var(--text);
  resize: none; max-height: 100px; line-height: 1.55; padding: .2rem 0;
}
.qk-textarea::placeholder { color: var(--text3); }

/* Input wrap (the pill around textarea + buttons) */
.qk-input-wrap {
  display: flex; align-items: flex-end; gap: .3rem;
  background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: 20px; padding: .5rem .5rem .5rem .9rem;
  transition: border-color .2s, box-shadow .2s;
}
.qk-input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-g2); }

/* Input bar (the container below messages) */
.qk-input-bar {
  padding: .65rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg2);
  flex-shrink: 0;
}

/* Sidebar shell */
.qk-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
.qk-sidebar-header {
  padding: .9rem 1rem .75rem;
  background: linear-gradient(180deg, var(--bg2) 80%, transparent);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.qk-sidebar-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: .65rem; }
.qk-sidebar-brand-icon {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: var(--own-bg); display: flex; align-items: center;
  justify-content: center; font-size: .9rem; color: white;
  box-shadow: 0 4px 12px rgba(124,111,255,.4);
}
.qk-sidebar-brand-name { font-size: .95rem; font-weight: 800; flex: 1; color: var(--text); }
.qk-sidebar-list { flex: 1; overflow-y: auto; padding: .3rem .4rem; }
.qk-sidebar-list::-webkit-scrollbar { width: 3px; }
.qk-sidebar-list::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* Contact / conversation item */
.qk-convo-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .65rem .6rem; border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none; transition: background .12s;
}
.qk-convo-item:hover { background: var(--bg3); }
.qk-convo-item.active { background: var(--accent-g); }

/* Avatar */
.qk-ava {
  flex-shrink: 0; border-radius: 50%; overflow: hidden;
  background: var(--own-bg); display: flex; align-items: center;
  justify-content: center; font-weight: 800; color: white;
  position: relative;
}
.qk-ava img { width: 100%; height: 100%; object-fit: cover; }
.qk-ava.md { width: 42px; height: 42px; font-size: .95rem; }
.qk-ava.sm { width: 30px; height: 30px; font-size: .68rem; }
.qk-ava.lg { width: 40px; height: 40px; font-size: .88rem; }
.qk-ava .online-dot {
  position: absolute; bottom: 0; right: 0;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--bg2);
}

/* Convo item info */
.qk-convo-info { flex: 1; min-width: 0; }
.qk-convo-name { font-size: .86rem; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qk-convo-preview { font-size: .73rem; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: .05rem; }
.qk-convo-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; flex-shrink: 0; }
.qk-convo-time { font-size: .63rem; color: var(--text3); }
.qk-unread-badge { background: var(--accent); color: white; font-size: .58rem; font-weight: 800; border-radius: 99px; padding: .1rem .4rem; min-width: 17px; text-align: center; }

/* Topbar */
.qk-topbar {
  height: var(--topbar-h); flex-shrink: 0;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1rem; gap: .7rem;
}
.qk-topbar-title { font-size: .95rem; font-weight: 800; color: var(--text); flex: 1; }
.qk-topbar-actions { display: flex; gap: .3rem; }

/* Messages area */
.qk-messages {
  flex: 1; overflow-y: auto; padding: 1rem 1.1rem;
  display: flex; flex-direction: column; gap: .25rem;
  scroll-behavior: smooth; min-height: 0;
}
.qk-messages::-webkit-scrollbar { width: 4px; }
.qk-messages::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* Message rows */
.qk-msg-row { display: flex; align-items: flex-end; gap: .45rem; animation: qkMsgIn .15s ease; }
@keyframes qkMsgIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:none; } }
.qk-msg-row.out { flex-direction: row-reverse; }

/* Message bubble */
.qk-bubble-col { max-width: min(500px, 74%); display: flex; flex-direction: column; }
.qk-msg-row.out .qk-bubble-col { align-items: flex-end; }
.qk-bubble {
  padding: .6rem .9rem; border-radius: var(--radius-xs) var(--radius) var(--radius) var(--radius);
  font-size: .88rem; line-height: 1.6; word-break: break-word;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text); position: relative; transition: filter .12s;
}
.qk-bubble:hover { filter: brightness(1.06); }
.qk-msg-row.out .qk-bubble {
  background: var(--own-bg); border-color: transparent; color: white;
  border-radius: var(--radius) var(--radius-xs) var(--radius) var(--radius);
  box-shadow: 0 4px 14px rgba(124,111,255,.3);
}
.qk-bubble-meta {
  font-size: .62rem; color: var(--text3); margin-top: .14rem;
  display: flex; align-items: center; gap: .25rem; padding: 0 .1rem;
}
.qk-msg-row.out .qk-bubble-meta { justify-content: flex-end; color: rgba(255,255,255,.4); }

/* Date separator */
.qk-date-sep {
  display: flex; align-items: center; gap: .5rem; margin: .6rem 0;
  font-size: .68rem; color: var(--text3); font-weight: 600;
}
.qk-date-sep::before, .qk-date-sep::after { content:''; flex:1; height:1px; background:var(--border); }

/* System message */
.qk-sys-msg { text-align: center; font-size: .72rem; color: var(--text3); font-style: italic; margin: .3rem 0; }

/* Typing indicator */
.qk-typing { display: none; align-items: center; gap: .45rem; padding: .3rem 1rem; font-size: .78rem; color: var(--text2); font-style: italic; }
.qk-typing.show { display: flex; }
.qk-typing-dots span { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--text2); animation: qkBounce 1.2s infinite; }
.qk-typing-dots span:nth-child(2) { animation-delay: .2s; }
.qk-typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes qkBounce { 0%,60%,100%{transform:translateY(0);} 30%{transform:translateY(-5px);} }

/* Reply bar */
.qk-reply-bar { display: none; align-items: center; gap: .6rem; padding: .5rem 1rem; background: var(--bg2); border-top: 1px solid var(--border); }
.qk-reply-bar.show { display: flex; }
.qk-reply-bar-info { flex: 1; min-width: 0; }
.qk-reply-bar-author { font-size: .72rem; font-weight: 700; color: var(--accent3); }
.qk-reply-bar-text { font-size: .78rem; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Context menu */
.qk-ctx-menu {
  position: fixed; z-index: 5000;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: .35rem; min-width: 168px;
  box-shadow: var(--shadow-lg); display: none;
  animation: qkCtxIn .1s ease;
}
.qk-ctx-menu.show { display: block; }
@keyframes qkCtxIn { from{opacity:0;transform:scale(.95);} to{opacity:1;transform:none;} }
.qk-ctx-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .55rem .8rem; border-radius: var(--radius-sm); cursor: pointer;
  font-size: .83rem; font-weight: 600; color: var(--text2); transition: all .12s;
}
.qk-ctx-item:hover { background: var(--bg3); color: var(--text); }
.qk-ctx-item.danger:hover { background: rgba(244,63,94,.1); color: var(--red); }
.qk-ctx-item i { font-size: .88rem; width: 16px; flex-shrink: 0; }

/* Reaction popup */
.qk-react-popup {
  position: fixed; z-index: 5001;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 99px; padding: .35rem .5rem;
  display: none; gap: .15rem; box-shadow: var(--shadow);
  animation: qkCtxIn .12s ease;
}
.qk-react-popup.show { display: flex; }
.qk-react-btn { background: none; border: none; cursor: pointer; font-size: 1.2rem; padding: .1rem .25rem; border-radius: 99px; transition: transform .1s; }
.qk-react-btn:hover { transform: scale(1.3); }

/* Sidebar footer (QK code) */
.qk-sidebar-footer {
  padding: .75rem 1rem; border-top: 1px solid var(--border);
  background: var(--bg2); flex-shrink: 0;
}
.qk-code-row {
  display: flex; align-items: center; gap: .45rem;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: .5rem .75rem;
}
.qk-code-val { font-family: 'Courier New', monospace; font-size: .85rem; font-weight: 800; color: var(--accent3); flex: 1; letter-spacing: .05em; }
.qk-code-copy { background: var(--own-bg); color: white; border: none; border-radius: 6px; padding: .25rem .6rem; font-size: .68rem; font-weight: 700; cursor: pointer; font-family: var(--font); }

/* Lightbox */
.qk-lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 9999; display: none; align-items: center; justify-content: center; backdrop-filter: blur(8px); cursor: pointer; }
.qk-lightbox.active { display: flex; }
.qk-lightbox img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius); }
.qk-lightbox-close { position: absolute; top: 1rem; right: 1rem; background: rgba(255,255,255,.12); border: none; color: white; font-size: 1.4rem; cursor: pointer; width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

/* Toast stack */
.qk-toasts { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .35rem; pointer-events: none; }
.qk-toast { background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--radius-sm); padding: .6rem .9rem; display: flex; align-items: center; gap: .5rem; box-shadow: var(--shadow); animation: qkToastIn .2s ease; font-size: .83rem; pointer-events: auto; }
@keyframes qkToastIn { from{opacity:0;transform:translateY(8px);} to{opacity:1;transform:none;} }

/* Modal overlay */
.qk-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 8000; display: none; align-items: center; justify-content: center; padding: 1rem; backdrop-filter: blur(6px); }
.qk-modal-overlay.show { display: flex; }
.qk-modal { background: var(--bg2); border: 1px solid var(--border2); border-radius: 20px; padding: 1.5rem; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); animation: qkModalIn .2s ease; }
@keyframes qkModalIn { from{opacity:0;transform:scale(.95) translateY(10px);} to{opacity:1;transform:none;} }
.qk-modal-title { font-size: 1.05rem; font-weight: 800; margin-bottom: 1rem; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.qk-modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.2rem; }

/* Form inputs */
.qk-input {
  width: 100%; padding: .65rem .95rem;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg3); font-family: var(--font);
  font-size: .88rem; color: var(--text); outline: none; transition: border-color .2s;
}
.qk-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-g2); }
.qk-input::placeholder { color: var(--text3); }
.qk-label { font-size: .82rem; font-weight: 600; color: var(--text2); display: block; margin-bottom: .35rem; }

/* Empty state */
.qk-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 3rem 1.5rem; color: var(--text2); gap: .75rem; flex: 1; }
.qk-empty-icon { width: 64px; height: 64px; border-radius: 18px; background: var(--accent-g); border: 1px solid var(--border2); display: flex; align-items: center; justify-content: center; font-size: 1.8rem; color: var(--accent3); }
.qk-empty-title { font-size: 1.05rem; font-weight: 800; color: var(--text); }
.qk-empty-sub { font-size: .85rem; color: var(--text2); max-width: 280px; line-height: 1.6; }

/* Mobile sidebar overlay */
.qk-sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 790; }
.qk-sidebar-overlay.active { display: block; }

/* Bootstrap alert fix */
.alert.alert-dismissible { display: none !important; }

/* Mobile */
@media (max-width: 700px) {
  :root { --sidebar-w: 100vw; --topbar-h: 54px; }
  .qk-sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 800; transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1); box-shadow: 6px 0 24px rgba(0,0,0,.5); width: min(300px, 88vw); }
  .qk-sidebar.open { transform: translateX(0); }
  .qk-messages { padding: .75rem .65rem; }
  .qk-bubble-col { max-width: 86%; }
}