
:root {
  --bg-color: #0b0d10;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --card-bg: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.08);
  --msg-me: #6366f1;
  --msg-them: rgba(255, 255, 255, 0.08);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --input-bg: rgba(255, 255, 255, 0.05);
  --modal-bg: rgba(11, 13, 16, 0.92);
}

body.light-theme {
  --bg-color: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --msg-me: #6366f1;
  --msg-them: #f1f5f9;
  --input-bg: #f1f5f9;
  --modal-bg: rgba(248, 250, 252, 0.92);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: none;
  display: flex;
  flex-direction: column;
}

body::before {
  content: ''; position: fixed; top: -30%; left: -20%; width: 70%; height: 70%;
  background: radial-gradient(circle, var(--accent) 0%, transparent 60%);
  opacity: 0.12; filter: blur(120px); z-index: -1; pointer-events: none;
}

.reconnect-banner {
  background-color: var(--danger); color: #fff; text-align: center;
  padding: 0.4rem; font-size: 0.85rem; font-weight: 500; z-index: 9999;
}

.top-nav { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; z-index: 10; flex-shrink: 0; }
.logo { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.5px; display: flex; align-items: center; cursor: pointer; user-select: none; }
.logo:hover { opacity: 0.85; }

.controls { display: flex; gap: 0.5rem; align-items: center; }

.custom-select-wrapper { position: relative; display: inline-flex; align-items: center; }
.glass-select.minimal {
  appearance: none; -webkit-appearance: none;
  background: transparent; color: var(--text-primary); border: none;
  padding: 0.5rem 1.5rem 0.5rem 0.5rem; font-weight: 500; font-size: 0.95rem; cursor: pointer; outline: none;
}
.glass-select.minimal option { background: var(--bg-color); color: var(--text-primary); }
.select-icon { position: absolute; right: 0.5rem; pointer-events: none; color: var(--text-secondary); }

.glass-input {
  background: var(--input-bg); border: 1px solid var(--card-border);
  color: var(--text-primary); padding: 0.75rem 1rem; border-radius: 8px;
  font-family: inherit; font-size: 16px; outline: none; transition: border-color 0.2s;
}
.glass-input:focus { border-color: var(--accent); }

button { cursor: pointer; border: none; outline: none; font-family: inherit; transition: all 0.2s ease; display: inline-flex; align-items: center; justify-content: center; }
.btn-primary {
  background: var(--accent); color: #fff; padding: 0.875rem 1.75rem;
  border-radius: 10px; font-weight: 500; font-size: 1rem;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary {
  background: var(--card-bg); color: var(--text-primary); border: 1px solid var(--card-border);
  padding: 0.875rem 1.5rem; border-radius: 10px; font-weight: 500;
}
.btn-secondary:hover { background: rgba(255,255,255,0.06); }

.full { width: 100%; }
.icon-btn { background: transparent; color: var(--text-secondary); padding: 0.4rem; border-radius: 50%; min-width: 36px; min-height: 36px; }
.icon-btn:hover { background: var(--card-bg); color: var(--text-primary); }
.icon-btn.accent { color: var(--accent); }
.text-btn { background: transparent; color: var(--text-secondary); font-weight: 500; font-size: 0.95rem; }
.text-btn:hover { color: var(--text-primary); }
.text-btn.inline { padding: 0 0.4rem; color: var(--accent); }

.glass-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-radius: 16px;
}

.user-menu-container { position: relative; }
.profile-btn { display: flex; align-items: center; gap: 0.5rem; background: var(--card-bg); padding: 0.4rem 0.8rem; border-radius: 20px; border: 1px solid var(--card-border); }

main { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }

