/* === Variables === */
:root {
    --primary: #1a56db;
    --primary-dark: #1544b5;
    --primary-light: #e8f0fe;
    --accent: #f59e0b;
    --accent-hover: #d97706;
    --text: #1f2937;
    --text-muted: #6b7280;
    --bg: #ffffff;
    --bg-alt: #f8fafc;
    --border: #e5e7eb;
    --success: #059669;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --max-width: 1200px;
    --transition: 150ms ease;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
ul { list-style: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input { font: inherit; }

/* === Layout === */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

/* === Header === */
.header {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 64px;
}
.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text);
    text-decoration: none;
    flex-shrink: 0;
}
.logo:hover { text-decoration: none; }
.logo-icon { flex-shrink: 0; }

.search-form {
    flex: 1;
    max-width: 400px;
    position: relative;
    display: flex;
}
.search-input {
    width: 100%;
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-alt);
    font-size: 0.875rem;
    transition: border-color var(--transition);
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg);
}
.search-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    padding: 0.25rem;
}

.nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.nav a {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--transition);
    text-decoration: none;
}
.nav a:hover {
    background: var(--bg-alt);
    text-decoration: none;
}

.mobile-menu-btn { display: none; color: var(--text); }

/* === Hero === */
.hero {
    background: linear-gradient(135deg, var(--primary-light) 0%, #f0f4ff 100%);
    padding: 3rem 0;
    text-align: center;
}
.hero h1 {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.75rem;
}
.hero-subtitle {
    color: var(--text-muted);
    font-size: 1.125rem;
    margin-bottom: 1.5rem;
}
.hero-search {
    max-width: 560px;
    margin: 0 auto 1.5rem;
    display: flex;
    gap: 0.5rem;
}
.hero-search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color var(--transition);
}
.hero-search-input:focus {
    outline: none;
    border-color: var(--primary);
}
.hero-categories {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}
.category-pill {
    display: inline-block;
    padding: 0.375rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    transition: all var(--transition);
    text-decoration: none;
}
.category-pill:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    text-decoration: none;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.875rem;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent {
    background: var(--accent);
    color: white;
}
.btn-accent:hover { background: var(--accent-hover); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }

.btn-download {
    background: var(--bg);
    border: 2px solid var(--border);
    color: var(--text);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}
.btn-download:hover {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: var(--shadow-md);
}
.btn-download--docx:hover { border-color: #2b5797; color: #2b5797; }
.btn-download--xlsx:hover { border-color: #217346; color: #217346; }
.btn-download--pdf:hover { border-color: #d32f2f; color: #d32f2f; }

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

.download-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

/* === Sections === */
.section { padding: 3rem 0; }
.section-alt { background: var(--bg-alt); }
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}
.section-header .section-title { margin-bottom: 0; }
.section-link {
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
}

/* === Template Grid === */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* === Template Card === */
.template-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition);
}
.template-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}
.template-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}
.template-card-link:hover { text-decoration: none; }
.template-card-preview {
    aspect-ratio: 4/3;
    overflow: hidden;
    background: var(--bg-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}
.template-card-preview img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}
.template-card-preview--placeholder {
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
}
.template-card-body {
    padding: 1rem;
}
.template-card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--text);
    line-height: 1.4;
}
.template-card-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    line-height: 1.5;
}
.template-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* === Format Badges === */
.format-badges { display: flex; gap: 0.375rem; flex-wrap: wrap; }
.format-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.format-badge--docx { background: #dbeafe; color: #2b5797; }
.format-badge--xlsx { background: #dcfce7; color: #217346; }
.format-badge--pdf { background: #fce4ec; color: #d32f2f; }
.format-badge--pptx { background: #fff3e0; color: #d84315; }
.format-badge--odt { background: #e8eaf6; color: #3949ab; }

.download-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* === Trust Section === */
.trust-section {
    padding: 3rem 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
}
.trust-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    text-align: center;
}
.trust-icon {
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: center;
}
.trust-item h3 {
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
}
.trust-item p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* === Breadcrumb === */
.breadcrumb {
    padding: 1.25rem 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb-sep {
    margin: 0 0.5rem;
    color: var(--border);
}

/* === Template Detail === */
.template-detail {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2.5rem;
    padding-bottom: 3rem;
}
.template-detail h1 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
}
/* Sidebar illustration on detail page */
.sidebar-illustration {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    margin-bottom: 1.5rem;
}
.sidebar-illustration img {
    max-width: 200px;
    height: auto;
}
.download-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--bg-alt);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}
.download-section h2 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.template-content { margin-bottom: 2rem; }
.template-meta-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* === Sidebar === */
.template-sidebar {
    position: sticky;
    top: 80px;
}
.template-sidebar h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
}
.related-list { display: flex; flex-direction: column; gap: 0.75rem; }
.related-item {
    display: block;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: all var(--transition);
}
.related-item:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}
.related-item h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
}

