@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --blue-50: #eff6ff;
    --blue-100: #dbeafe;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --blue-700: #1d4ed8;
    --blue-800: #1e40af;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.08), 0 4px 8px rgba(0,0,0,0.04);
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--blue-600); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--blue-700); }

/* ── Header ── */
.header {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 2rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    background: rgba(255,255,255,0.95);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--gray-900);
    font-weight: 700;
    font-size: 1.05rem;
}
.header-logo:hover { color: var(--blue-600); }

.header-logo svg {
    width: 28px;
    height: 28px;
    color: var(--blue-600);
    flex-shrink: 0;
}

.header-logo-img {
    height: 28px;
    width: auto;
    flex-shrink: 0;
}

.header-center {
    flex: 1;
    max-width: 480px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--gray-500);
}

.header-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--blue-100);
    color: var(--blue-600);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    overflow: hidden;
    flex-shrink: 0;
}

.header-user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.header-admin-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-500);
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    transition: all var(--transition);
}
.header-admin-link:hover {
    color: var(--blue-600);
    border-color: var(--blue-200, #bfdbfe);
    background: var(--blue-50);
}
.header-admin-link svg { width: 14px; height: 14px; }

/* ── Search input (shared) ── */
.search-wrapper {
    position: relative;
    width: 100%;
}

.search-wrapper input {
    width: 100%;
    padding: 0.55rem 1rem 0.55rem 2.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-family: inherit;
    background: var(--gray-50);
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
    outline: none;
    color: var(--gray-800);
}
.search-wrapper input::placeholder { color: var(--gray-400); }
.search-wrapper input:focus {
    border-color: var(--blue-500);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-wrapper .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
    display: flex;
}
.search-wrapper .search-icon svg { width: 16px; height: 16px; }

/* ── Search dropdown ── */
.search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 200;
}
.search-dropdown.active { display: block; }

.search-dropdown-item {
    padding: 0.7rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--gray-100);
    text-decoration: none;
    color: var(--gray-800);
}
.search-dropdown-item:last-child { border-bottom: none; }
.search-dropdown-item:hover { background: var(--blue-50); color: var(--gray-800); }

.search-dropdown-item .item-title {
    font-size: 0.88rem;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-dropdown-item .item-cat {
    font-size: 0.7rem;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}
.search-dropdown-empty {
    padding: 1.25rem;
    text-align: center;
    color: var(--gray-400);
    font-size: 0.88rem;
}
.search-dropdown-more {
    display: block;
    padding: 0.65rem 1rem;
    text-align: center;
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--blue-600);
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    border-radius: 0 0 var(--radius) var(--radius);
    text-decoration: none;
    transition: background 0.15s;
}
.search-dropdown-more:hover { background: var(--gray-100); color: var(--blue-700); }
.search-dropdown-loading {
    padding: 1.25rem;
    text-align: center;
    color: var(--gray-400);
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--blue-500);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Hero ── */
.hero {
    text-align: center;
    padding: 4.5rem 2rem 3.5rem;
    background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 50%, #3b82f6 100%);
    color: #fff;
    position: relative;
    overflow: visible;
    z-index: 50;
}
.hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Ccircle cx='30' cy='30' r='2'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }

.hero h2 {
    font-size: 2.25rem;
    font-weight: 800;
    margin-bottom: 0.6rem;
    letter-spacing: -0.025em;
}
.hero p {
    color: rgba(255,255,255,0.8);
    font-size: 1.05rem;
    margin-bottom: 2rem;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.hero-search {
    position: relative;
    max-width: 560px;
    margin: 0 auto;
}
.hero-search input {
    width: 100%;
    padding: 1rem 1.25rem 1rem 3.25rem;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(8px);
    color: #fff;
    transition: all var(--transition);
    outline: none;
}
.hero-search input::placeholder { color: rgba(255,255,255,0.6); }
.hero-search input:focus {
    background: #fff;
    border-color: #fff;
    color: var(--gray-800);
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.hero-search input:focus::placeholder { color: var(--gray-400); }

.hero-search .search-icon {
    position: absolute;
    left: 1.1rem;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255,255,255,0.6);
    pointer-events: none;
    display: flex;
    transition: color var(--transition);
}
.hero-search input:focus ~ .search-icon,
.hero-search:focus-within .search-icon { color: var(--gray-400); }
.hero-search .search-icon svg { width: 18px; height: 18px; }
.hero-search .search-dropdown { text-align: left; }

/* ── Main content ── */
.main-content { flex: 1; }

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}
.container-wide { max-width: 1140px; }