/* STRICT VIEW ISOLATION FIX */
.view { display: none !important; flex: 1; flex-direction: column; align-items: center; justify-content: center; padding: 1.25rem; text-align: center; height: 100%; }
.view.active { display: flex !important; animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.hidden { display: none !important; }

/* Landing */
.hero { max-width: 500px; width: 100%; }
.badge {
  display: inline-block; background: rgba(99, 102, 241, 0.1); color: var(--accent);
  padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; margin-bottom: 1.25rem; border: 1px solid rgba(99, 102, 241, 0.2); letter-spacing: 0.5px;
}
.hero h1 { font-size: 3rem; font-weight: 600; margin-bottom: 1rem; line-height: 1.1; letter-spacing: -1px; }
.subtitle { color: var(--text-secondary); font-size: 1.05rem; line-height: 1.5; margin-bottom: 2rem; }
.action-group { display: flex; gap: 0.75rem; justify-content: center; margin-bottom: 2rem; flex-wrap: wrap; }
.stats { color: var(--text-secondary); font-size: 0.85rem; display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.pulse-dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse 2s infinite; }
.pulse-dot.green { background: #10b981; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); } 70% { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0); } 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); } }

/* Modals */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--modal-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); z-index: 200; align-items: center; justify-content: center; padding: 1rem; }
.modal.active { display: flex; animation: modalFadeIn 0.2s ease-out; }
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content { width: 100%; max-width: 420px; padding: 1.5rem; text-align: left; position: relative; box-shadow: 0 20px 40px rgba(0,0,0,0.3); max-height: 90vh; overflow-y: auto; }
.modal-content.wide { max-width: 480px; }
.modal-content.extra-wide { max-width: 600px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-header h2 { font-size: 1.2rem; font-weight: 600; }
.close-modal { margin: -0.5rem; }

/* Filter Specifics */
.section-title { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: var(--accent); letter-spacing: 0.8px; margin-bottom: 0.75rem; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-group { margin-bottom: 0.5rem; }
.form-group label { display: block; margin-bottom: 0.3rem; color: var(--text-secondary); font-size: 0.8rem; }
.form-group .custom-select-wrapper { display: flex; background: var(--input-bg); border: 1px solid var(--card-border); border-radius: 8px; }
.form-group select.minimal { padding: 0.55rem 1.75rem 0.55rem 0.75rem; width: 100%; font-size: 0.9rem; }
.form-divider { height: 1px; background: var(--card-border); margin: 1rem 0; }

.nsfw-compact { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem; background: rgba(239, 68, 68, 0.05); border: 1px solid rgba(239, 68, 68, 0.2); border-radius: 10px; }
.nsfw-info { display: flex; flex-direction: column; }
.nsfw-label { font-weight: 500; font-size: 0.9rem; color: #fca5a5; }
body.light-theme .nsfw-label { color: #dc2626; }
.nsfw-hint { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--card-border); transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--danger); }
input:checked + .slider:before { transform: translateX(20px); }

.auth-toggle { margin-top: 1.5rem; text-align: center; font-size: 0.9rem; color: var(--text-secondary); }
.error-msg { background: rgba(239, 68, 68, 0.1); color: var(--danger); padding: 0.75rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.85rem; border: 1px solid rgba(239,68,68,0.2); text-align: center; }
.success-msg { background: rgba(16, 185, 129, 0.1); color: var(--success); padding: 0.75rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.85rem; border: 1px solid rgba(16,185,129,0.2); text-align: center; }

/* Admin Dashboard */
.admin-stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; }
.stat-card { background: var(--input-bg); border: 1px solid var(--card-border); padding: 1rem; border-radius: 10px; text-align: center; display: flex; flex-direction: column; }
.stat-num { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.stat-lbl { font-size: 0.7rem; color: var(--text-secondary); margin-top: 0.2rem; }
.admin-reports-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; max-height: 250px; overflow-y: auto; }
.report-item { background: var(--input-bg); border: 1px solid var(--card-border); padding: 0.75rem; border-radius: 8px; font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.5rem; }
.report-meta { display: flex; flex-direction: column; gap: 0.2rem; }
.report-reason { color: var(--danger); font-weight: 500; }
.report-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }
.report-actions button { padding: 0.4rem 0.75rem; font-size: 0.75rem; border-radius: 6px; }

