:root {
  --bg-primary: #0a0e1a;
  --bg-card: #111827;
  --bg-card-hover: #1a2236;
  --bg-surface: #0d1321;
  --border: #1e293b;
  --border-light: #2a3650;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; color: inherit; }
input, textarea { font-family: inherit; }

/* LOGIN */
.login-screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background: #0e1121; position: relative; overflow: hidden; }
.login-screen::before { content: ''; position: fixed; inset: 0; background: radial-gradient(ellipse 60% 50% at 20% 20%, rgba(99,102,241,0.08) 0%, transparent 60%), radial-gradient(ellipse 50% 40% at 80% 80%, rgba(139,92,246,0.06) 0%, transparent 60%); pointer-events: none; }
.login-card { background: rgba(255,255,255,0.05); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid rgba(255,255,255,0.1); border-radius: 20px; padding: 48px 40px; width: 100%; max-width: 400px; text-align: center; position: relative; z-index: 1; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 40px; }
.brand .logo { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.brand-logo { width: 72px; height: 72px; border-radius: 50%; }
.brand h1 { font-size: 1.5rem; font-weight: 700; color: #fff; }
.brand h1 span { color: var(--accent-light); }
.brand p { font-size: 0.75rem; color: rgba(255,255,255,0.4); letter-spacing: 2px; text-transform: uppercase; margin-top: -8px; }
#login-form { text-align: left; }
.form-group { margin-bottom: 14px; }
#login-form label { display: block; font-size: 0.75rem; font-weight: 500; color: rgba(255,255,255,0.5); margin-bottom: 6px; letter-spacing: 0.5px; text-transform: uppercase; }
#login-form input { width: 100%; padding: 13px 16px; background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; color: #fff; font-size: 0.9375rem; outline: none; transition: border-color 0.2s, background 0.2s; }
#login-form input::placeholder { color: rgba(255,255,255,0.25); }
#login-form input:focus { border-color: rgba(255,255,255,0.35); background: rgba(255,255,255,0.1); }
#login-form button[type="submit"] { width: 100%; padding: 14px; background: #fff; color: #0e1121; border: none; border-radius: 10px; font-size: 0.9375rem; font-weight: 700; cursor: pointer; margin-top: 8px; transition: opacity 0.2s, transform 0.1s; }
#login-form button[type="submit"]:hover { opacity: 0.92; }
.error { margin-top: 14px; padding: 10px 14px; background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); border-radius: 8px; color: #fca5a5; font-size: 0.875rem; min-height: 1.1em; text-align: center; }
.hint { margin-top: 32px; font-size: 0.75rem; color: rgba(255,255,255,0.2); }

/* APP */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--bg-surface); border-bottom: 1px solid var(--border); }
.topbar-brand { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; font-weight: 600; }
.logo.sm { width: 32px; height: 32px; border-radius: 50%; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--bg-card-hover); object-fit: cover; border: 1px solid var(--border); }
.icon-btn { background: var(--bg-card); border: 1px solid var(--border); width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; transition: all 0.2s; }
.icon-btn.sm { width: 30px; height: 30px; font-size: 0.9rem; border-radius: 8px; }
.icon-btn:hover { border-color: var(--accent); background: var(--bg-card-hover); }
.content { flex: 1; overflow-y: auto; position: relative; }
.tab { display: none; height: 100%; flex-direction: column; }
.tab.active { display: flex; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 8px; }
.section-head h2 { font-size: 1.3rem; font-weight: 700; }
.btn-primary { background: var(--accent); color: #fff; padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 0.9rem; transition: all 0.2s; }
.btn-primary:hover { background: #4f46e5; transform: translateY(-1px); }
.cards { padding: 8px 16px 100px; display: flex; flex-direction: column; gap: 12px; }

/* CHAT LAYOUT */
.chat-layout { display: flex; height: 100%; }
.channel-sidebar { width: 220px; background: var(--bg-surface); border-right: 1px solid var(--border); padding: 12px 8px; overflow-y: auto; flex-shrink: 0; }
.channel-sidebar-head { display: flex; align-items: center; justify-content: space-between; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 8px 8px 4px; font-weight: 600; }
.channel-item { padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; color: var(--text-secondary); transition: all 0.15s; display: flex; align-items: center; gap: 6px; }
.channel-item:hover { background: var(--bg-card); color: var(--text-primary); }
.channel-item.active { background: var(--accent); color: #fff; }
.channel-item .hash { color: var(--text-muted); }
.channel-item.active .hash { color: rgba(255,255,255,0.6); }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { padding: 10px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.95rem; color: var(--text-secondary); background: var(--bg-surface); }
.chat-list { flex: 1; overflow-y: auto; padding: 16px 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 80%; padding: 10px 14px; border-radius: 16px; background: var(--bg-card); border: 1px solid var(--border); font-size: 0.95rem; line-height: 1.45; word-break: break-word; }
.bubble .meta { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 3px; font-weight: 500; }
.bubble.mine { align-self: flex-end; background: linear-gradient(135deg, #6366f1, #5558e3); border-color: var(--accent); }
.bubble.mine .meta { color: rgba(255,255,255,0.7); }
.bubble img { max-width: 100%; border-radius: 10px; margin-top: 6px; display: block; }
.bubble a { color: var(--accent-light); }
.bubble.mine a { color: #fff; text-decoration: underline; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--bg-surface); border-top: 1px solid var(--border); }
.chat-form input[type="text"] { flex: 1; background: var(--bg-card); border: 1px solid var(--border); border-radius: 22px; padding: 11px 16px; color: var(--text-primary); font-size: 0.95rem; outline: none; }
.chat-form input[type="text"]:focus { border-color: var(--accent); }
.attach-btn { display: flex; align-items: center; justify-content: center; width: 44px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 50%; font-size: 1.2rem; }
.send-btn { width: 44px; background: var(--accent); border-radius: 50%; font-size: 1.1rem; color: #fff; }

@media (max-width: 768px) {
  .channel-sidebar { display: none; }
  .channel-sidebar.mobile-open { display: block; position: absolute; z-index: 30; height: 100%; width: 240px; }
}

/* CARDS */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; transition: all 0.2s; cursor: pointer; }
.card:hover { border-color: var(--border-light); }
.card h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; }
.card .meta { color: var(--text-muted); font-size: 0.78rem; margin-bottom: 10px; }
.card p { color: #cbd5e1; font-size: 0.92rem; line-height: 1.5; }
.card .cover-img { width: 100%; height: 160px; object-fit: cover; border-radius: 10px; margin-bottom: 12px; }
.card .post-content { color: #cbd5e1; font-size: 0.92rem; line-height: 1.6; }
.card .post-content h2 { font-size: 1.1rem; margin: 12px 0 6px; }
.card .post-content h3 { font-size: 1rem; margin: 10px 0 4px; }
.card .post-content ul { padding-left: 20px; margin: 8px 0; }
.card .post-content li { margin-bottom: 4px; }
.card .post-content blockquote { border-left: 3px solid var(--accent); padding-left: 12px; margin: 8px 0; color: var(--text-secondary); font-style: italic; }
.card .actions { display: flex; gap: 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.card .action-btn { display: flex; align-items: center; gap: 5px; font-size: 0.85rem; color: var(--text-muted); background: none; padding: 4px 8px; border-radius: 6px; transition: all 0.15s; }
.card .action-btn:hover { color: var(--text-primary); background: var(--bg-card-hover); }
.card .action-btn.liked { color: var(--accent-light); }
.card .attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.card .attachments img { width: 80px; height: 80px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.card .attachments a { font-size: 0.8rem; color: var(--accent-light); background: var(--bg-card-hover); padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); }

/* POLLS */
.poll-opt { display: block; width: 100%; text-align: left; background: var(--bg-card-hover); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-top: 8px; position: relative; overflow: hidden; font-size: 0.92rem; transition: border-color 0.2s; }
.poll-opt .bar { position: absolute; inset: 0; background: rgba(99,102,241,0.15); width: 0; transition: width 0.4s ease; }
.poll-opt .lbl { position: relative; display: flex; justify-content: space-between; font-weight: 500; }
.poll-opt.voted { border-color: var(--accent); }
.poll-opt:hover { border-color: var(--accent); }
.poll-closed-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.7rem; font-weight: 600; background: rgba(239,68,68,0.15); color: var(--red); margin-left: 8px; }

/* MODAL */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px 20px 0 0; padding: 22px 18px; width: 100%; max-width: 600px; max-height: 92dvh; overflow-y: auto; padding-bottom: max(22px, env(safe-area-inset-bottom)); }
.modal-card h3 { margin-bottom: 14px; font-size: 1.2rem; font-weight: 600; }
.modal-card input, .modal-card textarea { width: 100%; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; color: var(--text-primary); font-size: 0.95rem; margin-bottom: 10px; outline: none; }
.modal-card input:focus, .modal-card textarea:focus { border-color: var(--accent); }
.modal-card textarea { min-height: 90px; resize: vertical; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions button { flex: 1; padding: 12px; border-radius: 10px; font-weight: 600; }
.btn-cancel { background: var(--bg-card-hover); border: 1px solid var(--border); color: var(--text-secondary); }
.opt-row { display: flex; gap: 8px; align-items: center; }
.opt-row input { flex: 1; }
.opt-row .rm { width: 38px; flex: none; background: var(--bg-card-hover); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; color: var(--text-muted); }
.add-opt { background: var(--bg-card-hover); border: 1px dashed var(--border); width: 100%; padding: 9px; border-radius: 8px; color: var(--text-muted); margin-bottom: 10px; }
.add-opt:hover { border-color: var(--accent); }

/* AI EDITOR */
.ai-section { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.ai-section label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; display: block; margin-bottom: 6px; }
.ai-btn { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 8px; transition: opacity 0.2s; }
.ai-btn:hover { opacity: 0.9; }
.ai-btn:disabled { opacity: 0.5; }
.ai-loading { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 0.85rem; padding: 8px 0; }
.ai-spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.editor-preview { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-height: 120px; max-height: 300px; overflow-y: auto; color: #cbd5e1; font-size: 0.92rem; line-height: 1.6; }
.editor-preview:empty::before { content: 'El contenido generado aparecerá aquí…'; color: var(--text-muted); }
.editor-preview:focus { border-color: var(--accent); outline: none; }
.editor-preview h2 { font-size: 1.1rem; margin: 12px 0 6px; color: var(--text-primary); }
.editor-preview h3 { font-size: 1rem; margin: 10px 0 4px; color: var(--text-primary); }
.editor-preview ul { padding-left: 20px; margin: 8px 0; }
.editor-preview li { margin-bottom: 4px; }
.editor-preview blockquote { border-left: 3px solid var(--accent); padding-left: 12px; margin: 8px 0; color: var(--text-secondary); font-style: italic; }

/* COMMENTS */
.comments-section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.comment { display: flex; gap: 10px; margin-bottom: 12px; }
.comment .c-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-card-hover); flex-shrink: 0; object-fit: cover; }
.comment .c-body { flex: 1; }
.comment .c-meta { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 2px; }
.comment .c-meta strong { color: var(--text-primary); }
.comment .c-text { font-size: 0.9rem; color: #cbd5e1; line-height: 1.4; }
.comment-form { display: flex; gap: 8px; margin-top: 12px; }
.comment-form input { flex: 1; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 20px; padding: 9px 14px; color: var(--text-primary); font-size: 0.9rem; outline: none; }
.comment-form input:focus { border-color: var(--accent); }
.comment-form button { background: var(--accent); color: #fff; border-radius: 50%; width: 36px; font-size: 0.9rem; }

/* DETAIL VIEW */
.detail-card { max-width: 700px; }
.detail-card .detail-cover { width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; margin-bottom: 16px; }
.detail-card .detail-content { color: #cbd5e1; font-size: 0.95rem; line-height: 1.7; }
.detail-card .detail-content h2 { font-size: 1.2rem; margin: 16px 0 8px; color: var(--text-primary); }
.detail-card .detail-content h3 { font-size: 1.05rem; margin: 12px 0 6px; color: var(--text-primary); }
.detail-card .detail-content ul { padding-left: 20px; margin: 8px 0; }
.detail-card .detail-content blockquote { border-left: 3px solid var(--accent); padding-left: 14px; margin: 10px 0; color: var(--text-secondary); font-style: italic; }

/* TABBAR */
.tabbar { display: flex; background: var(--bg-surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; background: none; padding: 9px 0 7px; font-size: 1.3rem; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 2px; transition: color 0.2s; }
.tabbar button span { font-size: 0.68rem; font-weight: 500; }
.tabbar button.active { color: var(--accent-light); }
.empty { color: var(--text-muted); text-align: center; padding: 40px 20px; font-size: 0.9rem; }

/* GOOGLE LOGIN */
.google-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 13px; background: #fff; color: #1a1a1a; border: none; border-radius: 10px; font-size: 0.9375rem; font-weight: 600; cursor: pointer; transition: opacity 0.2s; }
.google-btn:hover { opacity: 0.92; }
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: rgba(255,255,255,0.2); font-size: 0.8rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(255,255,255,0.1); }

/* SEARCH BAR */
.chat-header { display: flex; align-items: center; justify-content: space-between; }
.search-bar { display: flex; gap: 8px; padding: 8px 12px; background: var(--bg-surface); border-bottom: 1px solid var(--border); }
.search-bar input { flex: 1; background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px; padding: 9px 14px; color: var(--text-primary); font-size: 0.9rem; outline: none; }
.search-bar input:focus { border-color: var(--accent); }
.search-results-info { padding: 6px 14px; font-size: 0.78rem; color: var(--text-muted); background: var(--bg-surface); border-bottom: 1px solid var(--border); }

/* MESSAGE MENU */
.msg-menu { position: fixed; background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 10px; padding: 4px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.4); min-width: 140px; }
.msg-menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 12px; background: none; border: none; color: var(--text-primary); font-size: 0.88rem; border-radius: 6px; text-align: left; }
.msg-menu button:hover { background: var(--bg-card-hover); }
.msg-menu button.danger { color: var(--red); }

/* MESSAGE EDITED BADGE */
.bubble .edited { font-size: 0.68rem; color: var(--text-muted); font-style: italic; margin-top: 3px; }
.bubble.mine .edited { color: rgba(255,255,255,0.5); }
.bubble .msg-actions { display: none; position: absolute; top: -8px; right: -8px; background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 6px; padding: 2px 6px; font-size: 0.75rem; cursor: pointer; }
.bubble.mine:hover .msg-actions { display: block; }
.bubble { position: relative; }

/* DASHBOARD */
.dash-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 600px) { .dash-stats { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; transition: border-color 0.2s; }
.stat-card:hover { border-color: var(--border-light); }
.stat-card .stat-icon { font-size: 1.5rem; margin-bottom: 6px; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); }
.stat-card .stat-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.stat-card.accent { border-color: var(--accent); background: linear-gradient(135deg, rgba(99,102,241,0.08), transparent); }
.stat-card.accent .stat-value { color: var(--accent-light); }
.stat-card.warn { border-color: rgba(245,158,11,0.3); }
.stat-card.warn .stat-value { color: #f59e0b; }
.dash-section { margin-bottom: 16px; }
.dash-section h3 { font-size: 0.95rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.dash-section h3 a { font-size: 0.8rem; color: var(--accent-light); cursor: pointer; text-decoration: none; }
.dash-post-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 8px; cursor: pointer; transition: border-color 0.2s; }
.dash-post-item:hover { border-color: var(--border-light); }
.dash-post-item .dpi-title { font-weight: 600; font-size: 0.92rem; margin-bottom: 3px; }
.dash-post-item .dpi-meta { font-size: 0.76rem; color: var(--text-muted); display: flex; gap: 12px; }
.dash-poll-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 8px; cursor: pointer; transition: border-color 0.2s; }
.dash-poll-item:hover { border-color: var(--border-light); }
.dash-poll-item .dpi-q { font-weight: 600; font-size: 0.92rem; margin-bottom: 6px; }
.dash-poll-item .dpi-bar { height: 6px; background: var(--bg-card-hover); border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.dash-poll-item .dpi-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.4s; }
.dash-poll-item .dpi-opt { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 3px; }
.dash-poll-item .dpi-meta { font-size: 0.76rem; color: var(--text-muted); margin-top: 6px; }
.dash-pending-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.68rem; font-weight: 600; background: rgba(245,158,11,0.15); color: #f59e0b; margin-left: 6px; }
.dash-voted-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.68rem; font-weight: 600; background: rgba(34,197,94,0.15); color: var(--green); margin-left: 6px; }