/* Global styles */
:root {
  --bg: rgb(24,24,24);
  --surface: #1f1f1f;
  --surface-2: #242424;
  --text: #e9e9e9;
  --muted: #b5b5b5;
  --primary: #7c5cff;
  --primary-2: #6a4afb;
  --error: #ff6b6b;
  --ok: #27c93f;
  --focus: #9aa9ff;
  --ring: 0 0 0 3px rgba(124,92,255,0.35);
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: grid;
  place-items: center;
  padding: 24px;
}

/* Cards & layout */
.card {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 720px;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.06);
}

.card.narrow { max-width: 520px; }
.card.wide { max-width: 820px; }
.card.superwide { max-width: 1080px; }

.logo { font-size: 42px; text-align: center; }
.title { text-align: center; margin: 8px 0 4px; }
.subtitle { text-align: center; color: var(--muted); margin: 0 0 20px; }

.actions { display: flex; gap: 12px; justify-content: center; }
.btn {
  appearance: none;
  border: 0;
  background: #2c2c2c;
  color: var(--text);
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease, opacity .2s ease;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); opacity: 0.9; }

.btn.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  color: white;
}
.btn.ghost { background: #2b2b2b; }
.btn.text { background: transparent; color: var(--muted); padding-left: 0; padding-right: 0; }
.btn.back { margin-bottom: 8px; }
.btn.stretch { width: 100%; justify-content: center; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: white;
  animation: spin .9s linear infinite;
  display: none;
}
.btn.loading .spinner { display: inline-block; }
.btn.loading span:last-child { opacity: 0.75; }

@keyframes spin { to { transform: rotate(360deg) } }

/* Forms */
.form { display: grid; gap: 16px; margin-top: 12px; }
.field { display: grid; gap: 8px; }
.field span { font-weight: 600; }
.required { color: #ffadad; }

input[type="text"],
input[type="password"],
input[type="file"] {
  width: 100%;
  background: #2a2a2a;
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  padding: 12px 12px;
  border-radius: 12px;
  outline: none;
  transition: box-shadow .15s ease, border-color .15s ease;
}
input::placeholder { color: #8b8b8b; }
input:focus { box-shadow: var(--ring); border-color: var(--focus); }

.help { color: var(--muted); font-size: 12px; }

.pass-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.error { color: var(--error); min-height: 18px; }

/* Avatar */
.avatar-field { margin-top: 6px; }
.avatar-row { display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: center; }
.avatar-preview {
  width: 96px; height: 96px; border-radius: 50%;
  overflow: hidden; border: 2px solid rgba(255,255,255,0.08);
  background: #2a2a2a; display: grid; place-items: center;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Screens & modal */
.screen.hidden { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  z-index: 50;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.modal-backdrop.show { opacity: 1; pointer-events: all; }
.modal { width: min(540px, calc(100% - 32px)); }

/* Animations */
.animate-pop { animation: pop .28s ease both; }
@keyframes pop {
  from { transform: scale(.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.animate-slide-up { animation: slideUp .32s ease both; }
@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.animate-fade-in { animation: fadeIn .32s ease both; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

/* Toast */
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  transform: translateY(8px); opacity: 0; pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.toast .toast-content {
  background: #222;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  min-width: 280px;
}
.toast-title { font-weight: 700; margin-bottom: 2px; }
.toast-message { color: var(--muted); }
.toast-progress { height: 4px; background: #303030; border-radius: 999px; margin-top: 10px; overflow: hidden; }
.toast-bar { height: 4px; width: 0%; background: var(--primary); }

.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast.hidden { display: none; }

/* Utility */
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* App header */
.app-header {
  width: 100%;
  max-width: 1080px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* Settings drawer/backdrop */
.settings-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 70;
  display: grid; grid-template-columns: 1fr auto;
}
.settings-backdrop.hidden { display: none; }

.settings-drawer {
  width: min(520px, 100%);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-left: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow);
  padding: 16px;
}
.animate-slide-in { animation: slideIn .28s ease both; }
@keyframes slideIn {
  from { transform: translateX(12px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.settings-header { display: flex; align-items: center; justify-content: space-between; }
.settings-content { display: grid; gap: 16px; margin-top: 8px; }
.set-block { padding: 12px; border: 1px solid rgba(255,255,255,0.06); border-radius: 12px; }
.set-block.danger { border-color: rgba(255, 107, 107, 0.35); }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.lab { width: 110px; color: var(--muted); }
.small { font-size: 12px; }

.btn.danger { background: #3a2020; color: #ffb2b2; }
.btn.danger:hover { background: #432323; }

/* Theme FX for gradient mode */
#themeFX {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
  background:
    radial-gradient(600px circle at var(--x1,20%) var(--y1,30%), var(--gradA, #7c5cff), transparent 60%),
    radial-gradient(600px circle at var(--x2,80%) var(--y2,70%), var(--gradB, #1dd1a1), transparent 60%);
  animation: floatXY 12s ease-in-out infinite alternate;
}
@keyframes floatXY {
  0%   { --x1: 20%; --y1: 30%; --x2: 80%; --y2: 70%; }
  50%  { --x1: 30%; --y1: 55%; --x2: 65%; --y2: 35%; }
  100% { --x1: 15%; --y1: 40%; --x2: 85%; --y2: 60%; }
}

/* Raise stacking of app content above gradient layer */
#app { position: relative; z-index: 1; }

/* Settings footer spacing */
.settings-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }

/* Raise delete confirm above drawer */

/* Nice select */
.nice-select {
  background: #2b2b2b;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.nice-select:focus { box-shadow: var(--ring); border-color: var(--focus); }

/* Nice color input */
.nice-color {
  -webkit-appearance: none;
  appearance: none;
  width: 42px; height: 32px;
  background: transparent;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 0;
  cursor: pointer;
}
.nice-color::-webkit-color-swatch-wrapper { padding: 0; }
.nice-color::-webkit-color-swatch { border: none; border-radius: 6px; }
.nice-color::-moz-color-swatch { border: none; border-radius: 6px; }

/* Settings drawer close animation */
.settings-drawer.closing { animation: slideOut .26s ease both; }
@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(12px); opacity: 0; }
}

.nice-color { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12); }
.settings-content .set-block + .set-block { margin-top: 6px; }

/* Hub actions */
.card.hub { display: grid; place-items: center; padding: 28px 24px; }
.hub-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* Room layout */
.room-root { display: grid; gap: 12px; max-width: 1080px; }
.room-header, .room-main, .room-footer { padding: 14px 16px; }
.room-header { display: flex; align-items: center; justify-content: space-between; }
.room-title { font-weight: 800; }
.room-online { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); }
.room-online .pill { background: #2a2a2a; border: 1px solid rgba(255,255,255,0.06); padding: 6px 8px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; }
.room-online .pill img { width: 18px; height: 18px; border-radius: 50%; display:block; }

.room-main { height: 52vh; overflow: auto; }
.chat-list { display: grid; gap: 10px; }
.bubble { background: #1f1f1f; border: 1px solid rgba(255,255,255,0.06); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.bubble .head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.bubble .head img { width: 28px; height: 28px; border-radius: 50%; }
.bubble .head .uname { font-weight: 700; }
.bubble .msgs { display: grid; gap: 6px; }
.msg { white-space: pre-wrap; word-wrap: break-word; }
.msg .time { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* Footer input */
.input-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; }
.input-row input[type="text"] { background: #2a2a2a; border: 1px solid rgba(255,255,255,0.08); color: var(--text); padding: 12px; border-radius: 12px; }

/* Settings switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { display:none; }
.slider { position: absolute; inset: 0; background: #333; border-radius: 999px; transition: .2s; }
.slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #bbb; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(18px); background: white; }

/* Bigger overall room UI */
.room-root { max-width: 1280px; }
.room-main { height: 68vh; }
.card.hub { padding: 36px 32px; }

/* Presence label */
.room-online::before {
  content: "Online:";
  color: var(--muted);
  margin-right: 8px;
}

/* Custom scrollbar for the chat window */
.room-main {
  scrollbar-width: thin;
  scrollbar-color: var(--primary) #1a1a1a;
}
.room-main::-webkit-scrollbar {
  width: 10px;
}
.room-main::-webkit-scrollbar-track {
  background: #121212;
  border-radius: 10px;
}
.room-main::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  border-radius: 10px;
  border: 2px solid #121212;
}
.room-main::-webkit-scrollbar-thumb:hover {
  filter: brightness(1.1);
}

/* Room: make cards full-width within room-root and increase size */
.room-root { max-width: 1320px; }
.room-root .card { max-width: 100%; width: 100%; }
.room-main { height: 74vh; }

/* Force full-width cards within room and explicit container width */
.room-root { width: min(86vw, 1320px); }
.room-header, .room-main, .room-footer { width: 100%; }

/* Attachment sizing inside chat */
.chat-list .msg img,
.chat-list .msg video,
.chat-list .msg audio {
  display: block;
  margin-top: 6px;
  border-radius: 8px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow);
}
.chat-list .msg img {
  max-height: 480px;
  object-fit: contain;
}
.chat-list .msg video {
  max-height: 360px;
  object-fit: contain;
}
.chat-list .msg audio {
  max-width: 420px;
  border-radius: 10px;
  box-shadow: none;
}

.toast-copy-btn{padding:8px 12px;font-size:14px}


/* Typing indicator dots inside online pills */
.room-online .pill .typing-dots{ display:none; width:22px; justify-content:space-between; align-items:center; }
.room-online .pill .typing-dots i{ width:6px; height:6px; border-radius:50%; background: var(--primary); opacity:.9; animation: typingDot 1s infinite ease-in-out; display:block; }
.room-online .pill .typing-dots i:nth-child(2){ animation-delay:.15s; }
.room-online .pill .typing-dots i:nth-child(3){ animation-delay:.30s; }
.room-online .pill.typing .typing-dots{ display:inline-flex; }
@keyframes typingDot{ 0%,80%,100%{ transform: translateY(0);} 40%{ transform: translateY(-3px);} }

/* Settings drawer scrollable with same scrollbar as chat */
.settings-drawer{ max-height:92vh; overflow:auto; }
.settings-drawer{ scrollbar-width: thin; scrollbar-color: var(--primary) #1a1a1a; }
.settings-drawer::-webkit-scrollbar{ width:10px; }
.settings-drawer::-webkit-scrollbar-track{ background:#121212; border-radius:10px; }
.settings-drawer::-webkit-scrollbar-thumb{ background: linear-gradient(180deg, var(--primary), var(--primary-2)); border-radius:10px; border:2px solid #121212; }
.settings-drawer::-webkit-scrollbar-thumb:hover{ filter: brightness(1.1); }


/* === Patch: Settings drawer should reach the bottom of the screen === */
.settings-backdrop { 
  align-items: stretch; /* ensure right column (drawer) stretches full height */
}
.settings-drawer {
  height: 100vh;              /* full viewport height */
  display: flex;              /* enable footer stick-to-bottom */
  flex-direction: column;
}
.settings-content {
  flex: 1;                    /* take remaining height */
  overflow: auto;             /* scroll if content exceeds viewport */
}

/* Match scrollbar styling to chat window for the settings content */
.settings-content {
  scrollbar-width: thin;
  scrollbar-color: var(--primary) #1a1a1a;
}
.settings-content::-webkit-scrollbar {
  width: 10px;
}
.settings-content::-webkit-scrollbar-track {
  background: #121212;
  border-radius: 10px;
}
.settings-content::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  border-radius: 10px;
  border: 2px solid #121212;
}
.settings-content::-webkit-scrollbar-thumb:hover {
  filter: brightness(1.1);
}
/* === End Patch === */

/* === Patch #2: Drawer flush to bottom === */
.settings-backdrop { padding-bottom: 0 !important; } /* remove bottom gap */
.settings-drawer { border-bottom-left-radius: 0; }   /* visually meets bottom edge */

/* === Patch #3: ensure drawer touches bottom of viewport === */
.settings-backdrop {
  grid-template-rows: 1fr !important; /* single full-height row */
}
.settings-drawer {
  height: 100vh !important;           /* hard-ensure full height */
  margin: 0 !important;               /* remove any bottom margin */
  align-self: stretch !important;     /* fill grid track */
}