/* History List */
.history-list { display: flex; flex-direction: column; gap: 0.75rem; }
.history-item { padding: 1rem; background: var(--input-bg); border-radius: 10px; border: 1px solid var(--card-border); }
.history-meta { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.history-empty { text-align: center; color: var(--text-secondary); padding: 2rem 0; font-size: 0.9rem; }

/* Search Animation */
.search-anim { position: relative; width: 90px; height: 90px; margin-bottom: 1.25rem; display: flex; align-items: center; justify-content: center; }
.circle { position: absolute; width: 100%; height: 100%; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; }
.circle.pulse { animation: ripple 2s cubic-bezier(0, 0.2, 0.8, 1) infinite; }
.circle.delayed { animation-delay: 1s; }
@keyframes ripple { 0% { transform: scale(0.5); opacity: 1; border-width: 4px; } 100% { transform: scale(1.5); opacity: 0; border-width: 0; } }

.broaden-box {
  background: transparent; padding: 0; margin-top: 1.5rem;
  max-width: 300px; width: 100%; text-align: center; animation: fadeIn 0.4s ease;
}
.btn-broaden {
  background: rgba(99, 102, 241, 0.15); color: #a5b4fc; border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 0.75rem 1.5rem; border-radius: 12px; font-weight: 600; font-size: 0.95rem; width: 100%; transition: all 0.2s;
}
body.light-theme .btn-broaden { background: rgba(99, 102, 241, 0.1); color: var(--accent); }
.btn-broaden:hover { background: var(--accent); color: #fff; }
.broaden-box p { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.6rem; }

/* Chat Layout */
.chat-layout { max-width: 720px; margin: 0 auto; padding: 0.5rem 1rem 1rem 1rem; width: 100%; justify-content: flex-start; position: relative; flex-direction: column; }
.chat-header { width: 100%; padding: 0.55rem 0.9rem; display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; position: relative; z-index: 100; flex-shrink: 0; }
.status-indicator { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; font-weight: 500; }
.chat-header-actions { display: flex; align-items: center; gap: 0.4rem; }

/* Sleeker Skip Button */
.btn-skip {
  background: rgba(99, 102, 241, 0.15); color: #a5b4fc; border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 0.35rem 0.75rem; border-radius: 8px; font-weight: 600; font-size: 0.8rem; gap: 0.35rem;
  transition: all 0.2s ease;
}
body.light-theme .btn-skip { background: rgba(99, 102, 241, 0.1); color: var(--accent); }
.btn-skip:hover { background: var(--accent); color: #fff; border-color: var(--accent); transform: translateY(-1px); }
.btn-skip:active { transform: translateY(0); }

.chat-menu-container { position: relative; }

.dropdown {
  position: absolute; top: calc(100% + 0.5rem); right: 0; padding: 0.4rem;
  display: flex; flex-direction: column; gap: 0.2rem; min-width: 170px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5); z-index: 150; border: 1px solid var(--card-border);
}
.dropdown.hidden { display: none !important; }
.dropdown button {
  padding: 0.55rem 0.85rem; text-align: left; background: transparent; color: var(--text-primary);
  border-radius: 6px; width: 100%; font-size: 0.85rem; justify-content: flex-start; gap: 0.5rem; font-weight: 500;
}
.dropdown button:hover { background: rgba(255,255,255,0.08); }
.dropdown button.danger { color: #fca5a5; }
body.light-theme .dropdown button.danger { color: #dc2626; }
.dropdown button.danger:hover { background: rgba(239, 68, 68, 0.15); }
.dropdown-divider { height: 1px; background: var(--card-border); margin: 0.2rem 0; }

.chat-messages { flex: 1; width: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; padding: 0.5rem 0.25rem; margin-bottom: 0.5rem; z-index: 1; scroll-behavior: smooth; }
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 2px; }

.msg { max-width: 78%; padding: 0.65rem 0.95rem; border-radius: 16px; font-size: 0.95rem; line-height: 1.4; animation: slideUp 0.15s ease-out; word-wrap: break-word; position: relative; }
.msg.me { background: var(--msg-me); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.them { background: var(--msg-them); color: var(--text-primary); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.p1 { background: rgba(99, 102, 241, 0.2); color: var(--text-primary); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.p2 { background: rgba(16, 185, 129, 0.2); color: var(--text-primary); align-self: flex-end; border-bottom-right-radius: 4px; }

.msg-img { max-width: 200px; border-radius: 10px; cursor: pointer; margin-top: 0.25rem; border: 1px solid rgba(255,255,255,0.1); transition: opacity 0.2s; }
.msg-img:hover { opacity: 0.9; }
.msg-time { font-size: 0.65rem; opacity: 0.75; margin-top: 0.25rem; display: block; text-align: right; }

.sys-msg { align-self: center; background: rgba(255,255,255,0.03); border: 1px solid var(--card-border); color: var(--text-secondary); font-size: 0.78rem; padding: 0.35rem 0.75rem; border-radius: 20px; margin: 0.4rem 0; }
.sys-msg.warning { border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }

.typing-indicator { font-size: 0.8rem; color: var(--text-secondary); text-align: left; width: 100%; margin-bottom: 0.4rem; display: flex; align-items: center; height: 18px; padding-left: 0.5rem; flex-shrink: 0;}
.typing-dot { display: inline-block; width: 4px; height: 4px; background: var(--text-secondary); border-radius: 50%; margin-right: 3px; animation: bounce 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

.chat-input-area { flex-shrink: 0; width: 100%; padding: 0.4rem 0.6rem; display: flex; gap: 0.4rem; align-items: center; border-radius: 24px; background: var(--card-bg); border: 1px solid var(--card-border); z-index: 10; margin-bottom: env(safe-area-inset-bottom); }
#chat-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text-primary); padding: 0.5rem 0.75rem; font-size: 16px; }
#chat-input::placeholder { color: var(--text-secondary); opacity: 0.7; }

@keyframes slideUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.lightbox { position: fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.95); z-index: 1000; display:flex; justify-content:center; align-items:center; flex-direction: column; }
.lightbox img { max-width: 95%; max-height: 90vh; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.close-lightbox { position: absolute; top: 1.5rem; right: 1.5rem; background: rgba(255,255,255,0.1); color: white; }

@media (max-width: 600px) {
  .top-nav { padding: 0.75rem 0.85rem; }
  .hero h1 { font-size: 2.2rem; }
  .view { padding: 1rem 0.75rem; }
  .action-group { flex-direction: column; width: 100%; }
  .action-group button { width: 100%; min-height: 48px; }
  .chat-layout { padding: 0.4rem 0.5rem 0.5rem 0.5rem; }
  .status-text { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .msg { max-width: 86%; font-size: 0.9rem; }
  .filter-grid { grid-template-columns: 1fr; gap: 0.4rem; }
  .modal-content { padding: 1.25rem 1rem; border-radius: 20px; }
  .btn-skip { padding: 0.35rem 0.65rem; font-size: 0.78rem; }
  .admin-stats-grid { grid-template-columns: 1fr; }
}
