/* ---------------------------------------------------------
   Visibilidad por rol. El <body> lleva data-role="secretaria|comunicacion"
   (lo setea app.js). Cada elemento marcado con .only-<rol> aparece sólo para
   ese rol. v1: separación de UI por frontend.
   --------------------------------------------------------- */
body[data-role="secretaria"] .only-comunicacion { display: none !important; }
body[data-role="comunicacion"] .only-secretaria { display: none !important; }

:root {
    /* Colors */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #10b981;
    --accent: #f59e0b;
    --bg-main: #f8fafc;
    --bg-sidebar: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --surface: #ffffff;
    --danger: #ef4444;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* Spacing */
    --header-height: 70px;
    --max-content-width: 1200px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    overflow: hidden; /* App container handles scroll */
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Login Overlay Styles */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.login-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: 1.25rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

/* Top Bar & Navigation */
.top-bar {
    height: var(--header-height);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    flex-shrink: 0;
    z-index: 30;
}

.top-bar-left, .top-bar-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--primary);
    padding-right: 1.25rem;
    border-right: 1px solid var(--border);
}

.top-nav {
    display: flex;
    gap: 0.25rem;
}

.btn-hub {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: white;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    margin-right: 0.75rem;
}
.btn-hub:hover { background: #f1f5f9; color: var(--text); }
.btn-hub i { width: 16px; height: 16px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-item:hover {
    background-color: #f1f5f9;
    color: var(--text-main);
}

.nav-item.active {
    background-color: #eef2ff;
    color: var(--primary);
}

.sidebar-footer {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background-color 0.2s;
    font-size: 0.9rem;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.view-container {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
    width: 100%;
    display: flex;
    justify-content: center;
}

.content-wrapper {
    width: 100%;
    max-width: var(--max-content-width);
}

.top-bar h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
    width: 18px;
}

.search-box input {
    padding: 0.5rem 1rem 0.5rem 2.25rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    width: 240px;
    font-size: 0.85rem;
}

.view-container {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* Grouped List Styles */
.list-group {
    margin-bottom: 3rem;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-left: 0.5rem;
}

.group-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    white-space: nowrap;
}

.group-line {
    height: 1px;
    background-color: var(--border);
    flex-grow: 1;
}

.tr-done {
    opacity: 0.6;
}

.tr-done td:not(:last-child) {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* List View */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table th {
    text-align: left;
    padding: 1rem;
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    font-size: 0.85rem;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.data-table tr:hover {
    background: #f1f5f9;
    cursor: pointer;
}

/* Check Button Custom Styles */
.btn-check-done {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--border);
    transition: color 0.2s;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-check-done:hover {
    color: var(--text-muted);
}
.btn-check-done.is-done {
    color: var(--secondary);
}
.btn-check-done i {
    width: 24px;
    height: 24px;
}

/* Modal/Sheet */
.sheet-overlay {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    display: flex;
    justify-content: flex-end;
    z-index: 100;
    transition: opacity 0.3s;
}

.sheet-overlay.hidden {
    display: none;
}

.sheet-content {
    width: 500px;
    background: white;
    height: 100%;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* Form Elements */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-group input, 
.form-group select, 
.form-group textarea {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus, 
.form-group select:focus, 
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.badge-user {
    background: #f1f5f9;
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* Conectados Newsletter UI */
.conectados-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    width: 100%;
}

.conectados-item {
    background: white;
    padding: 0.85rem 1.25rem 1.25rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    transition: box-shadow 0.2s, background-color 0.2s;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.conectados-item:hover {
    box-shadow: var(--shadow-md);
    background-color: #fdfdfd;
}

.conectados-item .drag-handle {
    position: absolute;
    left: -1rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    cursor: grab;
    color: var(--text-muted);
}

.conectados-item:hover .drag-handle {
    opacity: 0.5;
}

/* Save status toast (Guardando… / Guardado / Error) */
.save-status {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
    z-index: 1000;
    color: var(--text-muted);
}
.save-status.visible {
    opacity: 1;
    transform: translateY(0);
}
.save-status > span { display: none; }
.save-status[data-status="saving"] .save-saving { display: inline; color: var(--text-muted); }
.save-status[data-status="saved"]  .save-saved  { display: inline; color: var(--secondary); }
.save-status[data-status="error"]  .save-error  { display: inline; color: var(--danger); }

/* Banner discreto de efemérides debajo del group-header */
.efemerides-banner {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 0.5rem 0.85rem;
    margin-bottom: 0.85rem;
    background: #f8fafc;
    border-radius: 0.5rem;
    border-left: 3px solid var(--primary);
    line-height: 1.5;
}
.efemerides-banner strong {
    color: var(--text-main);
    font-weight: 600;
}

/* Modal de gestión de efemérides */
.ef-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.ef-modal-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
}
.ef-modal-toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.85rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    flex-shrink: 0;
}
.ef-modal-toolbar select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    font-size: 0.85rem;
    background: white;
}
.ef-modal-toolbar .ef-spacer { flex: 1; }
.ef-modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.75rem;
}
.ef-row {
    display: grid;
    grid-template-columns: 50px 110px 1fr auto;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.ef-row:hover { background: #f1f5f9; }
.ef-row input,
.ef-row select {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 0.35rem;
    font-size: 0.85rem;
    background: transparent;
    font-family: inherit;
}
.ef-row input:focus,
.ef-row select:focus {
    background: white;
    border-color: var(--border);
    outline: none;
}
.ef-row .ef-day {
    font-weight: 600;
    color: var(--text-main);
    text-align: center;
}
.ef-row .ef-actions {
    display: inline-flex;
    gap: 0.5rem;
}
.ef-row .ef-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
}
.ef-row .ef-actions button:hover { color: var(--danger); }
.ef-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Header de la vista Conectados (desktop) */
.conectados-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.conectados-header-actions {
    display: flex;
    gap: 0.5rem;
}

/* Mobile collapsed row (oculto en desktop) */
.conectados-mobile-row { display: none; }

/* Bottom tab bar mobile (oculto en desktop) */
.mobile-bottom-tabs { display: none; }

/* "Nueva Actividad" sólo aplica en la vista Agenda (list).
   Se oculta en Conectados y Santi tanto en desktop como en mobile. */
body[data-view="conectados"] #btn-new-activity,
body[data-view="santi"] #btn-new-activity {
    display: none;
}

.conectados-action-buttons {
    display: flex;
    justify-content: flex-end;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    gap: 0.5rem;
    z-index: 10;
}

.conectados-item .btn-ia-suggest {
    position: absolute;
    top: 1rem;
    right: 1rem;
    opacity: 0.3;
}

.conectados-item:hover .btn-ia-suggest {
    opacity: 1;
}

.input-conectados-title {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-main);
    border: none !important;
    background: transparent;
    width: 100%;
    padding: 0;
    padding-right: 2rem; /* space for IA button */
    font-family: inherit;
    resize: none;
    overflow: hidden;
    min-height: 1.5rem;
}

.input-conectados-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #374151;
    border: none !important;
    background: transparent;
    width: 100%;
    resize: none;
    overflow-y: auto;
    padding: 0;
    padding-right: 0.5rem;
    font-family: inherit;
    min-height: 5rem;
    max-height: 200px;
}

/* Custom scrollbar for textareas */
.input-conectados-text::-webkit-scrollbar {
    width: 4px;
}
.input-conectados-text::-webkit-scrollbar-track {
    background: transparent;
}
.input-conectados-text::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}
.input-conectados-text::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.spin {
    animation: spin 1s linear infinite;
}

