/* Grid Layout Fix: Use Flex for better handling of custom-sized modules */
.nvm-grid-container {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    padding: 30px 0;
    align-items: flex-start;
}

.nvm-module-box {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    /* Remove width: 100% to allow custom width */
    width: 250px; 
    height: 250px;
    min-width: 150px;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    box-sizing: border-box;
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1), box-shadow 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.nvm-module-box:hover {
    transform: translateY(-10px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.nvm-module-box.resizing {
    transition: none;
    transform: none;
    z-index: 1000;
    border-color: #007bff;
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.3);
}

/* Specific dimensions should disable aspect-ratio */
.nvm-module-box[style*="width"][style*="height"] {
    aspect-ratio: auto;
}

/* Resize Handle Upgrade */
.nvm-resize-handle {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 2px;
}

.nvm-resize-handle::after {
    content: "";
    width: 10px;
    height: 10px;
    border-right: 2px solid rgba(0,0,0,0.2);
    border-bottom: 2px solid rgba(0,0,0,0.2);
    transition: border-color 0.2s;
}

.nvm-resize-handle:hover::after {
    border-right-color: rgba(0,0,0,0.5);
    border-bottom-color: rgba(0,0,0,0.5);
}

/* Tooltip for resizing */
.nvm-resize-tooltip {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 101;
}

.resizing .nvm-resize-tooltip {
    opacity: 1;
}

.nvm-module-header {
    background: rgba(255, 255, 255, 0.3);
    padding: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    user-select: none;
}

.nvm-module-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: #1d1d1f;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nvm-module-body {
    padding: 20px;
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.65;
}

/* Skeleton UI */
.nvm-skeleton {
    width: 100%;
}

.nvm-skeleton-line {
    height: 14px;
    margin-bottom: 15px;
    background: linear-gradient(90deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.06) 75%);
    background-size: 200% 100%;
    animation: nvm-skeleton-loading 1.5s infinite ease-in-out;
    border-radius: 6px;
}

.nvm-skeleton-line:last-child {
    width: 70%;
}

@keyframes nvm-skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Themes */
.nvm-theme-dark .nvm-module-box {
    background: rgba(40, 40, 42, 0.8);
    border-color: rgba(255, 255, 255, 0.08);
    color: #f5f5f7;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.nvm-theme-dark .nvm-module-header {
    background: rgba(255, 255, 255, 0.03);
}

.nvm-theme-dark .nvm-module-header h3 { color: #f5f5f7; }

.nvm-theme-dark .nvm-skeleton-line {
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.05) 75%);
}

.nvm-theme-dark .nvm-resize-handle::after {
    border-right-color: rgba(255,255,255,0.3);
    border-bottom-color: rgba(255,255,255,0.3);
}

/* Modal Upgrade */
.nvm-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    transition: opacity 0.4s ease;
}

.nvm-modal-content {
    background: #fff;
    margin: 5vh auto;
    padding: 60px;
    border-radius: 30px;
    width: 85%;
    max-width: 1000px;
    height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.4);
    animation: nvm-modal-slide 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.nvm-theme-dark .nvm-modal-content {
    background: #1c1c1e;
    color: #f5f5f7;
    border: 1px solid rgba(255,255,255,0.1);
}

@keyframes nvm-modal-slide {
    from { transform: translateY(40px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.nvm-modal-close {
    color: #fff;
    position: fixed;
    top: 30px;
    right: 40px;
    font-size: 50px;
    font-weight: 200;
    cursor: pointer;
    z-index: 100001;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.nvm-modal-close:hover {
    transform: scale(1.2) rotate(90deg);
}

#nvm-modal-title {
    margin-top: 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding-bottom: 25px;
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.nvm-theme-dark #nvm-modal-title {
    border-bottom-color: rgba(255,255,255,0.1);
}

#nvm-modal-body {
    margin-top: 35px;
    font-size: 1.2rem;
    line-height: 1.8;
}

/* Scraped Content Styles */
.nvm-scraped-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nvm-scraped-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.4;
    color: inherit;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.nvm-scraped-desc {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
    opacity: 0.8;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.nvm-scraped-link {
    font-size: 0.75rem;
    opacity: 0.5;
    word-break: break-all;
    margin-top: 5px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nvm-error {
    color: #d63638;
    font-size: 0.9rem;
    text-align: center;
    padding: 10px;
    background: rgba(214, 54, 56, 0.1);
    border-radius: 10px;
}

.nvm-theme-dark .nvm-error {
    background: rgba(214, 54, 56, 0.2);
}