{% extends "base.html" %}

{% block title %}{{ tag_name }} — {{ collection_title }}{% endblock %}

{% block extra_css %}
.dynamic-page {
  max-width: var(--layout-max-width);
  margin: 2rem auto;
  padding: 0 1rem;
}
.dynamic-page__header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--color-accent);
}
.dynamic-page__title {
  font-family: var(--font-heading);
  font-size: 2rem;
  color: var(--color-primary);
}
.dynamic-page__subtitle {
  color: var(--color-muted);
  margin-top: 0.25rem;
}
.article-list { list-style: none; }
.article-list__item {
  padding: 1.25rem 0;
  border-bottom: 1px solid #f0f0f0;
}
.article-list__item:first-child { padding-top: 0; }
.article-list__title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  color: var(--color-primary);
  line-height: 1.3;
  margin-bottom: 0.25rem;
}
.article-list__meta {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-bottom: 0.4rem;
}
.article-list__summary {
  font-size: 0.95rem;
  line-height: 1.5;
}
.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid #f0f0f0;
}
.pagination a, .pagination span {
  padding: 0.5rem 1rem;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  font-size: 0.9rem;
}
.pagination .current {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
.tag-link {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: #f3f4f6;
  border-radius: 1rem;
  font-size: 0.85rem;
  color: var(--color-text);
}
.tag-link:hover { background: var(--color-accent); color: #fff; text-decoration: none; }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-muted);
}
@media (max-width: 768px) {
  .dynamic-page__title { font-size: 1.5rem; }
  .article-list__title { font-size: 1.15rem; }
}
{% endblock %}

{% block content %}
<div class="dynamic-page">
  <div class="dynamic-page__header">
    <h1 class="dynamic-page__title">{{ tag_name }}</h1>
    <p class="dynamic-page__subtitle">{{ article_count }} {% if article_count == 1 %}artikkel{% else %}artikler{% endif %}</p>
  </div>

  {% if articles | length > 0 %}
  <ul class="article-list">
    {% for item in articles %}
    <li class="article-list__item">
      <h2 class="article-list__title"><a href="{{ base_url }}/{{ item.short_id }}">{{ item.title }}</a></h2>
      <div class="article-list__meta">{{ item.published_at_short }}</div>
      {% if item.summary %}
      <p class="article-list__summary">{{ item.summary }}</p>
      {% endif %}
    </li>
    {% endfor %}
  </ul>

  {% if total_pages > 1 %}
  <nav class="pagination">
    {% if current_page > 1 %}
    <a href="{{ base_url }}/kategori/{{ tag_slug }}?side={{ current_page - 1 }}">Forrige</a>
    {% endif %}
    {% for p in page_range %}
    {% if p == current_page %}
    <span class="current">{{ p }}</span>
    {% else %}
    <a href="{{ base_url }}/kategori/{{ tag_slug }}?side={{ p }}">{{ p }}</a>
    {% endif %}
    {% endfor %}
    {% if current_page < total_pages %}
    <a href="{{ base_url }}/kategori/{{ tag_slug }}?side={{ current_page + 1 }}">Neste</a>
    {% endif %}
  </nav>
  {% endif %}
  {% else %}
  <div class="empty-state">Ingen artikler i denne kategorien.</div>
  {% endif %}
</div>
{% endblock %}
