/* Template Gallery Styles */

.template-gallery-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

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

.template-gallery-modal {
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    background: var(--bg-primary, #fff);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.template-gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.template-gallery-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #333);
}

.template-gallery-close {
    position: relative; /* Required for data-tooltip CSS */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary, #666);
    transition:
        background-color 0.15s,
        color 0.15s;
}

.template-gallery-close:hover {
    background: var(--bg-hover, #f0f0f0);
    color: var(--text-primary, #333);
}

/* Toolbar */
.template-gallery-toolbar {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.template-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary, #f5f5f5);
    border-radius: 8px;
    max-width: 300px;
}

.template-search svg {
    flex-shrink: 0;
    color: var(--text-secondary, #666);
}

.template-search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--text-primary, #333);
    outline: none;
}

.template-search-input::placeholder {
    color: var(--text-secondary, #999);
}

/* Body */
.template-gallery-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Categories sidebar */
.template-categories {
    width: 180px;
    padding: 16px;
    border-right: 1px solid var(--border-color, #e0e0e0);
    overflow-y: auto;
    flex-shrink: 0;
}

.template-category-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary, #666);
    transition:
        background-color 0.15s,
        color 0.15s;
    text-align: left;
}

.template-category-btn:hover {
    background: var(--bg-hover, #f5f5f5);
    color: var(--text-primary, #333);
}

.template-category-btn.active {
    background: var(--primary-light, #e3f2fd);
    color: var(--primary-color, #2196f3);
}

.template-category-btn .material-icons {
    font-size: 18px;
}

/* Template grid */
.template-grid {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    align-content: start;
}

.template-loading,
.template-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-secondary, #666);
    text-align: center;
}

.template-empty svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.template-empty p {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 500;
}

.template-empty span {
    font-size: 13px;
    opacity: 0.7;
}

/* Template card */
.template-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition:
        transform 0.15s,
        box-shadow 0.15s,
        border-color 0.15s;
}

.template-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color, #2196f3);
}

.template-preview {
    aspect-ratio: 100 / 130;
    background: var(--bg-secondary, #f5f5f5);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

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

.template-preview svg {
    width: 80%;
    height: 80%;
}

.template-info {
    padding: 12px;
    border-top: 1px solid var(--border-color, #e0e0e0);
}

.template-name {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.template-description {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--text-secondary, #666);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    min-height: 34px;
}

.template-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary, #888);
}

.template-category {
    background: var(--bg-secondary, #f0f0f0);
    padding: 2px 8px;
    border-radius: 4px;
}

/* Footer */
.template-gallery-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color, #e0e0e0);
    display: flex;
    justify-content: center;
}

.template-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition:
        background-color 0.15s,
        transform 0.1s;
}

.template-btn:active {
    transform: scale(0.98);
}

.template-btn-primary {
    background: var(--primary-color, #2196f3);
    color: white;
}

.template-btn-primary:hover {
    background: var(--primary-dark, #1976d2);
}

.template-btn-secondary {
    background: var(--bg-secondary, #f0f0f0);
    color: var(--text-primary, #333);
}

.template-btn-secondary:hover {
    background: var(--bg-hover, #e0e0e0);
}

/* Dark theme */
[data-theme='dark'] .template-gallery-modal {
    background: var(--bg-primary);
}

[data-theme='dark'] .template-card {
    background: var(--bg-secondary);
}

[data-theme='dark'] .template-preview {
    background: #1e1e1e;
}

/* Responsive */
@media (max-width: 768px) {
    .template-gallery-modal {
        width: 95%;
        max-height: 90vh;
    }

    .template-gallery-body {
        flex-direction: column;
    }

    .template-categories {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color, #e0e0e0);
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }

    .template-category-btn {
        padding: 8px 12px;
    }

    .template-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}