.view-container > * {
    animation: fadeIn 0.4s ease-out;
}

/* Responsive (Mobile Version) */
@media (max-width: 768px) {
    /* 1. Ocultar vistas innecesarias y el buscador */
    .top-nav,
    .search-box {
        display: none !important;
    }
    
    /* 2. Top Bar simplificada */
    .top-bar {
        padding: 0 1rem;
        gap: 0.5rem;
    }
    .logo {
        padding-right: 0.5rem;
        border-right: none;
    }
    .logo span {
        display: none; /* Hide 'Comu BCR' text, keep icon */
    }
    /* Botón "Nueva Actividad" solo con el "+" en mobile (el id es el selector
       correcto; antes se usaba .btn-new-activity como clase y no aplicaba, por
       eso el texto se veía cortado). */
    #btn-new-activity span {
        display: none;
    }
    #btn-new-activity {
        padding: 0.6rem;
    }
    /* Archivados se oculta en mobile para descongestionar la barra (queda en desktop). */
    #btn-archived {
        display: none !important;
    }
    .view-container {
        padding: 1rem;
    }

    /* 3. Transformar la Tabla a Tarjetas (Cards) */
    .data-table thead {
        display: none; /* Ocultar cabeceras */
    }
    
    .data-table, 
    .data-table tbody, 
    .data-table tr, 
    .data-table td {
        display: block;
        width: 100%;
    }
    
    .data-table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border);
        border-radius: 0.75rem;
        padding: 1rem;
        position: relative;
        background: white;
        box-shadow: var(--shadow-sm);
    }
    
    .data-table td {
        padding: 0.25rem 0;
        border-bottom: none;
    }

    /* Ajustar celdas para el diseño de tarjeta */
    /* Celda 1 (Fecha) y Celda 2 (Hora) */
    .data-table td:nth-child(1),
    .data-table td:nth-child(2) {
        display: inline-block;
        font-size: 0.8rem;
        color: var(--text-muted);
        margin-right: 0.5rem;
    }
    
    /* Celda 3 (Actividad) */
    .data-table td:nth-child(3) {
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
    }
    
    /* Celda 4 (Responsable) */
    .data-table td:nth-child(4) {
        display: inline-block;
        margin-right: 0.5rem;
    }
    .data-table td.td-responsible::before {
        content: "Responsable:";
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-muted);
        margin-right: 0.5rem;
        text-transform: uppercase;
    }
    
    /* Celda 5 (Canales) */
    .data-table td:nth-child(5) {
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid var(--border);
    }
    
    /* Celda 6 (Ok) */
    .data-table td:nth-child(6) {
        position: absolute;
        top: 1rem;
        right: 1rem;
        text-align: right;
        width: auto;
        padding: 0;
    }
    
    /* 4. Ajustes del Modal/Sheet */
    .sheet-content {
        width: 100%;
    }

    /* 5. Bottom Tab Bar (Mobile Navigation) */
    .mobile-bottom-tabs {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: white;
        border-top: 1px solid var(--border);
        z-index: 50;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .mobile-bottom-tabs .nav-item {
        flex: 1;
        flex-direction: column;
        gap: 0.2rem;
        padding: 0.4rem;
        font-size: 0.7rem;
        font-weight: 600;
        border-radius: 0;
    }
    .mobile-bottom-tabs .nav-item i {
        width: 22px;
        height: 22px;
    }
    .mobile-bottom-tabs .nav-item.active {
        background-color: transparent;
        color: var(--primary);
    }
    /* Reservar espacio para que la tab bar no tape el contenido */
    .view-container {
        padding-bottom: calc(60px + 1.5rem);
    }

    /* 6. Conectados — vista mobile colapsada/expandida */
    .conectados-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .conectados-item {
        padding: 0;
    }
    .conectados-mobile-row {
        display: flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0.5rem 0.75rem 0.5rem 0.5rem;
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }
    .conectados-mobile-handle {
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-muted);
        flex-shrink: 0;
        touch-action: none;
    }
    .conectados-mobile-title {
        flex: 1;
        font-weight: 600;
        font-size: 0.95rem;
        color: var(--text-main);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }
    .conectados-mobile-chevron {
        width: 20px;
        height: 20px;
        color: var(--text-muted);
        transition: transform 0.2s;
        flex-shrink: 0;
    }
    /* Por defecto colapsado: ocultar drag-handle desktop, botones y contenido */
    .conectados-item .drag-handle { display: none; }
    .conectados-item .conectados-action-buttons { display: none; }
    .conectados-item .conectados-content { display: none; }
    /* Expandido: mostrar todo (menos el drag-handle de desktop) */
    .conectados-item.expanded {
        padding-bottom: 1rem;
    }
    .conectados-item.expanded .conectados-action-buttons { display: flex; }
    .conectados-item.expanded .conectados-content {
        display: flex;
        padding: 0 1rem;
    }
    .conectados-item.expanded .conectados-mobile-chevron {
        transform: rotate(180deg);
    }

    /* Action buttons (IA + borrar): cuando expanded, al final del bloque,
       no superpuestos con el chevron */
    .conectados-item.expanded .conectados-action-buttons {
        position: static;
        order: 99;
        padding: 0.25rem 1rem 0;
        justify-content: flex-end;
        gap: 1rem;
    }
    .conectados-item.expanded .btn-delete-conectados,
    .conectados-item.expanded .btn-gen-conectados {
        opacity: 1 !important;
        padding: 0.5rem !important;
    }
    .conectados-item.expanded .btn-delete-conectados i,
    .conectados-item.expanded .btn-gen-conectados i {
        width: 20px !important;
        height: 20px !important;
    }

    /* 7. Vista Conectados — la top-bar queda sin contenido útil
       (logo ya eliminado, btn-new-activity oculto globalmente) → ocultarla entera */
    body[data-view="conectados"] .top-bar {
        display: none;
    }
    body[data-view="conectados"] .view-container {
        padding-top: 1.5rem;
    }

    /* 8. Header de Conectados en mobile: stack vertical, sin "Generar Newsletter" */
    .conectados-header-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }
    .conectados-header-bar h2 {
        font-size: 1.1rem;
    }
    .conectados-header-actions {
        width: 100%;
        /* En mobile apilamos los controles (chip de Edición + botón Bloque)
           uno abajo del otro, ocupando el ancho completo. */
        flex-direction: column;
        gap: 0.5rem;
    }
    .conectados-header-actions > *,
    .conectados-header-actions #edition-control {
        width: 100%;
    }
    .conectados-header-actions #btn-edition {
        width: 100%;
        justify-content: space-between;
    }
    #btn-gen-newsletter {
        display: none !important;
    }
    #btn-add-block {
        width: 100% !important;
        padding: 0.7rem 0.5rem !important;
        font-size: 0.9rem !important;
        white-space: nowrap;
    }
    /* El popover del control de Edición en mobile: full-width, ancho al chip */
    .conectados-header-actions #edition-popover {
        right: 0;
        left: 0;
        min-width: 0;
    }

    /* Save status toast en mobile: arriba de la tab bar */
    .save-status {
        bottom: calc(60px + 0.75rem);
        right: 0.75rem;
    }

    /* 9. Salvaguardas anti-overflow horizontal */
    body {
        overflow-x: hidden;
    }
    .view-container,
    .content-wrapper {
        max-width: 100%;
        overflow-x: hidden;
    }
    /* Forzar a los grid items a respetar el ancho del grid
       (sin esto su min-width: auto les deja crecer hasta el contenido) */
    .conectados-grid {
        width: 100%;
        max-width: 100%;
    }
    .conectados-grid > .conectados-item {
        min-width: 0;
        max-width: 100%;
    }
}

