/* ==========================================
   VARIABLES Y ESTILOS GENERALES
   ========================================== */
:root {
    --primary-color: #ffcc00;
    --primary-hover: #e6b800;
    --bg-dark: #121826;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================
   NAVBAR
   ========================================== */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0f172a;
    padding: 15px 5%;
    border-bottom: 2px solid var(--border-color);
}

.navbar .logo img {
    height: 45px;
    border-radius: 6px;
}

.navbar ul {
    display: flex;
    list-style: none;
    gap: 20px;
    align-items: center;
}

.navbar a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.navbar a:hover,
.navbar a.active {
    color: var(--primary-color);
}

.btn-logout {
    color: #ef4444 !important;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: transparent;
    color: var(--text-main);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.theme-toggle:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ==========================================
   CONTENEDOR PRINCIPAL
   ========================================== */
.noticias-container {
    max-width: 900px;
    margin: 30px auto;
    padding: 0 20px;
    flex: 1;
}

.header-seccion {
    text-align: center;
    margin-bottom: 30px;
}

.header-seccion h1 {
    font-size: 2.2rem;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.header-seccion p {
    color: var(--text-muted);
}

/* ==========================================
   PANEL ADMIN
   ========================================== */
.admin-panel {
    margin-bottom: 35px;
}

.admin-card {
    background: #1e293b;
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

.admin-card h2 {
    color: var(--primary-color);
    font-size: 1.3rem;
    margin-bottom: 15px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group > label:not(.home-feature-toggle) {
    display: block;
    margin-bottom: 6px;
    color: var(--text-main);
    font-weight: 600;
}

.admin-card input[type="text"],
.admin-card input[type="url"],
.admin-card input[type="file"],
.admin-card textarea,
.news-content-editor {
    width: 100%;
    padding: 12px;
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: #fff;
    font-size: 0.95rem;
}

.admin-card textarea,
.news-content-editor {
    resize: vertical;
}

.news-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-bottom: 0;
    border-radius: 7px 7px 0 0;
    background: #172033;
}

.news-format-button {
    display: inline-grid;
    width: 40px;
    height: 38px;
    place-items: center;
    border: 1px solid #475569;
    border-radius: 6px;
    background: #0f172a;
    color: var(--text-main);
    font-size: 1rem;
    cursor: pointer;
    touch-action: manipulation;
}

.news-format-button:hover,
.news-format-button:focus-visible {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.news-content-editor {
    min-height: 180px;
    max-height: 480px;
    overflow-y: auto;
    border-radius: 0 0 7px 7px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.news-content-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
}

.news-content-editor:focus {
    outline: 2px solid rgba(255, 204, 0, 0.45);
    outline-offset: 1px;
}

.news-content-editor ul,
.news-content-editor ol {
    padding-left: 1.6rem;
}

.news-content-editor li {
    margin: 3px 0;
}

.ayuda-imagen {
    margin: -4px 0 14px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.news-images-preview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.admin-image-choice {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    background: #0f172a;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
}

.admin-image-choice.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
    color: var(--primary-color);
}

.admin-image-choice img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 5px;
}

.admin-image-choice input {
    accent-color: var(--primary-color);
}

.admin-image-choice span {
    text-align: center;
}

.home-feature-toggle {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    margin: 0 0 16px;
    padding: 13px;
    border: 1px solid rgba(255, 204, 0, 0.35);
    border-radius: 8px;
    background: rgba(255, 204, 0, 0.06);
    cursor: pointer;
}

.home-feature-toggle input {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    margin-top: 2px;
    accent-color: var(--primary-color);
}

.home-feature-toggle span {
    display: flex;
    flex-direction: column;
    gap: 3px;
    color: var(--text-main);
}

.home-feature-toggle small {
    color: var(--text-muted);
    font-weight: 400;
}

.btn-publicar {
    background: var(--primary-color);
    color: #0f172a;
    border: none;
    padding: 12px 24px;
    font-weight: bold;
    font-size: 1rem;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    transition: background 0.3s ease;
}

.btn-publicar:hover {
    background: var(--primary-hover);
}

.status-msg {
    margin-top: 12px;
    font-weight: 600;
    text-align: center;
}

/* ==========================================
   TARJETAS DE NOTICIAS
   ========================================== */
.noticia-card {
    background: var(--card-bg);
    border-left: 5px solid var(--primary-color);
    border-radius: 10px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: transform 0.2s ease;
}

.noticia-card:hover {
    transform: translateY(-2px);
}

.noticia-card h2 {
    color: #fff;
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.noticia-card .fecha {
    display: block;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 15px;
}

.home-feature-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0 0 12px;
    padding: 5px 10px;
    border: 1px solid rgba(255, 204, 0, 0.4);
    border-radius: 999px;
    color: var(--primary-color);
    background: rgba(255, 204, 0, 0.08);
    font-size: 0.78rem;
    font-weight: 700;
}

.noticia-img {
    width: 100%;
    max-height: 420px;
    object-fit: cover;
    border-radius: 8px;
    cursor: zoom-in;
    transition: filter 0.2s ease;
}

.noticia-img:hover {
    filter: brightness(0.9);
}

.news-image-viewer[hidden] {
    display: none;
}

.news-image-viewer {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(2, 6, 23, 0.94);
    color: #f8fafc;
}

.news-image-viewer-panel {
    display: flex;
    width: min(1200px, 100%);
    height: min(900px, 100%);
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    background: #0f172a;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.news-image-viewer-toolbar {
    display: flex;
    min-height: 60px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.news-image-viewer-caption {
    min-width: 0;
    overflow: hidden;
    color: #e2e8f0;
    font-size: 0.9rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.news-image-viewer-controls {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 7px;
}

.news-image-zoom-button,
.news-image-viewer-close {
    min-width: 42px;
    min-height: 40px;
    border: 1px solid #475569;
    border-radius: 8px;
    background: #1e293b;
    color: #f8fafc;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.news-image-zoom-button[aria-pressed="true"] {
    border-color: #ffcc00;
    background: #ffcc00;
    color: #0f172a;
}

.news-image-viewer-close {
    margin-left: 4px;
    font-size: 1.15rem;
}

.news-image-zoom-button:hover,
.news-image-viewer-close:hover {
    border-color: #ffcc00;
}

.news-image-viewer-stage {
    display: flex;
    min-height: 0;
    flex: 1;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

.news-image-viewer-image-wrap {
    display: flex;
    min-width: 100%;
    min-height: 100%;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.news-image-viewer-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform: scale(var(--image-zoom, 1));
    transform-origin: center;
    transition: transform 0.18s ease;
    user-select: none;
    -webkit-user-drag: none;
}

.news-image-viewer-hint {
    padding: 0 12px 10px;
    color: #94a3b8;
    font-size: 0.8rem;
    text-align: center;
}

.noticia-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin: 15px 0;
}

.noticia-gallery:has(.noticia-img:only-child) {
    grid-template-columns: 1fr;
}

.noticia-destacada {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

.contenido-corto {
    color: #cbd5e1;
    font-size: 1rem;
}

.contenido-completo {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease;
    color: #cbd5e1;
    font-size: 1rem;
    line-height: 1.7;
}

.contenido-completo.open {
    padding-top: 10px;
}

.contenido-formateado {
    white-space: normal;
    overflow-wrap: anywhere;
}

.contenido-formateado p {
    margin: 0 0 10px;
}

.contenido-formateado ul,
.contenido-formateado ol {
    margin: 8px 0;
    padding-left: 1.6rem;
}

.contenido-formateado li + li {
    margin-top: 4px;
}

.enlace-adjunto {
    display: inline-block;
    margin-top: 12px;
    color: var(--primary-color);
    font-weight: bold;
    text-decoration: none;
}

.enlace-adjunto:hover {
    text-decoration: underline;
}

/* BOTÓN DESPLEGABLE */
.leer-toggle {
    background: rgba(255, 204, 0, 0.15);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.leer-toggle:hover {
    background: var(--primary-color);
    color: #0f172a;
}

.leer-toggle[aria-expanded="true"] {
    margin-bottom: 8px;
}

.acciones-noticia-admin {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.acciones-noticia-admin button,
.btn-cancelar-edicion {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 9px 13px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.editar-noticia-btn {
    background: #2563eb;
    color: #fff;
}

.eliminar-noticia-btn {
    background: #b91c1c;
    color: #fff;
}

.acciones-noticia-admin button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.noticia-social {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.news-metrics,
.news-social-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.news-metrics {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.news-metrics i {
    color: var(--primary-color);
}

.news-social-actions {
    margin-top: 10px;
}

.news-social-actions button,
.news-comment-form button,
.news-admin-reply-form button {
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 8px 12px;
    background: #0f172a;
    color: var(--text-main);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.news-social-actions button:hover,
.news-social-actions button.is-liked {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.news-social-actions button:disabled,
.news-comment-form button:disabled,
.news-admin-reply-form button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.news-interaction-status {
    min-height: 1.4em;
    margin: 5px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.news-comments h3 {
    margin: 8px 0 10px;
    color: var(--text-main);
    font-size: 1rem;
}

.news-comment {
    margin: 8px 0;
    padding: 11px 12px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.7);
}

.news-comment > strong,
.news-admin-reply strong {
    color: var(--primary-color);
    font-size: 0.9rem;
}

.news-comment > p,
.news-admin-reply p {
    margin-top: 3px;
    color: #cbd5e1;
    overflow-wrap: anywhere;
}

.news-admin-reply {
    margin: 10px 0 0 12px;
    padding-left: 12px;
    border-left: 2px solid var(--primary-color);
}

.news-comment-form,
.news-admin-reply-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-top: 10px;
}

.news-comment-form textarea,
.news-admin-reply-form textarea {
    width: 100%;
    min-height: 58px;
    resize: vertical;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    background: #0f172a;
    color: var(--text-main);
    font: inherit;
}

.news-comment-form button,
.news-admin-reply-form button {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.comments-loading,
.comments-empty,
.comments-error,
.noticias-vacias {
    color: var(--text-muted);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.btn-cancelar-edicion {
    width: 100%;
    margin-top: 8px;
    background: transparent;
    color: var(--text-main);
}

.loading-spinner {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 1.2rem;
}

body.light {
    --bg-dark: #f1f5f9;
    --card-bg: #ffffff;
    --text-main: #172033;
    --text-muted: #64748b;
    --border-color: #d7dee8;
    background-color: var(--bg-dark);
    color: var(--text-main);
}

body.light .navbar,
body.light footer {
    background: #ffffff;
    border-color: var(--border-color);
}

body.light .navbar a {
    color: #475569;
}

body.light .navbar a:hover,
body.light .navbar a.active {
    color: #9a7200;
}

body.light .theme-toggle {
    color: #334155;
    background: #f8fafc;
}

body.light .navbar .header-notification-btn {
    border-color: #cbd5e1;
    background: #f8fafc;
    color: #334155;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

body.light .navbar .header-notification-btn:hover,
body.light .navbar .header-notification-btn:focus-visible {
    border-color: #9a7200;
    background: #fffbeb;
    color: #8a6500;
}

body.light .navbar .header-notification-badge {
    border-color: #fff;
}

body.light .admin-card {
    background: #ffffff;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

body.light .admin-card input[type="text"],
body.light .admin-card input[type="url"],
body.light .admin-card input[type="file"],
body.light .admin-card textarea,
body.light .news-content-editor,
body.light .admin-image-choice,
body.light .news-social-actions button,
body.light .news-comment-form textarea,
body.light .news-admin-reply-form textarea {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #172033;
}

body.light .news-editor-toolbar {
    background: #e9eef5;
}

body.light .news-format-button {
    border-color: #cbd5e1;
    background: #ffffff;
    color: #334155;
}

body.light .contenido-formateado {
    color: #334155;
}

body.light .admin-card input::placeholder,
body.light .admin-card textarea::placeholder,
body.light .news-comment-form textarea::placeholder,
body.light .news-admin-reply-form textarea::placeholder {
    color: #64748b;
}

body.light .home-feature-toggle {
    background: #fffbeb;
    border-color: #e8ca68;
}

body.light .home-feature-toggle span,
body.light .noticia-card h2,
body.light .contenido-corto,
body.light .contenido-completo,
body.light .news-comment > p,
body.light .news-admin-reply p {
    color: #334155;
}

body.light .home-feature-toggle small {
    color: #64748b;
}

body.light .noticia-card {
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

body.light .home-feature-badge,
body.light .leer-toggle {
    color: #8a6500;
}

body.light .news-comment {
    background: #f1f5f9;
}

body.light .news-comment > strong,
body.light .news-admin-reply strong {
    color: #8a6500;
}

body.light .news-social-actions button:hover,
body.light .news-social-actions button.is-liked,
body.light .news-comment-form button,
body.light .news-admin-reply-form button {
    color: #8a6500;
}

body.light .enlace-adjunto {
    color: #8a6500;
}

/* FOOTER */
footer {
    text-align: center;
    padding: 20px;
    background: #0f172a;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 600px) {
    .navbar {
        flex-direction: column;
        gap: 10px;
    }
    .navbar ul {
        justify-content: center;
        flex-wrap: wrap;
        gap: 12px;
    }
    .noticia-card {
        padding: 18px;
    }
    .noticia-gallery {
        grid-template-columns: 1fr;
    }
    .news-content-editor {
        min-height: 160px;
    }
    .news-image-viewer {
        padding: 0;
    }
    .news-image-viewer-panel {
        width: 100%;
        height: 100%;
        border: 0;
        border-radius: 0;
    }
    .news-image-viewer-toolbar {
        min-height: 58px;
        gap: 6px;
        padding: 8px;
    }
    .news-image-viewer-caption {
        display: none;
    }
    .news-image-viewer-controls {
        width: 100%;
        justify-content: center;
        gap: 8px;
    }
    .news-image-zoom-button {
        min-width: 58px;
        min-height: 44px;
    }
    .news-image-viewer-close {
        width: 44px;
        min-height: 44px;
        margin-left: auto;
    }
    .news-image-viewer-image-wrap {
        padding: 8px;
    }
    .news-image-viewer-hint {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}