/* ── Section title ── */
.section-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.75rem;
    padding-bottom: 0;
}
.section-title h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--gray-900);
}
.section-title .count {
    font-size: 0.8rem;
    color: var(--gray-400);
    font-weight: 500;
}

/* ── Departments panel (home) ── */
.departments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.department-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.35rem 1.5rem;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}
.department-card:hover {
    border-color: var(--blue-500);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.department-card-icon {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--blue-50);
    color: var(--blue-700);
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1;
}

.department-card-info { flex: 1; min-width: 0; }
.department-card-info h3 {
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.3;
}
.department-card-count {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.15rem;
}

.department-card-arrow {
    color: var(--gray-300);
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: all var(--transition);
}
.department-card:hover .department-card-arrow { color: var(--blue-600); transform: translateX(2px); }

/* ── Department badge (article meta, search results, dropdown) ── */
.department-badge,
.search-dropdown-item .item-dept {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--blue-700);
    background: var(--blue-50);
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Filter chips (search) ── */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}
.chip {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-600);
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 999px;
    padding: 0.3rem 0.85rem;
    text-decoration: none;
    transition: all var(--transition);
}
.chip:hover { border-color: var(--blue-500); color: var(--blue-600); }
.chip.active {
    background: var(--blue-600);
    border-color: var(--blue-600);
    color: #fff;
}

/* ── Categories grid ── */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
}

.category-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.5rem;
    transition: all var(--transition);
    cursor: default;
}
.category-card:hover {
    border-color: var(--blue-200, #bfdbfe);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.category-card-header {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.category-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--blue-50);
    color: var(--blue-600);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.category-card-icon svg { width: 20px; height: 20px; }

.category-card-info { flex: 1; min-width: 0; }
.category-card-info h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.15rem;
    line-height: 1.3;
}
.category-card-info h3 a {
    color: inherit;
    text-decoration: none;
}
.category-card-info h3 a:hover { color: var(--blue-600); }
.category-card-count {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.category-card-articles {
    list-style: none;
    margin: 0;
    padding: 0;
}
.category-card-articles li {
    border-top: 1px solid var(--gray-100);
}
.category-card-articles li a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0;
    color: var(--gray-600);
    font-size: 0.88rem;
    transition: color var(--transition);
}
.category-card-articles li a:hover { color: var(--blue-600); }
.category-card-articles li a::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--gray-300);
    flex-shrink: 0;
    transition: background var(--transition);
}
.category-card-articles li a:hover::before { background: var(--blue-500); }

.category-card-footer {
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--gray-100);
}
.category-card-footer a {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--blue-600);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.category-card-footer a:hover { gap: 0.5rem; }

/* ── Breadcrumb ── */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.84rem;
    color: var(--gray-400);
    margin-bottom: 1.5rem;
}
.breadcrumb a { color: var(--gray-500); }
.breadcrumb a:hover { color: var(--blue-600); }
.breadcrumb .sep { color: var(--gray-300); font-size: 0.75rem; }
.breadcrumb .current { color: var(--gray-600); }

/* ── Page title ── */
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 1.25rem;
}

/* ── Article list (category / search) ── */
.article-list { list-style: none; }

.article-list-item {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    transition: all var(--transition);
}
.article-list-item:hover {
    border-color: var(--blue-200, #bfdbfe);
    box-shadow: var(--shadow-sm);
}

.article-list-item a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.15rem;
    color: var(--gray-700);
    text-decoration: none;
    gap: 1rem;
}
.article-list-item a:hover { color: var(--blue-600); }

.article-list-title {
    font-weight: 500;
    font-size: 0.92rem;
    flex: 1;
    min-width: 0;
}

.article-list-meta {
    font-size: 0.75rem;
    color: var(--gray-400);
    white-space: nowrap;
    flex-shrink: 0;
}