/* === Prose === */
.prose h2 { font-size: 1.375rem; margin: 2rem 0 0.75rem; }
.prose h3 { font-size: 1.125rem; margin: 1.5rem 0 0.5rem; }
.prose p { margin-bottom: 1rem; }
.prose ul, .prose ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li { margin-bottom: 0.375rem; }
.prose a { color: var(--primary); text-decoration: underline; }
.prose strong { font-weight: 600; }

/* === Search === */
.search-form-large {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
    max-width: 600px;
}
.search-input-large {
    flex: 1;
    min-width: 0;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}
.search-input-large:focus {
    outline: none;
    border-color: var(--primary);
}
.search-page-header {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}
.search-count {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* === Page Content === */
.page-content {
    max-width: 720px;
    padding: 2rem 0 3rem;
}
.page-content h1 { margin-bottom: 1.5rem; }

/* === Category Description === */
.category-description {
    color: var(--text-muted);
    margin-bottom: 2rem;
    max-width: 720px;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
    grid-column: 1 / -1;
}

/* === Mobile Download Bar === */
.mobile-download-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem;
    z-index: 50;
    gap: 0.5rem;
    justify-content: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

/* === Footer === */
.footer {
    background: var(--text);
    color: #d1d5db;
    padding: 3rem 0 1.5rem;
    margin-top: 3rem;
}
.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}
.footer h3 {
    color: white;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}
.footer p { font-size: 0.875rem; line-height: 1.6; }
.footer ul li { margin-bottom: 0.375rem; }
.footer a { color: #d1d5db; font-size: 0.875rem; }
.footer a:hover { color: white; }
.footer-bottom {
    border-top: 1px solid #374151;
    padding-top: 1.5rem;
    font-size: 0.8125rem;
    color: #9ca3af;
}

/* === Mobile === */
@media (max-width: 768px) {
    .container { padding: 0 1.25rem; }
    .nav { display: none; }
    .nav.is-open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        padding: 0.5rem;
        box-shadow: var(--shadow-lg);
    }
    .mobile-menu-btn { display: block; }
    .search-form { max-width: none; }

    .hero { padding: 2rem 0; }
    .hero h1 { font-size: 1.5rem; }
    .hero-subtitle { font-size: 1rem; }
    .hero-search { flex-direction: column; }
    .hero-categories { gap: 0.375rem; }
    .category-pill { font-size: 0.8125rem; padding: 0.25rem 0.75rem; }

    .section { padding: 2rem 0; }
    .section-title { font-size: 1.25rem; }

    .template-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .trust-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .template-detail {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    .template-detail h1 { font-size: 1.5rem; }

    .download-buttons { flex-direction: column; }
    .btn-download { width: 100%; justify-content: center; }

    .mobile-download-bar { display: flex; }
    .template-detail .download-section { margin-bottom: 1rem; }

    .footer-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .template-sidebar { position: static; }
    .sidebar-illustration { display: none; }

    .template-card-preview { aspect-ratio: 1/1; padding: 0.75rem; }
    .template-card-title { font-size: 0.875rem; }
    .template-card-desc { display: none; }
    .template-card-body { padding: 0.75rem; }

    /* Stack badges and download count vertically on small cards */
    .template-card-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    .template-card .download-count { display: none; }

    /* Search page fixes */
    .search-form-large {
        max-width: 100%;
        gap: 0.5rem;
    }
    .search-page-header {
        padding-top: 1rem;
        font-size: 1.5rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .template-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .template-detail {
        grid-template-columns: 1fr 250px;
    }
}
