/* ============================================
   LAYOUT - I.E.P.E. Apóstol Pablo
   Estilos para sidebar, header y estructura principal
   ============================================ */

/* Variables de Layout */
.admin-layout {
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --header-height: 60px;
    --sidebar-bg: var(--color-primary);
    --sidebar-hover: rgba(255,255,255,0.1);
    --sidebar-active: rgba(255,255,255,0.2);
}

/* ============================================
   LAYOUT PRINCIPAL
   ============================================ */
.admin-layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-admin-base);
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: width 0.3s ease, transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
}

/* Header del Sidebar */
.sidebar-header {
    padding: 1.5rem 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo {
    display: flex;
    justify-content: center;
}

.sidebar .logo-img {
    width: 100px;
    height: auto;
    border-radius: 10px;
    transition: width 0.3s ease;
}

.sidebar.collapsed .logo-img {
    width: 50px;
}

.sidebar .logo-fallback {
    width: 80px;
    height: 80px;
}

.sidebar.collapsed .logo-fallback {
    width: 45px;
    height: 50px;
}

/* Navegacion del Sidebar */
.sidebar-nav {
    flex: 1;
    padding: 0.5rem 1rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    color: white;
    border-radius: 8px;
    margin-bottom: 2px;
    transition: background 0.2s ease;
    white-space: nowrap;
    text-decoration: none;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-item span {
    display: inline-block;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    font-size: 0.9rem;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--sidebar-hover);
}

.nav-item.active {
    background: var(--color-highlight);
    color: #1a1a1a;
    font-weight: 600;
}

.nav-item.active:hover {
    background: var(--color-highlight);
    color: #1a1a1a;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.85rem;
}

.sidebar.collapsed .nav-item span {
    display: none !important;
    opacity: 0;
    visibility: hidden;
}

/* ============================================
   GRUPOS ACORDEON SIDEBAR
   ============================================ */
.nav-group {
    margin-bottom: 2px;
}

.nav-group-header {
    cursor: pointer;
}

.nav-group-arrow {
    width: 16px;
    height: 16px;
    margin-left: auto;
    transition: transform 0.25s ease;
    opacity: 0.5;
}

.nav-group.expanded .nav-group-arrow {
    transform: rotate(90deg);
    opacity: 0.8;
}

.nav-group.expanded .nav-group-header {
    color: white;
}

.nav-group-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-group.expanded .nav-group-items {
    max-height: 500px;
}

.nav-sub-item {
    padding-left: 3rem !important;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.75) !important;
    white-space: nowrap !important;
}

.nav-sub-item span {
    display: inline-block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.nav-sub-item:hover {
    color: white !important;
    background: var(--sidebar-hover) !important;
}

.nav-sub-item.active {
    color: #1a1a1a !important;
}

.sidebar.collapsed .nav-group-arrow {
    display: none !important;
}

.sidebar.collapsed .nav-group-items {
    max-height: 0 !important;
}

.sidebar.collapsed .nav-sub-item span {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

.nav-separator {
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 0.5rem 0;
}

/* ============================================
   CONTENIDO PRINCIPAL
   ============================================ */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.sidebar.collapsed ~ .main-wrapper {
    margin-left: var(--sidebar-collapsed);
}

/* ============================================
   HEADER
   ============================================ */
.main-header {
    height: var(--header-height);
    min-height: var(--header-height);
    flex-shrink: 0;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-menu {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s ease;
}

.btn-menu:hover {
    background: var(--color-primary);
    color: white;
}

.btn-menu svg {
    width: 20px;
    height: 20px;
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #6b7280;
    margin: 0;
    padding: 0;
    list-style: none;
    background: none;
}

.breadcrumb-icon {
    display: flex;
    align-items: center;
}

.breadcrumb-icon svg {
    width: 16px;
    height: 16px;
}

.breadcrumb a {
    color: var(--color-primary);
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb .separator {
    color: #d1d5db;
}

.breadcrumb .current {
    color: #374151;
    font-weight: 500;
}

/* Header Derecha */
.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-datetime {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #64748b;
    font-size: 0.8rem;
    font-weight: 500;
    padding-right: 0.5rem;
    border-right: 1px solid #e5e7eb;
    white-space: nowrap;
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: #4b5563;
    position: relative;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: #f3f4f6;
    color: var(--color-primary);
}

.btn-icon svg {
    width: 22px;
    height: 22px;
}

/* Notificaciones */
.btn-notifications {
    position: relative;
}

.btn-notifications:hover {
    background: #dbeafe;
    color: #2563eb;
    border-color: #bfdbfe;
}

.notification-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--color-error);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* Usuario Dropdown */
.user-dropdown {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-left: 0.75rem;
    border-left: 1px solid #e5e7eb;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--color-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.user-avatar svg {
    width: 20px;
    height: 20px;
}

.user-info {
    display: flex;
    flex-direction: column;
    margin-right: 0.25rem;
}

.user-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: #1f2937;
    line-height: 1.2;
}

.user-role {
    font-size: 0.7rem;
    color: #6b7280;
    line-height: 1.2;
}

.btn-header-action {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    color: #64748b;
    text-decoration: none;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-header-action svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

.btn-header-action.btn-profile:hover {
    background: #dbeafe;
    color: #2563eb;
    border-color: #bfdbfe;
}

.btn-header-action.btn-logout:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

/* Contenido */
.main-content {
    flex: 1;
    padding: 1.5rem;
}

/* Overlay mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* ============================================
   NOTIFICATION DROPDOWN
   ============================================ */
.notification-wrapper {
    position: relative;
}

.notification-dropdown-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 999;
}

.notification-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: -60px;
    width: 380px;
    max-height: 520px;
    background: white;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 40px rgba(0,0,0,0.12), 0 2px 10px rgba(0,0,0,0.08);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #f1f5f9;
}

.dropdown-header h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #1e293b;
}

