/* ── Reset & Variables ────────────────────────────────────────────────────── */
:root {
    --primary:        #6366f1;
    --primary-hover:  #4f46e5;
    --primary-light:  #eef2ff;
    --brand:          #6366f1;
    --bg:             #f3f4f6;
    --bg-secondary:   #f9fafb;
    --white:          #ffffff;
    --text:           #111827;
    --text-primary:   #111827;
    --text-secondary: #374151;
    --text-muted:     #6b7280;
    --border:         #e5e7eb;
    --radius:         14px;
    --shadow:         0 1px 2px rgba(17,24,39,.04), 0 6px 16px -4px rgba(17,24,39,.08);
    --shadow-md:      0 2px 4px rgba(17,24,39,.05), 0 16px 32px -8px rgba(17,24,39,.14);
}

/* ── Dark Mode CSS variable overrides ───────────────────────────────────────── */
html.dark {
    --bg:             #111827;
    --bg-secondary:   #1f2937;
    --white:          #1f2937;
    --text:           #f3f4f6;
    --text-primary:   #f3f4f6;
    --text-secondary: #d1d5db;
    --text-muted:     #9ca3af;
    --border:         #374151;
    --shadow:         0 1px 2px rgba(0,0,0,.5), 0 8px 22px -6px rgba(0,0,0,.55);
}
html.dark .card,
html.dark .post-card,
html.dark .event-card,
html.dark .lesson-card,
html.dark .form-card { background: #1f2937; border-color: #374151; }
html.dark .navbar,
html.dark .sub-nav   { background: #1f2937; border-color: #374151; }

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ── Top Navbar ──────────────────────────────────────────────────────────── */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    height: 58px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 200;
    gap: 16px;
}

.navbar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    flex-shrink: 0;
}

.navbar-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.navbar-user strong { color: var(--text); }

.btn-link {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 4px 8px;
    border-radius: 6px;
    text-decoration: none;
}
.btn-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }

/* Layout/sidebars/nav-menu legacy eliminados (shell usa grid de Tailwind). */

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ── User Profile Card ───────────────────────────────────────────────────── */
.profile-card {
    text-align: center;
    padding: 20px 16px;
}

.avatar {
    width: 52px; height: 52px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 1.3rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(99,102,241,.12), 0 2px 6px -1px rgba(17,24,39,.12);
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.avatar-sm { width: 32px; height: 32px; font-size: 0.8rem; }
.avatar-xs { width: 24px; height: 24px; font-size: 0.65rem; }

.profile-name { font-weight: 600; font-size: 0.95rem; }
.profile-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.level-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    margin-top: 6px;
    color: #fff;
}

.points-bar-wrap { margin-top: 10px; }
.points-bar-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
.points-bar { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; }
.points-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .4s; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
/* Botones: definidos en tailwind/input.css (@layer components) para estar
   disponibles en TODAS las páginas (app, auth, classroom y about). */

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }

label { font-size: 0.875rem; font-weight: 500; }

/* Campos de formulario: base definida en tailwind/input.css (@layer base)
   para estar disponible en TODAS las páginas y con foco/estados elegantes. */

.form-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #991b1b;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.form-success {
    background: #f0fdf4;
    border: 1px solid #86efac;
    color: #166534;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

