:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --ink: #1c1e27;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2f3e9e;
  --primary-ink: #ffffff;
  --accent: #f5a524;
  --danger: #d9463d;
  --danger-bg: #fdecea;
  --success: #1e8a4c;
  --success-bg: #e9f9ef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.75rem;
  background: linear-gradient(135deg, #1b2454, #2f3e9e);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.site-header .brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.3rem;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.site-header nav {
  display: flex;
  gap: 0.5rem;
}

.site-header nav a {
  color: #fff;
  text-decoration: none;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.15s ease;
}

.site-header nav a:hover {
  background: rgba(255, 255, 255, 0.24);
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1.75rem 3rem;
}

/* --- Date navigation --- */

.date-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
  position: sticky;
  top: 3.5rem;
  z-index: 10;
  background: var(--bg);
  padding: 0.75rem 0;
}

.date-picker {
  position: relative;
}

.date-nav-current {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
}

.date-nav-current::-webkit-details-marker {
  display: none;
}

.date-nav-current:hover {
  background: rgba(47, 62, 158, 0.08);
}

.date-nav-current strong {
  font-size: 1.15rem;
}

.date-nav-current span {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: capitalize;
}

.date-picker-list {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.2rem;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 30;
  width: max-content;
}

.date-picker-list a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
  white-space: nowrap;
  text-transform: capitalize;
}

.date-picker-list a:hover {
  background: rgba(47, 62, 158, 0.08);
}

.date-picker-list a.available {
  color: var(--ink);
  font-weight: 700;
}

.date-picker-list a.selected {
  background: var(--primary);
  color: #fff;
}

.nav-btn {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.nav-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(16, 24, 40, 0.06), 0 8px 20px rgba(16, 24, 40, 0.1);
}

/* --- Channel pager: pages through the channel list, N at a time --- */

.channel-pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.pager-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  text-decoration: none;
  font-size: 1.4rem;
  line-height: 1;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.pager-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(16, 24, 40, 0.06), 0 8px 20px rgba(16, 24, 40, 0.1);
}

.pager-btn.disabled {
  color: var(--border);
  box-shadow: none;
}

.pager-status {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 9rem;
  text-align: center;
}

/* --- Guide grid: shows one page of channels, no sideways scrolling --- */

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.1rem;
  align-items: start;
}

.channel-column {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.1rem 0.4rem;
  display: flex;
  flex-direction: column;
  max-height: 78vh;
}

.channel-column h2 {
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.05rem;
  font-weight: 700;
  padding-bottom: 0.65rem;
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.channel-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.programs {
  margin: 0;
  padding: 0 0 0.75rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.programs::-webkit-scrollbar {
  width: 6px;
}

.programs::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.programs ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.past-programs {
  margin-bottom: 0.4rem;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 0.3rem;
}

.past-programs summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.5rem;
  list-style: none;
}

.past-programs summary::-webkit-details-marker {
  display: none;
}

.past-programs summary::before {
  content: "\25B8  ";
}

.past-programs[open] summary::before {
  content: "\25BE  ";
}

.past-programs summary:hover {
  color: var(--primary);
}

.programs li {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border-radius: 8px;
}

.programs li:last-child {
  border-bottom: none;
}

.programs li.now {
  background: #fff6e6;
  box-shadow: inset 3px 0 0 var(--accent);
}

.programs .time {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.now-badge {
  background: var(--accent);
  color: #2a1c00;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.programs .title {
  font-weight: 600;
  line-height: 1.3;
}

.programs .desc {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.3;
}

.programs .empty {
  color: var(--muted);
  font-style: italic;
}

/* --- Messages --- */

.error {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #f5c2c0;
  padding: 0.75rem 1rem;
  border-radius: 10px;
}

.success {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid #b9e2c4;
  padding: 0.75rem 1rem;
  border-radius: 10px;
}

/* --- Admin --- */

form.import-form {
  margin-bottom: 0.5rem;
}

button.secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

table.channel-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
}

table.channel-table th,
table.channel-table td {
  text-align: left;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}

table.channel-table th {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.channel-table tr:last-child td {
  border-bottom: none;
}

form.login-form,
form.add-form {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

form.login-form label,
form.add-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"] {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--primary);
  color: var(--primary-ink);
  transition: filter 0.15s ease;
}

button:hover {
  filter: brightness(1.1);
}

button.danger {
  background: var(--danger);
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 480px;
  margin-bottom: 1.5rem;
}

.hint code {
  background: var(--border);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

h1 {
  font-size: 1.4rem;
  margin-bottom: 1.25rem;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2rem 0 1rem;
}

.site-footer a {
  color: var(--primary);
}

@media (max-width: 640px) {
  main {
    padding: 1rem;
  }

  .site-header {
    padding: 0.75rem 1rem;
  }

  .date-nav {
    top: 3.1rem;
  }

  .channel-column {
    max-height: none;
  }

  .programs {
    overflow-y: visible;
  }

  .date-picker-list {
    grid-template-columns: repeat(2, 1fr);
    width: 90vw;
    max-width: 320px;
    left: auto;
    right: -1.5rem;
    transform: none;
  }
}