.dropdown-mark-all {
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: background 0.15s;
}

.dropdown-mark-all:hover {
    background: #eff6ff;
}

.dropdown-tabs {
    display: flex;
    border-bottom: 1px solid #f1f5f9;
    padding: 0 0.5rem;
}

.dropdown-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.6rem 0.25rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.dropdown-tab:hover {
    color: #334155;
    background: #f8fafc;
}

.dropdown-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}

.dropdown-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #e2e8f0;
    color: #475569;
    font-size: 0.65rem;
    font-weight: 700;
}

.dropdown-tab.active .dropdown-tab-badge {
    background: var(--color-primary);
    color: white;
}

.dropdown-list {
    flex: 1;
    overflow-y: auto;
    max-height: 320px;
}

.dropdown-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f8fafc;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    color: inherit;
}

.dropdown-item:hover {
    background: #f8fafc;
}

.dropdown-item.unread {
    background: #f0f7ff;
}

.dropdown-item.unread:hover {
    background: #e8f2ff;
}

.dropdown-item-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary);
    flex-shrink: 0;
    margin-top: 6px;
}

.dropdown-item-dot.read {
    background: #cbd5e1;
}

.dropdown-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
}

.dropdown-item-icon.notif { background: #3b82f6; }
.dropdown-item-icon.msg { background: #8b5cf6; }
.dropdown-item-icon.post { background: #f59e0b; }

.dropdown-item-icon svg {
    width: 18px;
    height: 18px;
}

.dropdown-item-body {
    flex: 1;
    min-width: 0;
}

.dropdown-item-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-item-text {
    font-size: 0.75rem;
    color: #64748b;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

.dropdown-item-time {
    font-size: 0.68rem;
    color: #94a3b8;
    margin-top: 3px;
}

.dropdown-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    color: #94a3b8;
}

.dropdown-empty svg {
    width: 40px;
    height: 40px;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.dropdown-empty p {
    font-size: 0.85rem;
    margin: 0;
}

.dropdown-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.dropdown-footer {
    border-top: 1px solid #f1f5f9;
    padding: 0.6rem 1rem;
    text-align: center;
}

.dropdown-footer a {
    color: var(--color-primary);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: color 0.15s;
}

.dropdown-footer a:hover {
    color: var(--color-primary-dark);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
    }

    .main-wrapper {
        margin-left: 0 !important;
    }

    .user-info {
        display: none;
    }

    .header-datetime {
        display: none;
    }
}

@media (max-width: 640px) {
    .main-header {
        padding: 0 1rem;
    }

    .main-content {
        padding: 1rem;
    }

    .breadcrumb {
        display: none;
    }

    .notification-dropdown {
        position: fixed;
        top: 60px;
        left: 0.5rem;
        right: 0.5rem;
        width: auto;
    }
}

/* ============================================
   PAGE LAYOUT STANDARD
   ============================================ */
.page-container {
    max-width: 100%;
    padding: 0.5rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.header-info h1 {
    font-size: 1.5rem;
    color: var(--text-dark);
    margin: 0 0 0.25rem;
}

.header-info p {
    color: var(--text-gray);
    font-size: 0.9rem;
    margin: 0;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        gap: 1rem;
    }

    .header-actions {
        width: 100%;
    }

    .header-actions button {
        flex: 1;
    }
}

/* ============================================
   PRINT - Ocultar layout, solo mostrar contenido
   ============================================ */
@page {
    margin: 0.5cm;
}

@media print {
    .sidebar,
    .sidebar-overlay,
    .main-header {
        display: none !important;
    }

    .admin-layout {
        display: block;
        background: white;
    }

    .main-wrapper {
        margin-left: 0 !important;
    }

    .main-content {
        padding: 0.5cm;
    }
}
