
/* ===== TEMPLATE LIBRARY MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background-color: rgba(0, 0, 0, 0.6); /* Darker backdrop */
    backdrop-filter: blur(8px); /* Stronger blur */
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: all 0.3s ease;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: #fff;
    width: 100%;
    max-width: 1100px; /* Slightly wider */
    height: 85vh;
    border-radius: 16px; /* More rounded */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); /* Smooth spring-like animation */
}

@keyframes modalSlideUp {
    from { transform: translateY(40px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
    z-index: 10;
}

.modal-title {
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.modal-close {
    background: var(--bg-surface-hover);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    background-color: var(--border-subtle);
    color: var(--text-primary);
    transform: rotate(90deg);
}

.modal-search {
    padding: 24px 32px 16px; 
    background-color: #fff;
    position: relative;
    /* Removed border-bottom as categories are below */
}

.modal-search i {
    position: absolute;
    left: 48px;
    top: calc(50% - 4px); /* Adjust for padding-bottom being smaller */
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.modal-search input {
    width: 100%;
    padding: 16px 20px 16px 50px;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    font-size: 1.05rem;
    outline: none;
    transition: all 0.2s;
    background-color: var(--bg-surface-hover);
    font-family: inherit;
}

.modal-search input:focus {
    background-color: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

/* ===== NEW CATEGORY FILTERS ===== */
.modal-categories {
    padding: 0 32px 24px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    background-color: #fff;
    border-bottom: 1px solid var(--border-subtle);
}

.category-btn {
    background: transparent;
    border: 1px solid var(--border-subtle);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.category-btn:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--text-tertiary);
    color: var(--text-primary);
}

.category-btn.active {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

/* ===== GRID ===== */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    padding: 32px;
    overflow-y: auto;
    background-color: var(--bg-body); /* Slightly gray background to contrast white cards */
}

/* Scrollbar styling */
.template-grid::-webkit-scrollbar {
    width: 8px;
}
.template-grid::-webkit-scrollbar-track {
    background: transparent;
}
.template-grid::-webkit-scrollbar-thumb {
    background-color: var(--border-subtle);
    border-radius: 4px;
}
.template-grid::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-tertiary);
}

.template-card {
    background: #fff;
    border: 1px solid transparent;
    border-radius: 16px;
    padding: 24px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* Subtle shadow initially */
}

.template-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 20px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-color: var(--primary-light);
}

/* Use a top border accent instead of side */
.template-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 4px; /* Small gap from edges */
    right: 4px;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 0 0 4px 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.template-card:hover::after {
    opacity: 1;
}

.template-card h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px; /* Space for tag */
}

.template-card h3 i {
    color: var(--primary);
    background-color: var(--primary-light);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.template-card p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-top: 4px;
}

.tag {
    align-self: flex-start;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px; /* Pill shape */
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-block;
}

/* Updated Tag Colors for better aesthetics */
.tag-finanzen { background-color: #eff6ff; color: #1e40af; border: 1px solid #dbeafe; }
.tag-recht { background-color: #fef2f2; color: #991b1b; border: 1px solid #fee2e2; }
.tag-bauleitung { background-color: #ffedd5; color: #9a3412; border: 1px solid #fed7aa; }
.tag-personal { background-color: #f0f9ff; color: #075985; border: 1px solid #e0f2fe; }
.tag-marketing { background-color: #faf5ff; color: #6b21a8; border: 1px solid #f3e8ff; }
.tag-kunden { background-color: #f0fdf4; color: #166534; border: 1px solid #dcfce7; }
.tag-betrieb { background-color: #fefce8; color: #854d0e; border: 1px solid #fef9c3; }

/* Responsive adjustments */
@media (max-width: 768px) {
    .modal-content {
        height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }
    
    .template-grid {
        padding: 20px;
        grid-template-columns: 1fr;
    }
    
    .modal-categories {
        padding: 0 20px 20px;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 12px;
        -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    }
    
    .category-btn {
        flex-shrink: 0;
    }

    .modal-header, .modal-search {
        padding: 20px;
    }
    
    .modal-search {
        padding-bottom: 12px;
    }
}
