/* Globale variabler for konsistens */
:root {
  --bg-light: #f0f0f0;
  --bg-toggle: #f9f9f9; /* Beholdt hvis du vil differentiere, ellers sæt til --bg-light */
  --fade-width: 40px;
  --gap: 8px;
  --padding: 10px 12px;
  --button-padding: 6px 12px;
  --font-size: 0.95rem;
  --border: 1px solid #ccc;
  --active-bg: #0a84ff;
  --active-color: white;
  --shadow-scroll: inset 0 -2px 0 rgba(0,0,0,0.1);
}

/* Globale button-stilarter (brugtes af både day og toggle) */
#day-buttons button,
#toggle-buttons button {
  flex: 0 0 auto;
  padding: var(--button-padding);
  font-size: var(--font-size);
  border: var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 4px;
}

#day-buttons button.active,
#toggle-buttons button.active {
  background: var(--active-bg);
  color: var(--active-color);
  border-color: var(--active-bg);
}

/* Emoji-specifikt (kun toggle) */
#toggle-buttons .emoji {
  flex-shrink: 0;
  width: 1em;
  height: 1em;
  margin: 0;
  padding: 0;
  vertical-align: middle;
  display: inline-block;
}

/* ----------------------- */
/* Mobil (max-width: 768px) */
/* ----------------------- */
@media (max-width: 768px) {
  /* Fælles fade-effekter for begge containere */
  .day-buttons-container::before,
  .toggle-buttons-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: var(--fade-width);
    height: 100%;
    pointer-events: none;
    z-index: 2;
    background: linear-gradient(to right, var(--bg-light), rgba(240,240,240,0));
    opacity: var(--fade-left-opacity, 0);
    transition: opacity 0.3s;
  }

  .day-buttons-container::after,
  .toggle-buttons-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: var(--fade-width);
    height: 100%;
    pointer-events: none;
    z-index: 2;
    background: linear-gradient(to left, var(--bg-light), rgba(240,240,240,0));
    opacity: var(--fade-right-opacity, 1);
    transition: opacity 0.3s;
  }

  /* Day-buttons container (kun position) */
  .day-buttons-container {
    position: relative;
  }

  /* Toggle-buttons container (overflow hidden for fade) */
  .toggle-buttons-container {
    position: relative;
    overflow: hidden;
    width: 100%;
  }

  /* Fælles scrolling-opsætning for begge button-containere */
  #day-buttons,
  #toggle-buttons {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--gap);
    padding: var(--padding);
    background: var(--bg-light);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    align-items: center;
    scroll-behavior: smooth;
    box-shadow: var(--shadow-scroll);
  }
}

/* ----------------------- */
/* Desktop / generelt */
/* ----------------------- */
#day-buttons,
#toggle-buttons {
  display: flex;
  gap: var(--gap);
  padding: var(--padding);
  background: var(--bg-light);
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  align-items: center;
  scroll-behavior: smooth;
  box-shadow: var(--shadow-scroll);
}

/* TV-GUIDE GRID */
#guide {
  display: flex;
  flex-wrap: wrap;
  margin: 1px;
}

.channel {
  background: #fff;
  flex: 1 1 220px;
  margin: 0 0.5rem 1rem 0.5rem;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}

.channel h2 {
  margin: 0;
  padding: 8px;
  background: #fafafa;
  border-bottom: 1px solid #ddd;
  text-align: center;
  font-size: 1.1rem;
}

/* PROGRAMMER */
.program {
  display: grid;
  grid-template-columns: 50px 1fr;
  column-gap: 4px; /* Tilføjet mellemrum mellem tid og titel */	
  padding: 6px 10px;
  border-bottom: 1px solid #eee;
  font-size: 0.95rem;
  word-wrap: break-word;
  cursor: pointer;
  transition: background 0.2s;
}

.program:hover {
  background: #f3f6ff;
}

.program:last-child { border-bottom: none; }

.time { font-weight: bold; }

/* STREAMING IMAGE */
.program-image {
  width: 100%;
  margin: 5px 0;
  display: flex;
  justify-content: center;
}

.program-image img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  object-fit: cover;
}

/* REDIGER-KANALER KNAP & SØGEKNAP (NY: Matcher #edit-channels-stilen) */
#edit-channels,
#search-guide {
  margin: 0 0 10px 0;  /* NY: Lidt margin mellem knapperne */
  background: #eee;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  display: inline-block;  /* NY: For at placere dem side om side */
  margin-right: 10px;  /* NY: Spacing mellem søg og rediger */
}

/* FÆLLES MODAL-STYLING */
span#close-channel { font-size: xx-large; }
span#close-search {
    font-size: x-large;
}
h2#search-title {
    margin-top: 10px !important;
}
#channel-modal h2,
#program-modal h2 { margin-top: 0 !important; margin-bottom:10px!important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
  background: white;
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  position: relative;
  animation: fadeIn 0.25s ease;
}

#channel-modal .modal-content { margin-top: 70px; }

#program-modal h2 { margin-top: 0; font-size: 1.4rem; }
#program-modal p { margin: 6px 0; line-height: 1.4; }
.program-permalink {
    margin-top: 10px;
}