/* Newsletter & Image Upload Styles */
.conectados-content {
    display: flex;
    gap: 1.5rem;
}

.conectados-image-area {
    width: 240px;
    height: 160px;
    background: #f8fafc;
    border: 2px dashed #e2e8f0;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
    transition: all 0.2s;
    position: relative;
}

.conectados-image-area:hover {
    border-color: var(--primary);
    background: #f1f5f9;
}

.newsletter-img-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.newsletter-img-placeholder {
    color: #94a3b8;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.newsletter-img-placeholder span {
    font-size: 0.75rem;
    font-weight: 500;
}

.conectados-text-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (max-width: 640px) {
    .conectados-content {
        flex-direction: column;
    }
    .conectados-image-area {
        width: 100%;
        height: 180px;
    }
}

/* ============================================================
   Vista previa compacta del bloque (desktop).
   La edición real pasa al modal — la vista previa NO es editable.
   ============================================================ */
.conectados-grid > .conectados-item .conectados-image-area {
    cursor: default;
}
.conectados-grid > .conectados-item .conectados-image-area:hover {
    border-color: #e2e8f0;
    background: #f8fafc;
}

.conectados-preview-title {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-main);
    margin: 0 0 0.4rem 0;
    /* Truncado a 2 líneas para mantener altura predecible */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.conectados-preview-snippet {
    font-size: 0.9rem;
    line-height: 1.55;
    color: #475569;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.conectados-block-badge {
    align-self: flex-start;
}

