:root {
  color-scheme: light dark;

  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-muted: #f0f0ee;
  --border: #e2e2df;
  --field-bg: #eae9e5;
  --field-border: #c7c6c0;
  --text: #1c1c1a;
  --text-muted: #6b6b66;
  --accent: #2f6f4f;
  --accent-contrast: #ffffff;
  --today-ring: #d98a2b;
  --danger: #b3403a;
  --danger-bg: rgba(179, 64, 58, 0.1);
  --danger-border: rgba(179, 64, 58, 0.4);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --surface: #202024;
    --surface-muted: #26262b;
    --border: #34343a;
    --field-bg: #2c2c33;
    --field-border: #4a4a53;
    --text: #ededeb;
    --text-muted: #a3a3a0;
    --accent: #5ba982;
    --accent-contrast: #0d1410;
    --today-ring: #e0a350;
    --danger: #e0776f;
    --danger-bg: rgba(224, 119, 111, 0.12);
    --danger-border: rgba(224, 119, 111, 0.4);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.site-header {
  padding: 1.5rem 1.25rem 1rem;
  max-width: 960px;
  margin: 0 auto;
}

.site-header h1 {
  margin: 0 0 0.9rem;
  font-size: 1.4rem;
  font-weight: 700;
}

.filter-toggle-btn {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  margin-bottom: 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.filter-toggle-btn:hover {
  background: var(--surface-muted);
}

.filter-toggle-arrow {
  font-size: 0.7rem;
  color: inherit;
}

.filter-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.9rem 0.2rem;
  margin-bottom: 0.6rem;
  background: var(--surface);
}

.external-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  margin-left: 0.6rem;
  margin-bottom: 0.6rem;
  vertical-align: middle;
}

.external-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.filter-group {
  margin-bottom: 0.6rem;
}

.filter-group-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.button-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.filter-btn {
  font: inherit;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
}

.filter-btn:hover {
  background: var(--surface-muted);
}

.filter-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.9rem;
}

.view-toggle {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.toggle-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.toggle-btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.search-field input {
  font: inherit;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.search-field input {
  width: 200px;
  max-width: 40vw;
}

.subscribe-btn {
  font: inherit;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.subscribe-btn:hover {
  background: var(--surface-muted);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
  text-align: right;
}

.site-footer a {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* Month view */

.month-nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0 1rem;
}

.month-nav h2 {
  margin: 0;
  font-size: 1.1rem;
  flex: 1;
}

.month-nav button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

.month-nav button:hover {
  background: var(--surface-muted);
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.weekday-row div {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-bottom: 0.2rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 92px;
  min-width: 0;
  overflow: hidden;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.day-cell.is-outside {
  background: transparent;
  border-color: transparent;
}

.day-cell.is-outside .day-number {
  color: var(--text-muted);
  opacity: 0.5;
}

.month-block {
  margin-top: 1.5rem;
}

.month-block-label {
  margin: 0 0 0.6rem;
  font-size: 1.1rem;
}

.more-months-row {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
}

.day-number {
  font-size: 0.8rem;
  font-weight: 600;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.day-cell.is-today .day-number {
  border: 2px solid var(--today-ring);
}

.day-events {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
  min-width: 0;
}

.day-event-chip {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text);
  border: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  width: 100%;
}

.day-event-chip:hover {
  background: var(--border);
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Markerer arrangementer automatisk hentet fra en ekstern abonnementskilde (ICS/RSS). */
.sync-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3b82f6;
  margin-left: 6px;
  vertical-align: middle;
  cursor: help;
}

.day-more {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding-left: 2px;
}

/* List view */

.list-month-heading {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 1.5rem 0 0.6rem;
}

.list-month-heading:first-child {
  margin-top: 0.5rem;
}

.list-item {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}

.list-item:hover {
  background: var(--surface-muted);
}

.list-date {
  min-width: 52px;
  text-align: center;
  flex-shrink: 0;
}

.list-date .dow {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.list-date .dom {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
}

.list-body {
  flex: 1;
  min-width: 0;
}

.list-title {
  font-weight: 600;
  margin: 0 0 2px;
}

.list-excerpt {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0 0 3px;
}

.list-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.empty-state {
  color: var(--text-muted);
  padding: 2rem 0;
  text-align: center;
}

/* Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  max-width: 420px;
  width: 100%;
  padding: 1.5rem;
  position: relative;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}

.modal-category {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 700;
  margin: 0 0 0.3rem;
}

.modal h3 {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
  padding-right: 1.5rem;
}

.modal-meta {
  margin: 0 0 0.2rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.modal-description {
  margin: 0.8rem 0 0;
  font-size: 0.92rem;
}

.modal-link {
  display: inline-block;
  margin-top: 1rem;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.modal-link:hover {
  text-decoration: underline;
}

/* Abonnementsmodal */

.subscribe-help {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.8rem 0;
}

.subscribe-url-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
}

.subscribe-url-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

.subscribe-url-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.subscribe-url-row button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}

.subscribe-url-row button:hover {
  background: var(--border);
}

.subscribe-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 1rem 0 0;
}

.subscribe-note code {
  background: var(--surface-muted);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

@media (max-width: 560px) {
  .day-cell {
    min-height: 70px;
  }
  .weekday-row div {
    font-size: 0.65rem;
  }
  .search-field input {
    width: 140px;
  }
}