#program-modal .close {
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 1.8rem;
  cursor: pointer;
  color: #444;
}

/* KANALMODAL */
#channel-list { list-style: none; margin: 0; padding: 0; }
#channel-list li { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  padding: 6px; 
  border-bottom: 1px solid #ddd; 
  cursor: grab; 
}
#channel-list li.dragging { opacity: 0.5; }
input[type="checkbox"] { transform: scale(1.5); }

/* NY: SortableJS-styling for bedre drag-and-drop UX */
#channel-list li.sortable-chosen {
  background: #e3f2fd;
}
#channel-list li.sortable-ghost {
  opacity: 0.4;
  background: #f0f0f0;
  border: 2px dashed #ccc;
}
#channel-list li.sortable-drag {
  transform: rotate(5deg);
}
#channel-list li:active {
  cursor: grabbing;
}

.modal-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.modal-buttons button {
  flex: 1;
  margin: 0 4px;
  padding: 6px;
  border-radius: 4px;
  border: 1px solid #ccc;
  cursor: pointer;
  background: #f9f9f9;
}

#reset-channels {
  background: #fff3cd;
  border: 1px solid #e0a800;
  color: #8a6d3b;
}

#reset-channels:hover { background: #ffe8a1; }

/* Søge-modal specifik styling */
#search-modal .modal-content {
  max-width: 600px;
  max-height: 80vh;
}

.search-input-container {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  position: relative;
}

#search-input {
  flex: 1;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  outline: none;
}

#search-input:focus {
  border-color: var(--active-bg);
  box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
}

#clear-input {
  padding: 12px;
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  display: none;  /* Vis kun når der er tekst */
}

#clear-input:hover {
  background: #e0e0e0;
}

/* Resultater styling (fra tidligere forslag) – FORBEDRET: Undgå overlap med ikon */
#search-results {
  max-height: 400px;
  overflow-y: auto;
  padding: 10px 0;
}

.search-result-item {
  display: flex;
  flex-direction: column;
  padding: 12px 12px 12px 12px;  /* NY: Padding-right reserverer plads til ikon */
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  padding-right: 40px;  /* NY: Plads til ikon uden overlap */
}

.search-result-item:hover {
  background: #f9f9f9;
}

.search-result-item h3 {
  margin: 0 0 4px 0;
  font-size: 1.1rem;
  color: #333;
  overflow: hidden;  /* NY: Håndter lange titler */
  word-break: break-word;  /* NY: Bryd ord for bedre flow */
  line-height: 1.2;
}

.search-result-item h3 small {
  font-size: 0.85rem;
  color: #666;
  margin-left: 8px;
}

.search-result-item p {
  margin: 4px 0 0 0;  /* Opretthold lille top-margin, ingen bottom for kompakt look */
  color: #888;
  font-size: 0.9rem;
  line-height: 1.3!important;  /* Kompakt linjehøjde – overskriver temaets 1.7 */
}

.search-result-item .channel-icon {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 24px;
  height: 24px;
  object-fit: contain;
  z-index: 1;  /* NY: Sikrer ikon er over tekst hvis nødvendigt */
}

.no-results {
  text-align: center;
  padding: 40px 20px;
  color: #999;
  font-style: italic;
}

/* Responsivt: På små skærme, fuldskærm modal */
@media (max-width: 768px) {
  #search-modal .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  /* NY: På mobil, reducer ikon-størrelse og padding for bedre plads */
  .search-result-item {
    padding-right: 32px;
  }

  .search-result-item .channel-icon {
    width: 20px;
    height: 20px;
    right: 8px;
    top: 12px;
  }
}

/* RESPONSIVT LAYOUT */
@media (min-width: 768px) { .channel { flex: 0 0 calc(33.333% - 1rem); max-width: 300px; } }
@media (min-width: 640px) and (max-width: 767px) { .channel { flex: 0 0 calc(50% - 1rem); } }
@media (max-width: 639px) { .channel { flex: 0 0 100%; margin: 0 0 1rem 0; } }

/* FULDBREDDE REKLAME SEKTIONER */
.full-width-ad {
  width: 100%;
  margin: 2rem 0;
  display: block;
  text-align: center;
}

.full-width-ad > div {
  display: inline-block;
  max-width: 100%;
}

/* FOOTER */
footer {
  padding: 8px 20px;
  font-size: 0.8rem;
  color: #666;
  text-align: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.channel-logo {
  width: 40px;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0.5rem auto 0.5rem auto;
  object-fit: contain;
}

.streaming-title {
font-size: 0.95rem;
    word-wrap: break-word;
    cursor: pointer;
}

.streaming-genre {
  color: #888;
  font-size: 0.85em;
}
.streaming-image {
  text-align: center; /* Centrerer indhold horisontalt */
  position: relative; /* For badge-positionering */
}

.streaming-image img {
  max-width: 90%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* .episode-badge forbliver som du har den – ingen ændringer nødvendige */
.episode-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: #2c2f34;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  font-family: Arial, sans-serif;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  transform: translateZ(0);
}

/* Responsiv (hvis du vil have den) */
@media (max-width: 768px) {
  .episode-badge {
    font-size: 10px;
    padding: 3px 6px;
    top: 5px;
    right: 5px;
  }
}