/* ── Auth Pages ──────────────────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg);
}

.auth-box {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo h1 { font-size: 1.6rem; color: var(--primary); font-weight: 800; }
.auth-logo p { color: var(--text-muted); font-size: 0.875rem; margin-top: 4px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 0.875rem; color: var(--text-muted); }

/* ── Post Card ───────────────────────────────────────────────────────────── */
.post-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    transition: border-color .15s, box-shadow .2s, transform .2s;
}
.post-card:hover { border-color: #d7d9e0; box-shadow: var(--shadow-md); transform: translateY(-2px); }

.post-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.post-author-name { font-weight: 600; font-size: 0.875rem; }
.post-time { color: var(--text-muted); font-size: 0.78rem; margin-left: auto; }

.category-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.cat-general   { background: #e0f2fe; color: #0369a1; }
.cat-anuncios  { background: #fef3c7; color: #92400e; }
.cat-preguntas { background: #ede9fe; color: #6d28d9; }
.cat-logros    { background: #d1fae5; color: #065f46; }

.post-title { font-size: 1rem; font-weight: 700; margin-bottom: 6px; }
.post-title a { color: var(--text); }
.post-title a:hover { color: var(--primary); text-decoration: none; }

.post-content { color: #374151; font-size: 0.9rem; line-height: 1.65; }
.post-content-preview {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Quill-rendered HTML inside posts and comments */
.quill-content p     { margin: 0 0 0.5em; }
.quill-content p:last-child { margin-bottom: 0; }
.quill-content ul, .quill-content ol { margin: 0.4em 0 0.4em 1.4em; padding: 0; }
.quill-content li    { margin-bottom: 2px; }
.quill-content blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 10px;
    margin: 6px 0;
    color: var(--text-muted);
    font-style: italic;
}
.quill-content a     { color: var(--primary); text-decoration: underline; }
.quill-content strong { font-weight: 700; }
.quill-content em    { font-style: italic; }
.quill-content pre   { background: #f3f4f6; border-radius: 4px; padding: 8px 12px; font-size: 0.82rem; overflow-x: auto; }

/* Override Quill Snow theme border inside forms */
#quill-post-editor .ql-container,
#quill-comment-editor .ql-container { border-color: #d1d5db; border-radius: 0 0 4px 4px; }
#quill-post-editor .ql-toolbar,
#quill-comment-editor .ql-toolbar  { border-color: #d1d5db; border-radius: 4px 4px 0 0; }

/* Editores Quill en modo oscuro: los contenedores tienen background:#fff inline
   y Quill Snow trae toolbar/borde claros → cajas blancas en dark. Se oscurecen
   el fondo (con !important por el inline), bordes, texto, placeholder e iconos. */
html.dark #quill-post-editor,
html.dark #quill-edit-editor,
html.dark #quill-comment-editor,
html.dark .quill-reply-editor { background: #111827 !important; border-color: #374151 !important; }
html.dark .ql-toolbar.ql-snow { background: #1f2937; border-color: #374151 !important; }
html.dark .ql-container.ql-snow { border-color: #374151 !important; color: #e5e7eb; }
html.dark .ql-editor { color: #e5e7eb; }
html.dark .ql-editor.ql-blank::before { color: #9ca3af; }
html.dark .ql-snow .ql-stroke { stroke: #cbd5e1; }
html.dark .ql-snow .ql-fill { fill: #cbd5e1; }
html.dark .ql-snow .ql-picker-label,
html.dark .ql-snow .ql-picker { color: #cbd5e1; }
html.dark .ql-snow .ql-picker-options { background: #1f2937; border-color: #374151; }

.post-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ── Like Button ─────────────────────────────────────────────────────────── */
.like-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 20px;
    padding: 5px 12px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all .2s;
    font-family: inherit;
}
.like-btn:hover { border-color: #f87171; color: #dc2626; }
.like-btn.liked  { border-color: #f87171; background: #fef2f2; color: #dc2626; }
.like-btn svg { width: 14px; height: 14px; }

.comment-count-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.82rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 20px;
}
.comment-count-btn:hover { background: var(--bg); color: var(--text); text-decoration: none; }

/* ── Create Post Form ────────────────────────────────────────────────────── */
.create-post-card { margin-bottom: 16px; }
.create-post-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.create-post-input-fake {
    flex: 1;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.875rem;
    color: var(--text-muted);
}
.create-post-input-fake:hover { border-color: var(--primary); }

#create-post-form { display: none; margin-top: 14px; }
#create-post-form.open { display: block; }

/* ── Comments ────────────────────────────────────────────────────────────── */
.comments-section { margin-top: 20px; }
.comments-title { font-weight: 700; margin-bottom: 14px; font-size: 0.95rem; }

.comment {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}
.comment-body { flex: 1; }
.comment-bubble {
    background: var(--bg);
    border-radius: 0 10px 10px 10px;
    padding: 10px 14px;
    font-size: 0.875rem;
    line-height: 1.55;
}
.comment-author { font-weight: 600; font-size: 0.8rem; margin-bottom: 2px; }
.comment-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 5px; display: flex; gap: 10px; }
.reply-toggle { cursor: pointer; color: var(--primary); background: none; border: none; font-size: 0.72rem; font-family: inherit; }
.reply-toggle:hover { text-decoration: underline; }

.comment-replies { margin-left: 42px; margin-top: 10px; }

.reply-form { margin-top: 8px; display: none; }
.reply-form.open { display: flex; gap: 8px; }
.reply-input { flex: 1; }

.add-comment-form { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; }
.add-comment-form textarea { min-height: 60px; }

/* ── Leaderboard ─────────────────────────────────────────────────────────── */
.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}
.leaderboard-item:last-child { border-bottom: none; }
.lb-rank { width: 18px; font-weight: 700; color: var(--text-muted); flex-shrink: 0; text-align: center; }
.lb-name { flex: 1; font-weight: 500; }
.lb-pts  { color: var(--primary); font-weight: 600; }

/* ── Upcoming Events (sidebar) ───────────────────────────────────────────── */
.event-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
.event-item:last-child { border-bottom: none; }
.event-item-date { font-size: 0.72rem; color: var(--text-muted); }
.event-item-title { font-weight: 600; margin-top: 1px; }

/* ── Classroom ───────────────────────────────────────────────────────────── */
.courses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-top: 8px;
}

.course-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}

.course-card.locked { opacity: .7; }

.course-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    background: var(--primary-light);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
}

.course-title { font-weight: 700; font-size: 0.95rem; }
.course-desc  { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; flex: 1; }

.lock-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    background: #f3f4f6;
    color: #6b7280;
    width: fit-content;
}

/* ── Lesson Player ───────────────────────────────────────────────────────── */
.classroom-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 500px;
    box-shadow: var(--shadow);
}

.lesson-sidebar {
    border-right: 1px solid var(--border);
    overflow-y: auto;
    max-height: 80vh;
}

.lesson-sidebar-header {
    padding: 16px;
    font-weight: 700;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky; top: 0;
}

.module-group { border-bottom: 1px solid var(--border); }
.module-title { padding: 10px 16px; font-size: 0.8rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.lesson-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px 9px 24px;
    font-size: 0.85rem;
    color: var(--text);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background .15s;
}
.lesson-link:hover { background: var(--bg); text-decoration: none; }
.lesson-link.active { border-left-color: var(--primary); background: var(--primary-light); color: var(--primary); font-weight: 600; }

.lesson-main { padding: 24px; overflow-y: auto; }
.lesson-main h1 { font-size: 1.2rem; margin-bottom: 16px; }

.video-wrapper {
    position: relative;
    padding-top: 56.25%;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    margin-bottom: 20px;
}
.video-wrapper iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; }

.lesson-content { font-size: 0.9rem; line-height: 1.75; color: #374151; }
/* Contraste en modo oscuro para el texto enriquecido (lección, posts, comentarios) */
html.dark .lesson-content,
html.dark .post-content,
html.dark .quill-content,
html.dark .comment-body { color: #cbd5e1; }

/* ── Events ──────────────────────────────────────────────────────────────── */
.event-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    align-items: flex-start;
}

.event-date-block {
    flex-shrink: 0;
    text-align: center;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 10px;
    padding: 10px 14px;
    min-width: 58px;
}
.event-date-day   { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.event-date-month { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; }

.event-info { flex: 1; }
.event-title { font-weight: 700; margin-bottom: 4px; }
.event-desc  { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 10px; }
.event-time  { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 16px; }
.page-header h1 { font-size: 1.25rem; font-weight: 800; }
.page-header p  { font-size: 0.875rem; color: var(--text-muted); margin-top: 2px; }

/* ── Sort Bar ────────────────────────────────────────────────────────────── */
.sort-bar { display: flex; gap: 6px; margin-bottom: 14px; }
.sort-btn {
    padding: 5px 14px; border-radius: 20px; font-size: 0.8rem; font-weight: 600;
    cursor: pointer; border: 1.5px solid var(--border); background: var(--white); color: var(--text-muted);
    text-decoration: none;
}
.sort-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.sort-btn:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.sort-btn.active:hover { color: #fff; }

/* Navbar-search legacy eliminado (la busqueda vive en el header de Tailwind). */

/* ── Filter Toolbar (feed) ───────────────────────────────────────────────────── */
.filter-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
    align-items: center;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-left: auto;
}

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 20px;
    padding: 12px 0;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--white);
    text-decoration: none;
    transition: all .15s;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ── Search Results ──────────────────────────────────────────────────────────── */
.search-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin: 20px 0 10px;
}

.search-comment-card { margin-bottom: 10px; }
.search-lesson-card  { margin-bottom: 10px; }

.search-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.search-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}
.search-tab:hover { color: var(--text); text-decoration: none; }
.search-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.search-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 6px;
    min-width: 20px;
}
.search-tab.active .search-tab-badge { background: var(--primary-light); border-color: var(--primary-light); color: var(--primary); }

.search-see-all {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
    margin-left: auto;
}
.search-see-all:hover { text-decoration: underline; }

.search-section-title {
    display: flex;
    align-items: center;
}

/* ── Profile Page ────────────────────────────────────────────────────────────── */
.profile-header-card { margin-bottom: 16px; }

.profile-hero {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 20px;
}

.profile-avatar {
    width: 72px;
    height: 72px;
    font-size: 1.8rem;
    flex-shrink: 0;
}

.profile-hero-info { flex: 1; }
.profile-hero-name { font-size: 1.3rem; font-weight: 800; margin-bottom: 2px; }

.profile-points-bar-wrap { margin-top: 12px; max-width: 340px; }

.profile-stats {
    display: flex;
    gap: 0;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.stat-item {
    flex: 1;
    text-align: center;
    padding: 4px 0;
    border-right: 1px solid var(--border);
}
.stat-item:last-child { border-right: none; }

.stat-value { font-size: 1.3rem; font-weight: 800; color: var(--primary); line-height: 1.2; }
.stat-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* ── Post author link ────────────────────────────────────────────────────────── */
.post-author-link { color: var(--text); text-decoration: none; }
.post-author-link:hover { color: var(--primary); text-decoration: none; }

.lb-name { color: var(--text); text-decoration: none; }
.lb-name:hover { color: var(--primary); text-decoration: underline; }

/* ── Admin Panel ─────────────────────────────────────────────────────────── */
.admin-bar {
    display: flex;
    gap: 4px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.admin-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 7px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    transition: background .15s, color .15s;
}
.admin-tab:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.admin-tab.active { background: var(--primary-light); color: var(--primary); }
/* En dark, --primary-light es claro → caja brillante. Se usa un realce translúcido. */
html.dark .admin-tab.active { background: rgba(99, 102, 241, 0.20); color: #a5b4fc; }

/* Fondos claros hardcodeados inline (p.ej. admin/email_templates: card morado y
   chips <code>) → cajas brillantes en dark. Se anulan por selector de atributo. */
html.dark [style*="background:#faf5ff"] { background: #2e1065 !important; border-color: #5b21b6 !important; }
html.dark [style*="background:#eef2ff"] { background: rgba(99, 102, 241, 0.18) !important; color: #c7d2fe !important; }
html.dark [style*="background:#f3f4f6"] { background: #374151 !important; color: #e5e7eb !important; }
/* Rojo de peligro inline (#dc2626 red-600) tiene poco contraste en dark; se aclara
   a red-400, igual que el patrón dark:text-red-400 ya usado en clases Tailwind. */
html.dark [style*="color:#dc2626"] { color: #f87171 !important; }
/* Grises/rojos claros de la paleta usados inline (gray-50, gray-700 texto, red-50). */
html.dark [style*="background:#f9fafb"] { background: #1f2937 !important; border-color: #374151 !important; }
html.dark [style*="color:#374151"] { color: #d1d5db !important; }
html.dark [style*="background:#fef2f2"] { background: rgba(220, 38, 38, 0.15) !important; border-color: #7f1d1d !important; }
/* Iconos/badges de clase con fondos claros (classroom). */
html.dark .course-icon { background: rgba(99, 102, 241, 0.18); }
html.dark .lock-badge { background: #374151; color: #d1d5db; }
/* Chip sky inline (admin/lessons "Embed"). */
html.dark [style*="background:#e0f2fe"] { background: rgba(2, 132, 199, 0.20) !important; color: #7dd3fc !important; }
/* Cajas de aviso amarillas (Tailwind bg-yellow-50 sin variante dark en el build). */
html.dark .bg-yellow-50 { background: rgba(234, 179, 8, 0.12) !important; }
html.dark .border-yellow-200 { border-color: rgba(234, 179, 8, 0.35) !important; }
html.dark .text-yellow-700 { color: #fde047 !important; }

.admin-table-wrap { overflow-x: auto; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.admin-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-bottom: 1.5px solid var(--border);
    background: var(--bg);
}
.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg); }

/* ── Course Progress Bar ─────────────────────────────────────────────────── */
.course-progress { margin-top: 8px; }
.course-progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 4px;
}
.course-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width .4s;
}
.course-progress-label { font-size: 0.72rem; color: var(--text-muted); }

/* ── Event Attendees ─────────────────────────────────────────────────────── */
.event-attendees {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.event-attendee-count { font-size: 0.78rem; color: var(--text-muted); margin-left: 4px; }
.rsvp-group { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ── Notification Bell ───────────────────────────────────────────────────── */
.notif-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s;
    flex-shrink: 0;
}
.notif-bell:hover { background: var(--bg); }

.notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #dc2626;
    color: #fff;
    border-radius: 20px;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 4px;
    min-width: 16px;
    text-align: center;
    line-height: 1.4;
    pointer-events: none;
}

.notif-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 500;
    overflow: hidden;
}
.notif-dropdown.open { display: block; }

.notif-header {
    padding: 12px 16px;
    font-weight: 700;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.notif-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

#notif-list { max-height: 340px; overflow-y: auto; }

.notif-item {
    border-bottom: 1px solid var(--border);
    transition: background .15s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg); }
.notif-unread { background: #faf5ff; }
.notif-unread:hover { background: #f3e8ff; }

.notif-item-inner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
}

/* ── Conversation List ───────────────────────────────────────────────────── */
.conv-row { color: var(--text); transition: background .15s; }
.conv-row:hover { background: var(--bg); text-decoration: none; }
.conv-unread { background: #faf5ff; }
.conv-unread:hover { background: #f3e8ff; }

/* ── Chat Bubbles ────────────────────────────────────────────────────────── */
.chat-msg { display: flex; flex-direction: column; max-width: 72%; }
.chat-msg-mine { align-self: flex-end; align-items: flex-end; }
.chat-msg-theirs { align-self: flex-start; align-items: flex-start; }

.chat-msg-name { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 3px; }

.chat-bubble {
    padding: 9px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}
.chat-msg-mine   .chat-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg-theirs .chat-bubble { background: var(--bg); color: var(--text); border-bottom-left-radius: 4px; border: 1px solid var(--border); }

.chat-msg-time { font-size: 0.68rem; color: var(--text-muted); margin-top: 3px; }

/* Responsive legacy eliminado: la capa movil vive en los @media 767/768 mas abajo. */

/* -- Phase 4: Pin, video embed, mentions ------------------------------------ */
.post-pinned { border-left: 3px solid var(--primary) !important; }
.video-embed-wrap { position:relative; padding-bottom:56.25%; height:0; overflow:hidden; border-radius:8px; margin:10px 0; }
.video-embed-wrap iframe { position:absolute; top:0; left:0; width:100%; height:100%; border:none; }
.mention-link { color: var(--primary); font-weight:600; text-decoration:none; }
.mention-link:hover { text-decoration:underline; }

/* ── Fase 0: Toasts ────────────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 40px));
}
.toast {
    background: #1f2937;
    color: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.875rem;
    line-height: 1.35;
    box-shadow: 0 6px 24px rgba(0,0,0,0.18);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity .25s ease, transform .25s ease;
    border-left: 4px solid #6b7280;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: #16a34a; }
.toast-error   { border-left-color: #dc2626; }
.toast-info    { border-left-color: var(--primary); }

/* ── Fase 1: Imágenes en posts + estado editado ───────────────────────────── */
.post-image {
    max-width: 100%;
    border-radius: 8px;
    margin: 10px 0;
    display: block;
    border: 1px solid var(--border);
}
.post-edited { font-size: 0.7rem; color: var(--text-muted); font-style: italic; margin-left: 6px; }

/* Botones de acción del autor (editar/eliminar) */
.owner-actions { display: inline-flex; gap: 4px; }
.owner-actions form { display: inline; margin: 0; }

/* ── Fase 2: Estados vacíos ───────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state-title { font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-state-text { font-size: 0.9rem; margin-bottom: 16px; }

/* ── Fase 3: Guardar y reacciones ─────────────────────────────────────────── */
.save-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all .15s;
}
.save-btn:hover { border-color: var(--primary); color: var(--primary); }
.save-btn.saved { background: var(--primary-light); border-color: var(--primary); color: var(--primary); font-weight: 600; }

.reaction-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.reaction-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all .15s;
}
.reaction-btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.reaction-btn.active { background: var(--primary-light); border-color: var(--primary); }
.reaction-btn .re-count { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }
.reaction-btn.active .re-count { color: var(--primary); }

/* ── Fase 4: Encuestas ────────────────────────────────────────────────────── */
.poll { margin: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.poll-question { font-weight: 600; margin-bottom: 4px; }
.poll-option {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    text-align: left;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    cursor: pointer;
    overflow: hidden;
    font-size: 0.9rem;
    transition: border-color .15s;
}
.poll-option:hover { border-color: var(--primary); }
.poll-option.voted-mine { border-color: var(--primary); font-weight: 600; }
.poll-bar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    background: var(--primary-light);
    z-index: 0;
    transition: width .4s ease;
}
.poll-opt-text, .poll-opt-pct { position: relative; z-index: 1; }
.poll-opt-pct { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
.poll-total { font-size: 0.78rem; color: var(--text-muted); }

/* ── Fase 5: Tarjeta de bienvenida (onboarding) ───────────────────────────── */
.welcome-card { border-left: 4px solid var(--primary); background: linear-gradient(135deg, var(--primary-light), var(--white)); }
html.dark .welcome-card { background: #1f2937; }

/* =====================================================================
   CAPA MOVIL (plan ROADMAP_MOBILE)
   Reglas base seguras + bloques @media para usabilidad y estructura.
   ===================================================================== */

/* Base anti-desborde (segura en todos los tamanos) */
img, svg, video, iframe { max-width: 100%; }
.post-content, .comment-body, .comment-bubble, .quill-content,
.post-title, .chat-bubble, .page-header p { overflow-wrap: anywhere; }
/* code/pre con tokens largos sin espacios (rutas API, claves, secretos) rompen
   para no forzar el ancho del contenedor por min-content en móvil */
code, pre, .font-mono { overflow-wrap: anywhere; }
main, .card, .post-card, .post-meta, .post-body, .comment, .comment-body { min-width: 0; }

/* Drawer del community-switcher (oculto en escritorio) */
#cs-hamburger { display: none; }
#cs-backdrop  { display: none; }

@media (max-width: 767px) {
    body { padding-left: 0 !important; }            /* anula pl-[68px] de Tailwind */
    #community-switcher {
        transform: translateX(-100%);
        transition: transform .22s ease;
        z-index: 60;                 /* por encima de la topbar (z-50) al abrirse */
    }
    #community-switcher.is-open {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0,0,0,.35);
    }
    #cs-backdrop {
        position: fixed; inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 58;                 /* tapa el contenido, bajo el drawer */
    }
    #cs-backdrop.is-open { display: block; }
    #cs-hamburger {
        display: inline-flex;
        align-items: center; justify-content: center;
        width: 40px; height: 40px;
        border: none; background: transparent; cursor: pointer;
        color: #4b5563; border-radius: 8px;
    }
    #cs-hamburger:hover { background: #f3f4f6; }
    #cs-close { display: inline-flex !important; }   /* botón cerrar dentro del drawer */
}

/* Reglas moviles generales */
@media (max-width: 768px) {
    .page-header h1 { font-size: 1.4rem; }
    .page-header p  { font-size: 0.9rem; }

    .card, .post-card { padding: 14px; }
    .post-meta   { flex-wrap: wrap; gap: 4px 8px; }
    .post-actions, .owner-actions, .reaction-bar { flex-wrap: wrap; gap: 6px; }
    .filter-toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
    .filter-bar { margin-left: 0; flex-wrap: wrap; }
    .sort-bar   { flex-wrap: wrap; }

    /* Formularios sin zoom de iOS (>=16px). !important para ganar a estilos inline. */
    input, select, textarea { font-size: 16px !important; }
    .form-group input, .form-group select, .form-group textarea,
    .form-card input, .form-card select, .form-card textarea { width: 100%; }

    .ql-toolbar.ql-snow { flex-wrap: wrap; }
    .ql-toolbar .ql-formats { margin-right: 8px; }

    /* Tooltip de enlace de Quill: Quill lo posiciona al cursor con white-space:nowrap
       y puede salirse del viewport en móvil. Se fija a la izquierda y se acota.
       !important porque quill.snow.css (.ql-snow .ql-tooltip) tiene más especificidad
       y carga después de style.css. */
    .ql-snow .ql-tooltip { max-width: calc(100vw - 40px) !important; white-space: normal !important; z-index: 60; }
    .ql-snow .ql-tooltip:not(.ql-hidden) { left: 8px !important; }
    .ql-snow .ql-tooltip input[type=text] { max-width: 55vw; }

    .classroom-layout { grid-template-columns: 1fr; }
    .lesson-sidebar {
        max-height: 240px; overflow-y: auto;
        border-right: none; border-bottom: 1px solid var(--border);
    }

    aside.sticky { position: static !important; top: auto !important; }

    .search-tabs { flex-wrap: wrap; }

    /* El dropdown de notificaciones se anclaba con right:0 a la campana (que no
       está en el borde), y sus 320px se salían por la izquierda (título recortado).
       En móvil se fija al viewport, pegado al borde derecho y bajo el header. */
    #notif-dropdown {
        position: fixed;
        top: 62px;
        right: 8px;
        left: auto;
        margin-top: 0;
        width: min(340px, calc(100vw - 16px));
        max-height: calc(100dvh - 76px);
        overflow-y: auto;
    }

    /* Dropdowns <details> con form absoluto (Editar evento/curso/módulo/lección):
       con right-0 y el summary apilado a la izquierda en móvil, se salían de
       pantalla. Se anclan a la izquierda y se acotan al viewport. Cubre w-64/72/80. */
    details > form.absolute {
        right: auto !important;
        left: 0 !important;
        max-width: calc(100vw - 40px) !important;
    }

    #toast-container { left: 12px; right: 12px; bottom: 12px; max-width: none; }

    .profile-hero { flex-direction: column; align-items: center; text-align: center; }
    .profile-points-bar-wrap { max-width: 100%; }

    /* TABLAS: scroll horizontal contenido (no desborda la pagina) */
    table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
}

/* Mensajeria: el chat usa el alto real del movil (dvh, no vh) */
@media (max-width: 768px) {
    #chat-shell { height: calc(100dvh - 116px); }
    #chat-input { font-size: 16px !important; }
}

/* Pulido: foco visible y areas seguras (notch) */
@media (max-width: 768px) {
    a:focus-visible, button:focus-visible, input:focus-visible,
    select:focus-visible, textarea:focus-visible {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }
    #community-switcher { padding-top: max(12px, env(safe-area-inset-top)); }
}

/* ===== Fase 1 usabilidad: bottom nav movil, foco global, areas tactiles ===== */

/* Foco visible en TODOS los tamanos (accesibilidad de teclado tambien en escritorio) */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Barra inferior tipo app (solo movil, dentro de una comunidad) */
.bottom-nav { display: none; }
@media (max-width: 767px) {
    .bottom-nav {
        display: flex;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
        background: rgba(255,255,255,.82);
        -webkit-backdrop-filter: saturate(180%) blur(14px);
        backdrop-filter: saturate(180%) blur(14px);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -4px 16px -4px rgba(17,24,39,.12);
    }
    html.dark .bottom-nav { background: rgba(31,41,55,.85); border-color: #374151; }
    .bottom-nav a {
        flex: 1; display: flex; flex-direction: column;
        align-items: center; justify-content: center; gap: 3px;
        min-height: 56px; padding: 6px 0;
        font-size: 0.66rem; color: var(--text-muted); text-decoration: none;
        transition: color .15s ease;
    }
    .bottom-nav a.active { color: var(--primary); font-weight: 600; }
    .bottom-nav .bn-ico {
        font-size: 1.2rem; line-height: 1;
        padding: 4px 14px; border-radius: 999px;
        transition: background-color .18s ease, transform .18s ease;
    }
    .bottom-nav a.active .bn-ico {
        background: var(--primary-light); transform: translateY(-1px);
    }
    html.dark .bottom-nav a.active .bn-ico { background: rgba(99,102,241,.22); }
    body.has-bottom-nav { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }

    /* Areas tactiles de los iconos del header superior */
    #theme-toggle, #notif-toggle, #cs-hamburger, #lang-toggle {
        min-width: 44px; min-height: 44px;
        display: inline-flex; align-items: center; justify-content: center;
    }
}

/* ===== Fase 2: drawer del temario en la leccion (movil) ===== */
.lesson-temario-btn { display: none; }
.lesson-drawer-backdrop { display: none; }
@media (max-width: 767px) {
    .lesson-temario-btn {
        display: inline-flex; align-items: center; gap: 6px;
        margin-bottom: 12px; padding: 10px 14px; min-height: 44px;
        background: var(--primary); color: #fff; border: none; border-radius: 10px;
        font-weight: 600; font-size: 0.9rem; cursor: pointer;
    }
    .classroom-layout { display: block; }            /* anula el grid en movil */
    #lesson-sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
        width: min(82vw, 320px); height: 100dvh; max-height: none;
        background: #ffffff; overflow-y: auto;
        transform: translateX(-100%); transition: transform .22s ease;
        border-right: 1px solid var(--border); box-shadow: 0 0 40px rgba(0,0,0,.35);
        padding-top: max(12px, env(safe-area-inset-top));
    }
    html.dark #lesson-sidebar { background: #1f2937; }
    #lesson-sidebar.is-open { transform: translateX(0); }
    .lesson-drawer-backdrop.is-open {
        display: block; position: fixed; inset: 0; z-index: 59; background: rgba(0,0,0,.45);
    }
}

/* ===== Fase 2: editor Quill mas comodo en movil ===== */
@media (max-width: 767px) {
    .ql-toolbar.ql-snow { padding: 4px; }
    .ql-toolbar.ql-snow button { width: 32px; height: 32px; }
    .ql-toolbar .ql-formats { margin-right: 6px !important; }
    .ql-container.ql-snow { font-size: 16px; }
}

/* ===== Fase 3: tablas como tarjetas en movil (set core) + pista de scroll ===== */
@media (max-width: 767px) {
    table.cards-mobile { display: block; width: 100%; white-space: normal; overflow: visible; }
    table.cards-mobile thead { display: none; }
    table.cards-mobile tbody { display: block; }
    table.cards-mobile tr {
        display: block; border: 1px solid var(--border); border-radius: 12px;
        padding: 8px 12px; margin-bottom: 10px; background: #ffffff;
    }
    html.dark table.cards-mobile tr { background: #1f2937; }
    table.cards-mobile td {
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        padding: 6px 0 !important; border: none !important; text-align: right; width: auto;
    }
    table.cards-mobile td::before {
        content: attr(data-label); font-weight: 600; color: var(--text-muted);
        text-align: left; flex: 0 0 38%; white-space: nowrap;
    }
    table.cards-mobile td:not([data-label]) { justify-content: flex-start; }

    /* Pista de scroll en tablas anchas NO convertidas */
    .admin-table-wrap { position: relative; }
    .admin-table-wrap::after {
        content: "\2192 desliza para ver mas";
        display: block; font-size: 0.7rem; color: var(--text-muted);
        padding: 4px 2px 0; text-align: right;
    }
    .admin-table-wrap:has(table.cards-mobile)::after { display: none; }
}

/* ===== Fase 4: accesibilidad y pulido ===== */
/* Legibilidad del texto blanco de los badges sobre colores claros */
.level-badge { text-shadow: 0 1px 1.5px rgba(0,0,0,.4); }
/* Estado deshabilitado/cargando coherente en todos los botones */
.btn:disabled, .btn[disabled], button:disabled, button[disabled] {
    opacity: .6; cursor: not-allowed; pointer-events: none;
}
[aria-busy="true"] { cursor: progress; opacity: .8; }


/* FAB de instalar PWA: no tapar la bottom-nav en móvil */
.pwa-install-fab { bottom: 16px; }
@media (max-width: 767px) {
    body.has-bottom-nav .pwa-install-fab { bottom: calc(70px + env(safe-area-inset-bottom)); }
}

/* ===== Fase 7: red de seguridad para grids inline (paneles admin) =====
   Muchas vistas admin usan style="display:grid;grid-template-columns:..." con
   columnas fijas que no colapsan y desbordan a <768px. Al ser estilos inline,
   solo se pueden anular con !important. Se apilan a una columna en móvil:
   formularios (label+input alineados) y KPIs quedan legibles y sin scroll horiz. */
@media (max-width: 767px) {
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
}

/* ===== Fase 7: modales/overlays con scroll vertical seguro en móvil =====
   Backdrops fijos centrados (fixed inset-0 flex items-center) recortan
   formularios altos en pantallas cortas. Se permite scroll y se alinea arriba. */
@media (max-width: 767px) {
    .fixed.inset-0.flex.items-center { align-items: flex-start !important; overflow-y: auto; }
    .fixed.inset-0.flex.items-center > * { margin-top: 1rem; margin-bottom: 1rem; max-height: calc(100dvh - 2rem); overflow-y: auto; }
}

/* ===== Fase 7: cabeceras flex (.page-header con display:flex inline) =====
   p.ej. admin/analytics: h1 + selector de período en una fila que no envuelve
   fuerza ~495px de ancho. flex-wrap no está inline, así que CSS puede activarlo
   sin !important. Envuelve la cabecera y sus filas de controles en móvil. */
@media (max-width: 767px) {
    .page-header { flex-wrap: wrap; gap: 8px 12px; }
    .page-header > div { flex-wrap: wrap; }
}

/* ===== Fase 7: inputs de archivo nativos no fuerzan ancho en móvil =====
   <input type="file"> tiene un min-content grande ("Seleccionar archivo / Ningún
   archivo…") que empuja la celda de grid/flex por encima de 360px. min-width:0 +
   max-width:100% permite que la tarjeta contenedora se encoja al viewport. */
@media (max-width: 767px) {
    input[type="file"] { max-width: 100%; min-width: 0; }
}

/* ===== Fase 7: pantallas muy pequeñas (<360px, p.ej. iPhone SE 2016) =====
   El shell global (header superior + wrapper de contenido) deja poco ancho útil
   a 320px y provoca shrink-to-fit. Solo por debajo de 360px (no afecta al baseline
   de 360) se compacta el padding/gap del header y del contenedor para recuperar
   espacio. Reclama ~24px: 4 de 5 vistas densas pasan a caber en 320px. */
@media (max-width: 359.98px) {
    .max-w-7xl.my-6 { padding-left: 8px !important; padding-right: 8px !important; }
    header.max-w-7xl { padding-left: 8px !important; padding-right: 8px !important; column-gap: 8px !important; }
    header.max-w-7xl a.text-xl { max-width: 34vw !important; }
    header.max-w-7xl .border-l.pl-4 { padding-left: 8px !important; }
}

/* ===== Fase 7: meta de comentarios envuelve como filas en móvil =====
   .comment-meta es flex sin wrap; con 6 acciones (hora, editado, like, Responder,
   Editar, Eliminar) en una respuesta anidada estrecha, cada ítem se apretaba y
   partía sus palabras a mitad ("Respo/nder"). Se envuelve por filas y cada acción
   se mantiene entera. */
@media (max-width: 767px) {
    .comment-meta { flex-wrap: wrap; gap: 6px 12px; }
    .comment-meta > * { white-space: nowrap; }
}

/* ===== Fase 7: objetivos táctiles cómodos en móvil (WCAG 2.5.5, ≥44px) =====
   Botones y filtros quedaban en 28–32px de alto. En móvil se garantiza una zona
   táctil cómoda sin cambiar el aspecto (padding/anchura intactos, solo min-height).
   Se excluyen los botones de la toolbar de Quill (ya dimensionados a 32px aparte). */
@media (max-width: 767px) {
    /* .btn-sm reduce el min-height de .btn a ~32px; en móvil se restaura a 44px.
       !important porque tailwind.build.css carga después de style.css. .btn ya es
       inline-flex centrado, así que solo hace falta el min-height. */
    .btn { min-height: 44px !important; }
    .sort-btn { min-height: 42px; }
    /* Acciones compactas de tarjeta (Editar/Borrar/Gestionar) y tabs de panel */
    .admin-tab, .filter-bar a, .filter-bar button { min-height: 40px; }
    /* Enlaces de pie: zona táctil mayor sin separar en exceso la lista */
    footer a { display: inline-block; padding-top: 5px; padding-bottom: 5px; }
    /* Enlaces "ver más" de las tarjetas del sidebar (leaderboard / eventos) */
    aside a.block { padding-top: 7px; padding-bottom: 7px; }
}

/* ===== Fase 7: botones de texto largo envuelven en móvil =====
   Botones como "Eliminar esta comunidad permanentemente" (.btn es inline-flex
   con white-space:nowrap) fuerzan el ancho del contenedor por min-content.
   !important porque tailwind.build.css se carga después de style.css y ganaría
   con igual especificidad. En móvil se permite envolver el texto. */
@media (max-width: 767px) {
    .btn { white-space: normal !important; }
}

/* ===== Fase 8: respeto a prefers-reduced-motion (accesibilidad) =====
   Usuarios con sensibilidad vestibular activan "reducir movimiento" en su SO.
   Se neutralizan animaciones y transiciones (los drawers/modales abren al
   instante en vez de deslizar; la funcionalidad se mantiene intacta). */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== Fase 8: altura de viewport dinámica (dvh) para layouts a pantalla completa =====
   Los bodies con min-h-screen (100vh) incluyen la barra de URL del móvil, lo que
   descentra ligeramente el contenido centrado (páginas auth). body.min-h-screen
   (especificidad 0,1,1) gana a la clase .min-h-screen de Tailwind. @supports da
   fallback a 100vh donde dvh no exista. */
@supports (min-height: 100dvh) {
    body.min-h-screen { min-height: 100dvh; }
}

/* ── Nav de sección de la comunidad: hamburguesa SOLO en móvil ──────────────────
   El CSS de Tailwind está purgado y no siempre incluye md:hidden/md:flex para
   clases nuevas, así que forzamos el comportamiento responsive por ID. */
@media (min-width: 768px) {
    #community-nav { display: flex !important; }
    #community-nav-toggle { display: none !important; }
}
@media (max-width: 767.98px) {
    #community-nav:not(.hidden) { display: flex; }
}