.article-list-cat {
    font-size: 0.7rem;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Article detail ── */
.article-detail {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow-sm);
}

.article-detail-header {
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--gray-100);
}

.article-detail-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
    letter-spacing: -0.015em;
    line-height: 1.3;
}

.article-detail-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.82rem;
    color: var(--gray-400);
}
.article-detail-meta svg { width: 14px; height: 14px; }
.article-detail-meta span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.article-content {
    line-height: 1.85;
    color: var(--gray-700);
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.95rem;
}
.article-content img.zoomable { cursor: zoom-in; }

/* ── Ampliació d'imatges ── */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: rgba(17, 24, 39, 0.92);
}
.lightbox.open { display: flex; }
body.lightbox-open { overflow: hidden; }

.lightbox-figure {
    margin: 0;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}
.lightbox-figure img {
    max-width: 100%;
    /* Es reserva espai pel peu de foto perquè mai tapi la imatge. */
    max-height: calc(100vh - 8rem);
    object-fit: contain;
    border-radius: var(--radius-sm);
    background: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.lightbox-figure figcaption {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    text-align: center;
    max-width: 60ch;
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1.25rem;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.25); }

@media (max-width: 680px) {
    .lightbox { padding: 0.75rem; }
    .lightbox-figure img { max-height: calc(100vh - 6rem); }
}

.article-content img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    margin: 1rem auto;
    border: 1px solid var(--gray-200);
    float: none !important;
}
.article-content a { color: var(--blue-600); word-break: break-all; }
.article-content a:hover { text-decoration: underline; }
.article-content h1,
.article-content h2,
.article-content h3 {
    color: var(--gray-900);
    margin-top: 2rem;
    margin-bottom: 0.65rem;
    line-height: 1.3;
}
.article-content h1 { font-size: 1.5rem; }
.article-content h2 { font-size: 1.25rem; }
.article-content h3 { font-size: 1.1rem; }
.article-content p { margin-bottom: 1rem; }
.article-content ul,
.article-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}
.article-content li { margin-bottom: 0.35rem; }
.article-content code {
    background: var(--gray-100);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.88em;
}
.article-content pre {
    background: var(--gray-900);
    color: #e5e7eb;
    padding: 1.25rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin-bottom: 1rem;
    font-size: 0.88rem;
    line-height: 1.6;
}
.article-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.article-content blockquote {
    border-left: 3px solid var(--blue-500);
    margin: 1rem 0;
    padding: 0.75rem 1.25rem;
    background: var(--blue-50);
    color: var(--gray-700);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.article-content th,
.article-content td {
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--gray-200);
    text-align: left;
}
.article-content th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
}

/* ── No results ── */
.no-results {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--gray-400);
    font-size: 1rem;
}
.no-results svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ── Footer ── */
.footer {
    background: #fff;
    border-top: 1px solid var(--gray-200);
    padding: 1.5rem 2rem;
    text-align: center;
    margin-top: auto;
}
.footer-inner {
    max-width: 1140px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--gray-400);
}
.footer-inner a { color: var(--gray-500); }
.footer-inner a:hover { color: var(--blue-600); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .header { padding: 0 1rem; height: 56px; gap: 0.75rem; }
    .header-logo span { display: none; }
    .header-center { max-width: none; }
    .header-user span { display: none; }
    .header-admin-link span { display: none; }

    .hero { padding: 3rem 1.25rem 2.5rem; }
    .hero h2 { font-size: 1.65rem; }
    .hero p { font-size: 0.95rem; margin-bottom: 1.5rem; }
    .hero-search input { padding: 0.85rem 1rem 0.85rem 2.75rem; }

    .container { padding: 1.5rem 1rem; }
    .categories-grid { grid-template-columns: 1fr; gap: 1rem; }
    .category-card { padding: 1.25rem; }

    .page-title { font-size: 1.25rem; }

    .article-detail { padding: 1.5rem; }
    .article-detail-header h2 { font-size: 1.35rem; }

    .footer-inner { flex-direction: column; gap: 0.5rem; }
}

@media (max-width: 480px) {
    .header-center { display: none; }
    .hero h2 { font-size: 1.4rem; }
    .article-list-meta { display: none; }
}
