/* Card section container */
.card-section {
    background: white;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid #e5e7eb;
}

/* Section title */
.section-title {
    font-size: 18px;
    font-weight: 600;
    color: #111827;
    border: 1px solid #ffffff;
    border-radius: 4px;
    background: #ffffff;
}

/* Section title when focused */
.section-title:focus {
    outline: none;
    border-color: #3b82f6;
    background: white;
}

/* Section content container */
.section-content {
    display: flex;
}

/* Section editor container */
.section-editor {
    flex: 3; /* Reduced from 3 to give more space to bookmarks */
}

/* Section bookmarks container - Flex Grid Layout */
.section-bookmarks {
    flex: 1.2; /* Increased from 1.2 to give more space to bookmarks */
    display: flex;
    flex-wrap: wrap;
    gap: 2px; /* Changed to 2px gap */
    align-content: flex-start;
    box-sizing: border-box;
}

/* Ensure proper flex layout in expanded card */
.expanded .section-content {
    display: flex;
}

.card.expanded .editor-container,
.expanded .section-editor {
    flex: 2; /* Reduced from 3 to match section-editor */
}

.card.expanded .bookmarks-section,
.expanded .section-bookmarks {
    flex: 2; /* Increased from 1.2 for more space */
    display: flex;
    flex-wrap: wrap;
    gap: 8px; /* Changed to 2px gap */
    align-content: flex-start;
    box-sizing: border-box;
    margin-top: 75px;
}

/* Add section button container */
.add-section-container {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    position: sticky;
    bottom: 0;
    background: #ffffff;
    padding: 10px 0;
    z-index: 10;
}

/* Add section button */
.add-section-btn {
    background: #2d2d2d;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.add-section-btn:hover {
    background: #2563eb;
}

/* Dark mode support */
.dark-mode .add-section-container {
    background: #1f2937;
}

.dark-mode .card-section {
    background: #1f2937;
    border-color: #374151;
}

.dark-mode .section-title {
    color: #f3f4f6;
    background: #374151;
    border-color: #4b5563;
}

.dark-mode .section-title:focus {
    border-color: #60a5fa;
    background: #1f2937;
}

.dark-mode .section-bookmarks {
    background: transparent;
}

/* Bookmark Card Styles for Grid Layout */
.bookmark-card {
    /* Use flex basis for more reliable sizing */
    flex: 0 0 calc(50% - 1px); /* 2 per row with 2px gap */
    width: calc(50% - 1px); /* Fallback width */
    max-width: calc(50% - 1px); /* Prevent growing */
    background: #ffffff;
    border-radius: 8px;
    padding: 0;
    transition: all 0.3s ease;
    position: relative;
    border: none;
    display: flex;
    flex-direction: column;
    min-height: 200px; /* Reduced further since descriptions are hidden */
    box-sizing: border-box; /* Include padding and border in width */
}

.bookmark-card:hover {
    transform: translateY(-2px);
}

/* Remove margin-top from first bookmark - grid handles spacing */
.bookmark-card[data-bookmark-index="0"] {
    margin-top: 0;
}

/* Bookmark image placeholder */
.bookmark-image-placeholder {
    width: 100%;
    height: 60%; /* 60% of container height */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 6px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.bookmark-image-placeholder::before {
    content: "🔖";
    font-size: 28px; /* Reduced from 32px */
    opacity: 0.7;
    color: white;
}

.bookmark-image {
    width: 100%;
    height: 140px; /* Reduced from 120px */
    object-fit: cover;
    border-radius: 25px;
}

/* Bookmark title */
.bookmark-title {
    font-size: 13px; /* Reduced from 14px */
    font-weight: 600;
    margin-bottom: 6px;
    line-height: 1.3;
    color: #1f2937;
    padding: 12px 12px 0 12px; /* Add padding to title */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.bookmark-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s;
}

.bookmark-title a:hover {
    color: #667eea;
}

/* Bookmark description */
.bookmark-description {
    display: none; /* Hidden to make cards cleaner and more compact */
    font-size: 11px;
    color: #6b7280;
    line-height: 1.4;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex-grow: 1;
}

/* Bookmark date */
.bookmark-date {
    font-size: 10px; /* Reduced from 11px */
    color: #9ca3af;
    text-align: left;
    margin-top: auto;
    padding-right: 10px;
    padding-left: 12px;
}

/* Bookmark controls */
.bookmark-controls {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    padding: 11px;
}

.bookmark-move-btn {
    padding: 2px 6px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 11px;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    width: 20px;
}

.bookmark-move-btn:hover:not(:disabled) {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.bookmark-move-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.bookmark-move-btn svg {
    width: 12px;
    height: 12px;
}

/* Bookmark remove button in controls container */
.bookmark-controls-container {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 10;
    display: flex;
    gap: 2px;
}

.bookmark-remove-btn {
    padding: 2px 4px;
    background: #ef4444;
    border: 1px solid #dc2626;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    height: 20px;
    width: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.bookmark-remove-btn:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.bookmark-remove-btn svg {
    width: 12px;
    height: 12px;
}

/* Dark mode bookmark cards */
.dark-mode .bookmark-card {
    background: #374151;
    color: #f3f4f6;
}

.dark-mode .bookmark-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.dark-mode .bookmark-title {
    color: #f3f4f6;
}

.dark-mode .bookmark-title a:hover {
    color: #a5b4fc;
}

.dark-mode .bookmark-description {
    color: #d1d5db;
}

.dark-mode .bookmark-date {
    color: #9ca3af;
}

.dark-mode .bookmark-move-btn {
    background: #4b5563;
    border-color: #6b7280;
    color: #d1d5db;
}

.dark-mode .bookmark-move-btn:hover:not(:disabled) {
    background: #818cf8;
    border-color: #818cf8;
    color: white;
}

.dark-mode .bookmark-remove-btn {
    background: #dc2626;
    border-color: #b91c1c;
}

/* Responsive breakpoints */
@media (max-width: 1600px) {
    .bookmark-card {
        flex: 0 0 calc(33.333% - 10px); /* Maintain 3 per row */
        width: calc(33.333% - 10px);
        max-width: calc(33.333% - 10px);
    }
}

@media (max-width: 1200px) {
    .bookmark-card {
        flex: 0 0 calc(33.333% - 10px); /* Maintain 3 per row */
        width: calc(33.333% - 10px);
        max-width: calc(33.333% - 10px);
    }
    
    .section-bookmarks,
    .expanded .section-bookmarks {
        flex: 1.5; /* Adjust flex ratio for smaller screens */
    }
    
    .section-editor,
    .expanded .section-editor {
        flex: 2.5;
    }
}

@media (max-width: 1000px) {
    .bookmark-card {
        flex: 0 0 calc(50% - 7.5px); /* 2 per row on smaller screens */
        width: calc(50% - 7.5px);
        max-width: calc(50% - 7.5px);
    }
    
    /* Stack editor and bookmarks vertically on mobile */
    .section-content {
        flex-direction: column;
    }
    
    .section-bookmarks,
    .expanded .section-bookmarks {
        padding-left: 0;
        padding-top: 20px;
    }
}

/* Responsive design */
@media (max-width: 768px) {
    .section-content {
        flex-direction: column;
    }
    
    .section-editor {
        flex: none;
    }
    
    .section-bookmarks {
        flex: none;
        padding-left: 16px;
    }
}
