:root {
  --bg: #0f111a;
  --surface: #171a26;
  --surface-2: #202536;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --accent: #f59e0b;
  --bubble-me: #b45309;
  --bubble-other: #1e2333;
  --chat-wallpaper: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100dvh; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}

.hidden { display: none !important; }
.view { height: 100dvh; width: 100vw; }
.min-w-0 { min-width: 0; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.bold { font-weight: 600; }
.accent-text { color: var(--accent); }
.full-width { width: 100%; }

/* Privacy Curtain */
.curtain {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(9, 11, 18, 0.96); backdrop-filter: blur(22px);
  display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer;
}
.curtain-box h2 { margin: 8px 0 4px; font-size: 20px; }

.center-screen { display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 36px 28px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.login-logo { width: 76px; height: 76px; border-radius: 20px; margin-bottom: 12px; }
.login-card h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: 0.4px; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #111; font-weight: 700; text-decoration: none;
  border: none; border-radius: 12px; padding: 12px 18px; cursor: pointer; font-size: 15px;
}
.btn-secondary {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn-danger {
  background: rgba(239, 68, 68, 0.16); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: 13px; font-weight: 700;
}
.icon-btn {
  background: transparent; border: none; color: var(--text); font-size: 17px;
  padding: 6px 7px; border-radius: 10px; cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.mini-btn {
  background: var(--surface-2); color: var(--accent); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 9px; font-size: 11px; font-weight: 600; cursor: pointer;
}
.pill-btn {
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.pill-btn.active { background: var(--accent); color: #111; border-color: var(--accent); }
.ttl-select {
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 6px; font-size: 11px; outline: none; max-width: 68px; flex-shrink: 0;
}
.ttl-select.active { color: var(--accent); border-color: var(--accent); }

#app-view { display: flex; }

.sidebar {
  width: 290px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; z-index: 25;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; border-bottom: 1px solid var(--border);
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; border-radius: 10px; }
.brand-title { font-weight: 700; font-size: 16px; }
.icon-actions { display: flex; align-items: center; gap: 2px; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 10px; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: 0.8px;
  padding: 12px 8px 6px;
}
.list { display: flex; flex-direction: column; gap: 3px; }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border-radius: 12px; cursor: pointer; transition: background 0.15s;
}
.list-item:hover { background: var(--surface-2); }
.list-item.active { background: rgba(245, 158, 11, 0.16); border: 1px solid rgba(245, 158, 11, 0.35); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  position: relative; flex-shrink: 0;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%; background: #4b5563;
  position: absolute; bottom: 0; right: 0; border: 2px solid var(--surface);
}
.dot.online { background: #22c55e; }
.item-meta { min-width: 0; flex: 1; }
.item-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top));
}
.chat-header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-only { display: none; }

/* Search & Date Bar */
.search-bar {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
#search-input, #jump-date-input {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; outline: none;
}
#search-input { flex: 1; min-width: 0; }
#jump-date-input { max-width: 135px; }
.search-results {
  max-height: 220px; overflow-y: auto; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 6px 12px;
}
.search-hit {
  padding: 8px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px;
}
.search-hit:last-child { border-bottom: none; }

.messages-wrap {
  flex: 1; overflow-y: auto; position: relative;
  background-image: var(--chat-wallpaper); background-size: cover; background-position: center;
}
.load-older-wrap { text-align: center; padding: 10px 0 0; }
.messages {
  padding: 12px 14px 18px; display: flex; flex-direction: column; gap: 10px;
  min-height: 100%; background: rgba(0, 0, 0, 0.22);
}

.date-divider {
  align-self: center; background: rgba(0,0,0,0.45); color: var(--muted);
  font-size: 11px; padding: 3px 10px; border-radius: 999px; margin: 4px 0;
}
.msg-row { display: flex; flex-direction: column; max-width: 80%; }
.msg-row.me { align-self: flex-end; align-items: flex-end; }
.msg-row.other { align-self: flex-start; align-items: flex-start; }
.msg-sender { font-size: 11px; color: var(--muted); margin: 0 8px 3px; }
.bubble {
  background: var(--bubble-other); color: var(--text); padding: 10px 13px;
  border-radius: 16px; border-bottom-left-radius: 4px; position: relative;
  word-wrap: break-word; line-height: 1.42; font-size: 14.5px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.msg-row.me .bubble {
  background: var(--bubble-me); border-bottom-left-radius: 16px; border-bottom-right-radius: 4px;
}
.bubble.deleted-bubble { font-style: italic; opacity: 0.6; }
.reply-quote {
  font-size: 12px; background: rgba(0,0,0,0.25); border-left: 3px solid var(--accent);
  padding: 5px 8px; border-radius: 6px; margin-bottom: 6px;
}
.msg-media { max-width: 260px; max-height: 300px; border-radius: 10px; display: block; margin-top: 4px; }
.msg-audio { width: 225px; margin-top: 4px; }
.file-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(0,0,0,0.28); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; margin-top: 4px; min-width: 210px;
}
.file-meta { min-width: 0; flex: 1; }
.file-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-link {
  display: inline-block; margin-top: 5px; font-size: 11.5px; color: var(--accent);
  text-decoration: none; font-weight: 600;
}
.vo-card {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px;
  border-radius: 12px; background: rgba(0,0,0,0.28); border: 1px dashed var(--accent);
  color: var(--text); cursor: pointer; font-weight: 600; font-size: 13.5px;
}
.vo-card.opened { border-style: solid; border-color: var(--border); color: var(--muted); cursor: default; font-style: italic; }

.msg-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 5px;
  margin-top: 4px; font-size: 10.5px; color: rgba(255,255,255,0.68);
}
.seen-tick { color: #38bdf8; font-weight: 700; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 3px; opacity: 0.72; margin-top: 2px; }
.msg-action-btn { background: none; border: none; color: var(--muted); font-size: 11.5px; cursor: pointer; padding: 2px 4px; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react-chip {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 7px; font-size: 12px; cursor: pointer; color: var(--text);
}

.typing-bar { padding: 4px 16px; font-size: 12px; color: var(--accent); background: var(--surface); }
.reply-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px; background: var(--surface-2); border-top: 1px solid var(--border);
}
.reply-bar-text { display: flex; flex-direction: column; min-width: 0; }

.composer {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
#msg-input {
  flex: 1; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 20px; padding: 9px 13px; font-size: 15px; outline: none; min-width: 0;
}
.send-btn { border-radius: 50%; width: 38px; height: 38px; padding: 0; flex-shrink: 0; }
.recording { color: #ef4444 !important; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Modals & Drawers */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 60;
}
.modal-card {
  width: 100%; max-width: 420px; max-height: 85dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 17px; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface-2); padding: 10px 12px; border-radius: 12px; cursor: pointer;
}
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-chip {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 11px; font-size: 12px; cursor: pointer;
}
.preset-chip.active { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }
.drawer-list { display: flex; flex-direction: column; gap: 8px; max-height: 55dvh; overflow-y: auto; }
.drawer-item {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; font-size: 13px; display: flex; flex-direction: column; gap: 4px;
}
.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.color-grid label { display: flex; align-items: center; justify-content: space-between; font-size: 13px; background: var(--surface-2); padding: 8px 10px; border-radius: 10px; }
.wallpaper-row { display: flex; gap: 8px; }
.wallpaper-row button { flex: 1; }
.text-field {
  width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 14px;
}
.members-checklist { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.member-opt { display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--surface-2); border-radius: 10px; font-size: 14px; }

/* View-Once Fullscreen */
.fullscreen-modal { flex-direction: column; background: #000; padding: 0; user-select: none; }
.vo-top { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); }
.vo-badge { background: var(--accent); color: #111; font-weight: 700; padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.vo-content { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; padding: 10px; }
.vo-content img, .vo-content video { max-width: 100%; max-height: 80dvh; border-radius: 12px; }
.vo-content iframe { width: 95vw; height: 78dvh; border: none; background: #fff; border-radius: 10px; }
.vo-caption { padding: 14px; text-align: center; font-size: 15px; }

/* Calls */
.call-banner {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(92vw, 400px); background: var(--surface); border: 1px solid var(--accent);
  border-radius: 16px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6); z-index: 85;
}
.btn-accept { background: #22c55e; color: #052e16; font-weight: 700; border: none; border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.btn-decline { background: #ef4444; color: #fff; font-weight: 700; border: none; border-radius: 10px; padding: 8px 14px; cursor: pointer; }

.call-overlay { position: fixed; inset: 0; background: #07080d; z-index: 90; display: flex; flex-direction: column; }
#remote-video { width: 100%; height: 100%; object-fit: cover; }
#local-video {
  position: absolute; top: max(70px, env(safe-area-inset-top)); right: 16px;
  width: 110px; height: 155px; object-fit: cover; border-radius: 14px;
  border: 2px solid var(--accent); background: #111;
}
.call-status-bar {
  position: absolute; top: max(18px, env(safe-area-inset-top)); left: 16px;
  background: rgba(0,0,0,0.55); padding: 8px 14px; border-radius: 12px;
}
.call-controls {
  position: absolute; bottom: max(28px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; background: rgba(15,17,26,0.8); padding: 12px 18px; border-radius: 999px;
}
.call-ctrl-btn {
  width: 52px; height: 52px; border-radius: 50%; border: none; background: var(--surface-2);
  color: #fff; font-size: 20px; cursor: pointer;
}
.call-ctrl-btn.off { background: #6b7280; opacity: 0.65; }
.call-ctrl-btn.hangup { background: #ef4444; }

@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 82vw; max-width: 310px; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vw rgba(0,0,0,0.55); }
  .msg-row { max-width: 88%; }
}