/* Espaciado más generoso en el botón Editar para que se note */
.conectados-action-buttons .btn-edit-conectados:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ============================================================
   Modal de edición de bloque
   ============================================================ */
.conectados-editor-overlay {
    /* hereda de .login-overlay */
    z-index: 1000;
}

.conectados-editor-card {
    /* override del max-width chico de .login-card */
    padding: 0 !important;
    text-align: left;
}

.conectados-editor-card textarea,
.conectados-editor-card input[type="text"] {
    font-family: inherit;
}

/* ============================================================
   Vista "Agenda de Compromisos" (rol Secretaría).
   Reproduce el diseño de la landing pública (static/compromisos/style.css)
   con clases prefijadas .cmp-* para no colisionar con la app. La diferencia:
   acá se puede crear y editar.
   ============================================================ */

/* Para Secretaría, la vista ES la pantalla: ocultamos la top-bar de la app y
   el padding del contenedor para que el header azul quede full-width. */
body[data-role="secretaria"] .top-bar { display: none; }
body[data-role="secretaria"] .view-container { padding: 0; background: #f7f8fb; }
body[data-role="secretaria"] .mobile-bottom-tabs { display: none; }

/* Área (Funcionarios): misma lógica que Secretaría — la vista es la pantalla. */
body[data-role="area"] .top-bar { display: none; }
body[data-role="area"] .view-container { padding: 0; background: #f7f8fb; }
body[data-role="area"] .mobile-bottom-tabs { display: none; }

/* En la vista de área, sólo las tarjetas propias son clickeables (editar). */
.cmp-card.cmp-clickable, .cmp-past-item.cmp-clickable { cursor: pointer; }
.cmp-card:not(.cmp-clickable) { cursor: default; }

.cmp-view {
    width: 100%;
    min-height: 100%;
    background: #f7f8fb;
    color: #0f172a;
}

.cmp-topbar {
    background: linear-gradient(135deg, #0742ab 0%, #052f7a 100%);
    color: white;
    padding: 1.5rem 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
}
.cmp-topbar-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.cmp-brand { display: flex; align-items: center; gap: 0.85rem; }
.cmp-brand-mark {
    width: 44px; height: 44px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.15);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1rem; letter-spacing: 0.5px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}
.cmp-brand-logo { height: 64px; width: auto; display: block; }
.cmp-brand-title { font-size: 1.15rem; font-weight: 700; line-height: 1.2; }
.cmp-brand-sub { font-size: 0.75rem; opacity: 0.8; margin-top: 0.15rem; letter-spacing: 0.3px; }

.cmp-actions { display: flex; align-items: center; gap: 0.6rem; }
.cmp-hub {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.8rem; font-weight: 500;
    padding: 0.45rem 0.65rem; border-radius: 8px;
    display: inline-flex; align-items: center; gap: 0.35rem;
}
.cmp-hub:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.cmp-new-btn {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.28);
    padding: 0.5rem 0.95rem; border-radius: 8px;
    font-size: 0.85rem; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; gap: 0.4rem;
    font-family: inherit; transition: background 0.15s;
}
.cmp-new-btn:hover { background: rgba(255, 255, 255, 0.28); }
.cmp-ghost-btn {
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.35);
    padding: 0.5rem 0.85rem; border-radius: 8px;
    font-size: 0.85rem; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; gap: 0.4rem;
    font-family: inherit; transition: background 0.15s;
}
.cmp-ghost-btn:hover { background: rgba(255, 255, 255, 0.14); }

.cmp-filters {
    max-width: 900px;
    margin: 1.25rem auto 0;
    padding: 0 1.25rem;
    display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.cmp-filter-btn {
    background: white;
    border: 1px solid #e2e8f0;
    color: #334155;
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    font-size: 0.82rem; font-weight: 500; cursor: pointer;
    transition: all 0.15s; font-family: inherit;
}
.cmp-filter-btn:hover { border-color: #0742ab; color: #0742ab; }
.cmp-filter-btn.active { background: #0742ab; color: white; border-color: #0742ab; }

/* Barra: buscador + filtro por responsable + icono "ver pasadas" */
.cmp-toolbar {
    max-width: 900px; margin: 0.85rem auto 0; padding: 0 1.25rem;
    display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
}
.cmp-search {
    flex: 1 1 240px; min-width: 170px;
    display: flex; align-items: center; gap: 0.5rem;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 0.6rem; padding: 0.5rem 0.75rem;
}
.cmp-search svg { width: 16px; height: 16px; color: #64748b; flex-shrink: 0; }
.cmp-search input {
    border: none; outline: none; width: 100%; background: transparent;
    font-size: 0.9rem; font-family: inherit; color: #0f172a;
}
.cmp-resp-filter {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 0.6rem;
    padding: 0.5rem 0.75rem; font-size: 0.88rem; font-family: inherit; color: #0f172a; cursor: pointer;
}
.cmp-icon-btn {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 0.6rem;
    width: 40px; height: 40px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: #64748b;
}
.cmp-icon-btn svg { width: 18px; height: 18px; }
.cmp-icon-btn:hover { border-color: #0742ab; color: #0742ab; }
.cmp-icon-btn.active { background: #eef2ff; border-color: #0742ab; color: #0742ab; }

.cmp-content { max-width: 900px; margin: 1.5rem auto; padding: 0 1.25rem 2rem; }
.cmp-empty { text-align: center; padding: 3rem 1rem; color: #64748b; font-size: 0.95rem; }

.cmp-day-group { margin-bottom: 2rem; }
.cmp-day-header {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
    color: #0742ab; letter-spacing: 1.2px;
    margin: 0 0 0.85rem;
    border-left: 3px solid #0742ab; padding-left: 0.65rem;
}
.cmp-day-header .cmp-day-date {
    font-size: 0.9rem; color: #334155; font-weight: 500;
    text-transform: none; letter-spacing: 0; margin-left: 0.5rem;
}

.cmp-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.06);
    margin-bottom: 0.75rem;
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 1rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.cmp-card:hover {
    border-color: #0742ab;
    box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.1), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
}
.cmp-time { font-size: 1.15rem; font-weight: 700; color: #0742ab; line-height: 1.1; padding-top: 0.15rem; }
.cmp-time .cmp-tbd { font-size: 0.8rem; color: #64748b; font-weight: 500; }
.cmp-body { min-width: 0; }
.cmp-title { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.4rem; color: #0f172a; }
.cmp-daybadge {
    display: inline-block;
    font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
    color: #0742ab; background: #dbeafe;
    padding: 0.12rem 0.5rem; border-radius: 999px;
    margin-bottom: 0.45rem;
}
.cmp-meta {
    display: flex; flex-wrap: wrap; gap: 0.4rem 1rem;
    font-size: 0.82rem; color: #64748b; margin-bottom: 0;
}
.cmp-meta strong { color: #334155; font-weight: 600; }
.cmp-desc { font-size: 0.92rem; color: #334155; line-height: 1.55; margin: 0 0 0.5rem; white-space: pre-wrap; }
.cmp-attach { margin-top: 0.6rem; }
.cmp-attach a {
    display: inline-flex; align-items: center; gap: 0.4rem;
    font-size: 0.82rem; font-weight: 600; color: #0742ab; text-decoration: none;
    padding: 0.4rem 0.7rem; border: 1px solid #cbd5e1; border-radius: 0.5rem; background: #f8fafc;
}
.cmp-attach a:hover { border-color: #0742ab; background: #eef2ff; }
.cmp-edit-hint { align-self: center; color: #94a3b8; display: flex; }

/* Sección "Pasadas": compacta y con menos peso visual, clickeable */
.cmp-past-section { margin-top: 2rem; }
.cmp-past-header {
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
    color: #94a3b8; border-top: 1px solid #e2e8f0; padding-top: 1rem; margin: 0 0 0.4rem;
}
.cmp-past-item {
    display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap;
    padding: 0.5rem 0.55rem; border-bottom: 1px solid #f1f5f9; border-radius: 0.4rem; cursor: pointer;
}
.cmp-past-item:hover { background: #f8fafc; }
.cmp-past-date { color: #94a3b8; font-weight: 600; font-size: 0.78rem; min-width: 60px; text-transform: capitalize; flex-shrink: 0; }
.cmp-past-time { color: #94a3b8; font-size: 0.8rem; font-variant-numeric: tabular-nums; min-width: 46px; flex-shrink: 0; }
.cmp-past-title { color: #475569; font-weight: 500; font-size: 0.88rem; flex: 1; min-width: 0; }

.cmp-footer {
    text-align: center;
    padding: 1.5rem 1.25rem;
    color: #64748b; font-size: 0.75rem;
    border-top: 1px solid #e2e8f0;
    background: white;
}

@media (max-width: 640px) {
    .cmp-topbar { padding: 1.1rem 1rem; }
    .cmp-brand-title { font-size: 1rem; }
    /* En mobile: sin pastillas de filtro ni botón Imprimir (usar desktop). */
    .cmp-filters { display: none; }
    #cmp-print-btn { display: none; }
    .cmp-content { padding: 0 1rem 2rem; margin-top: 1.25rem; }
    .cmp-card { grid-template-columns: 1fr; gap: 0.4rem; padding: 1rem; }
    .cmp-time { font-size: 0.95rem; }
    .cmp-title { font-size: 1rem; }
    .cmp-edit-hint { display: none; }
    /* Lugar / Participa: cada uno en su propia línea (no como tabla de 2 columnas). */
    .cmp-meta { flex-direction: column; gap: 0.2rem; }
}

/* --- Impresión a PDF por rango de fechas (botón "Imprimir") --- */
/* El layout/tipografía va FUERA de @media print para que la medición offscreen
   (el paginado por JS en printRange) calcule las mismas alturas que la
   impresión. @media print sólo agrega tamaño de página, saltos y visibilidad.
   Cada .cmp-pa-page es una hoja A4 con su encabezado y su pie ("Página N de M")
   repetidos — así el PDF queda paginado y con el título en todas las hojas. */
#cmp-print-area { display: none; }

.cmp-pa-page {
    box-sizing: border-box;
    width: 210mm; min-height: 295mm; padding: 12mm 16mm;
    display: flex; flex-direction: column; background: #fff; color: #1a1a1a;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 12px; line-height: 1.5;
}
.cmp-pa-body { flex: 1 1 auto; }
.cmp-pa-head { display: flex; align-items: center; gap: 12px; border-bottom: 2px solid #0742ab; padding-bottom: 8px; margin-bottom: 12px; }
.cmp-pa-logo { height: 40px; width: auto; display: block; }
.cmp-pa-head h1 { font-size: 18px; color: #0742ab; margin: 0; font-weight: 700; line-height: 1.15; }
.cmp-pa-head p { margin: 1px 0 0; color: #666; font-size: 11px; }
.cmp-pa-day-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #0742ab; border-bottom: 1px solid #cbd5e1; padding: 8px 0 3px; margin: 0; }
.cmp-pa-day-h .cont-tag { font-weight: 500; text-transform: none; letter-spacing: 0; color: #64748b; font-size: 0.92em; }
.cmp-pa-act { display: grid; grid-template-columns: 52px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px solid #eef1f5; }
.cmp-pa-time { font-weight: 700; color: #0742ab; }
.cmp-pa-title { font-weight: 700; font-size: 12.5px; margin-bottom: 3px; }
.cmp-pa-desc { color: #333; margin: 2px 0 4px; white-space: pre-wrap; }
.cmp-pa-meta { font-size: 11px; color: #475569; line-height: 1.6; }
.cmp-pa-meta strong { color: #1a1a1a; }
.cmp-pa-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid #cbd5e1; margin-top: 10px; padding-top: 6px; font-size: 10px; color: #666; }

@media print {
    body * { visibility: hidden !important; }
    #cmp-print-area, #cmp-print-area * { visibility: visible !important; }
    #cmp-print-area { display: block; position: absolute; inset: 0; width: 100%; }
    .cmp-pa-page { page-break-after: always; }
    .cmp-pa-page:last-child { page-break-after: avoid; }
    @page { size: A4; margin: 0; }
}

.conectados-editor-card #editor-image-area:hover {
    border-color: var(--primary);
    background: #f1f5f9;
}

/* Animación del loader del botón IA */
.spin {
    animation: spin 1s linear infinite;
}

