:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #152036;
  --ink-soft: #5c6780;
  --primary: #006d77;
  --primary-strong: #005660;
  --danger: #b42318;
  --border: #d7deea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, #d4f4ff 0, transparent 35%),
    radial-gradient(circle at bottom left, #ffe9d6 0, transparent 35%),
    var(--bg);
}

.app {
  width: min(1080px, 100% - 2rem);
  margin: 2rem auto 3rem;
  display: grid;
  gap: 1.25rem;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2.5vw, 2.4rem);
}

.header p {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
}

.user-banner {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.65rem;
  background: #f9fbff;
  overflow: visible;
}

.header {
  position: relative;
  padding-right: 320px;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #dce8fb;
  border: 1px solid #bfd4f4;
}

.user-avatar-img {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid #bfd4f4;
  display: block;
}

.icon-button {
  padding: 0;
  border: none;
  background: transparent;
}

.icon-button:hover {
  background: transparent;
}

.account-menu-wrap {
  position: relative;
}

.account-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  min-width: 190px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(17, 34, 67, 0.2);
  padding: 0.35rem;
  z-index: 600;
}

.menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
}

.menu-item:hover {
  background: #eef4ff;
}

.menu-item.danger-item {
  color: #b42318;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 5px 20px rgba(16, 30, 61, 0.05);
}

#pending-email-card {
  margin-top: 0.35rem;
  padding: 0.75rem;
  background: #f8fbff;
}

.auth-grid {
  display: grid;
  grid-template-columns: minmax(0, 460px);
  gap: 1rem;
}

#auth-login-panel,
#auth-register-panel {
  max-width: 460px;
}

.link-button {
  background: transparent;
  color: #1f4fa1;
  padding: 0;
  text-align: left;
}

.link-button:hover {
  background: transparent;
  color: #163e81;
  text-decoration: underline;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 900;
}

.modal-card {
  width: min(460px, 100%);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  box-shadow: 0 14px 34px rgba(16, 30, 61, 0.24);
}

.modal-card-wide {
  width: min(980px, 100%);
  max-height: 92vh;
  overflow-y: auto;
}

.avatar-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 0.9rem;
  align-items: center;
  padding: 0.35rem 0 0.55rem;
}

.avatar-preview-wrap {
  width: 96px;
  height: 96px;
  border-radius: 999px;
  border: 3px solid #0b5a64;
  background: #f1fbff;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.avatar-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-initials {
  font-size: 2rem;
  font-weight: 800;
  color: #0b5a64;
}

.avatar-controls .small {
  font-size: 0.82rem;
  margin-top: 0.25rem;
  color: var(--ink-soft);
}

.file-label input[type="file"] {
  margin-top: 0.35rem;
}

@media (max-width: 520px) {
  .avatar-row {
    grid-template-columns: 1fr;
  }
  .avatar-preview-wrap {
    justify-self: start;
  }
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.inline-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.sort-control select {
  width: auto;
  min-width: 92px;
  padding: 0.45rem 0.55rem;
}

.journey-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.journey-actions button {
  min-width: 180px;
}

.form {
  display: grid;
  gap: 0.85rem;
}

.form h3 {
  margin: 0;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.95rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: #fff;
}

.search-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.search-row input {
  flex: 1 1 auto;
}

.search-row button {
  flex: 0 0 auto;
  min-width: 120px;
  height: 42px;
  white-space: nowrap;
}

button {
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  padding: 0.6rem 0.85rem;
}

button:hover {
  background: var(--primary-strong);
}

button.secondary {
  background: #e7edf6;
  color: var(--ink);
}

button.secondary:hover {
  background: #dce5f2;
}

button.secondary.state-on {
  background: #d9f4df;
  color: #0b6b2f;
}

button.secondary.state-on:hover {
  background: #c6edcf;
}

button.secondary.state-enable {
  background: #d8e9ff;
  color: #114a9b;
}

button.secondary.state-enable:hover {
  background: #c7ddfb;
}

button.danger {
  background: #fdeae8;
  color: var(--danger);
}

button.danger:hover {
  background: #f8d8d4;
}

.status {
  color: var(--ink-soft);
  margin: 0.5rem 0 0;
}

.catalog-loading {
  margin-top: 0.75rem;
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  color: var(--ink-soft);
  user-select: none;
}

.catalog-loading-icon {
  width: 136px;
  height: 136px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  filter: drop-shadow(0 10px 18px rgba(16, 30, 61, 0.18));
  transform-origin: 50% 70%;
  animation: tvrt-tv-wiggle 0.9s ease-in-out infinite;
  /* Inline SVG "TV" icon (dark teal). */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Crect x='10' y='18' width='44' height='30' rx='6' fill='%230b5a64'/%3E%3Crect x='14' y='22' width='36' height='22' rx='3' fill='%23e9eef8' opacity='0.95'/%3E%3Crect x='22' y='50' width='20' height='4' rx='2' fill='%230b5a64'/%3E%3Cpath d='M24 10 L18 4' stroke='%230b5a64' stroke-width='4' stroke-linecap='round'/%3E%3Cpath d='M40 10 L46 4' stroke='%230b5a64' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E");
}

.catalog-loading-text {
  font-weight: 700;
  letter-spacing: 0.01em;
}

@keyframes tvrt-tv-wiggle {
  0% { transform: rotate(-6deg) translateY(0); }
  50% { transform: rotate(6deg) translateY(-1px); }
  100% { transform: rotate(-6deg) translateY(0); }
}

.catalog-grid {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
}

.recs-panel {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  background: linear-gradient(180deg, #fffaf0 0%, #f1fbff 100%);
  box-shadow: 0 14px 34px rgba(16, 30, 61, 0.08);
}

.recs-panel .section-header h3 {
  margin: 0;
  font-size: 1.02rem;
}

.recs-content.hidden {
  display: none;
}

.recs-panel.recs-collapsed {
  padding: 0.65rem 0.75rem;
  background: linear-gradient(180deg, #d1f0ff 0%, #ffe2b3 100%);
  border-color: #0b5a64;
  border-left: 8px solid #0b5a64;
}

.recs-panel.recs-collapsed .catalog-grid,
.recs-panel.recs-collapsed .recs-because,
.recs-panel.recs-collapsed .status {
  display: none;
}

.recs-because {
  margin-top: 0.85rem;
}

.recs-because h4 {
  margin: 0.25rem 0 0.35rem;
  font-size: 1.02rem;
  color: var(--ink);
}

.catalog-more {
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
}

.catalog-more button {
  min-width: 220px;
}

.catalog-filters {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.55rem;
}

.my-shows-filters {
  margin-top: 0.35rem;
}

#manual-match-panel {
  margin-top: 0.75rem;
}

#manual-match-panel .catalog-grid {
  margin-top: 0.5rem;
}

.catalog-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  display: grid;
  position: relative;
}

.catalog-image {
  width: 100%;
  height: 220px;
  object-fit: cover;
  background: #e9eef8;
}

.catalog-body {
  padding: 0.6rem;
  display: grid;
  gap: 0.4rem;
}

.catalog-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  margin-top: 0.1rem;
}

.catalog-actions button {
  width: 100%;
}

.catalog-title {
  margin: 0;
  font-size: 0.95rem;
}

.catalog-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  min-height: 2.4em;
}

.catalog-track {
  width: 100%;
}

.catalog-track.state-untracked {
  background: #006d77;
  color: #ffffff;
}

.catalog-track.state-untracked:hover {
  background: #005660;
}

.catalog-track.state-tracked {
  background: #e7edf6;
  color: #152036;
}

.catalog-track.state-tracked:hover {
  background: #dce5f2;
}

.catalog-detail {
  font-size: 0.82rem;
  color: #2a3958;
  background: #ffffff;
  border: 1px solid #c9d4e7;
  border-radius: 8px;
  padding: 0.5rem;
  line-height: 1.35;
  white-space: pre-line;
  opacity: 1;
}

.catalog-detail-popup {
  position: absolute;
  z-index: 20;
  left: 0.5rem;
  right: 0.5rem;
  top: 0.5rem;
  box-shadow: 0 14px 30px rgba(18, 34, 70, 0.28);
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  word-break: break-word;
}

.catalog-item .catalog-detail-popup {
  top: 0.45rem;
  bottom: 3.4rem;
  max-height: none;
}

.shows-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

.show-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  position: relative;
  overflow: visible;
}

.show-main {
  display: flex;
  gap: 0.75rem;
  position: relative;
}

.show-poster {
  width: 70px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  background: #e9eef8;
}

.show-detail {
  max-width: 360px;
}

.show-detail.catalog-detail-popup {
  right: 0.75rem;
  top: 0.75rem;
  left: auto;
  min-width: 300px;
  max-width: 420px;
  z-index: 400;
  background: #102a43;
  color: #f0f6ff;
  border: 1px solid #0b2034;
  box-shadow: 0 16px 36px rgba(4, 13, 25, 0.45);
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  word-break: break-word;
}

.show-detail.catalog-detail-popup strong {
  color: #9ad1ff;
}

.show-title {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.show-meta,
.show-provider {
  margin: 0.2rem 0;
  color: var(--ink-soft);
}

.show-notes {
  margin: 0.25rem 0 0;
  color: #37425c;
  white-space: pre-wrap;
}

.network-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 0.22rem 0.5rem;
  font-size: 0.63rem;
  letter-spacing: 0.03em;
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
  background: #111827;
  min-height: 22px;
  min-width: 64px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.network-label {
  display: inline-block;
  max-width: 112px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.network-abc { background: #111827; }
.network-nbc { background: #1f6fd8; }
.network-cbs { background: #143b8f; }
.network-fox { background: #0f172a; }
.network-fx { background: #27272a; }
.network-amc { background: #111827; color: #f59e0b; }
.network-hbo { background: #111827; }
.network-max { background: #1d4ed8; }
.network-netflix { background: #e50914; }
.network-hulu { background: #16a34a; color: #062e14; }
.network-prime { background: #0ea5e9; color: #062c3a; }
.network-apple { background: #111827; }
.network-peacock { background: #f59e0b; color: #1f2937; }
.network-disney { background: #1d4ed8; }
.network-paramount { background: #1e40af; }
.network-paramountplus { background: #1d4ed8; }
.network-showtime { background: #dc2626; }
.network-starz { background: #18181b; }
.network-cw { background: #65a30d; color: #102100; }

.actions {
  display: grid;
  gap: 0.45rem;
  align-content: start;
  width: 230px;
}

.actions button {
  width: 100%;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
}

.empty-state {
  color: var(--ink-soft);
}

.hidden {
  display: none !important;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.profile-span-2 {
  grid-column: span 2;
}

.streaming-fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  margin: 0;
}

.streaming-fieldset legend {
  padding: 0 0.35rem;
  color: var(--ink-soft);
}

.streaming-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.45rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  font-size: 0.92rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  background: #fff;
}

.checkbox-label input[type="checkbox"] {
  margin: 0;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.service-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  justify-content: flex-start;
  text-align: left;
}

.service-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 24px;
  border-radius: 6px;
  background: #e7eefb;
  color: #173a70;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid rgba(0, 0, 0, 0.12);
  letter-spacing: 0.02em;
}

.service-netflix { background: #e50914; color: #fff; }
.service-hulu { background: #1ce783; color: #032819; }
.service-disney { background: #113ccf; color: #fff; }
.service-max { background: #0057ff; color: #fff; }
.service-prime { background: #00a8e1; color: #062d3d; }
.service-apple { background: #111827; color: #fff; }
.service-peacock { background: #f59e0b; color: #1f2937; }
.service-paramount { background: #1e40af; color: #fff; }
.service-paramountplus { background: #173fa3; color: #fff; }
.service-youtube { background: #ff0033; color: #fff; }
.service-sling { background: #0066ff; color: #fff; }
.service-fubo { background: #f97316; color: #111827; }
.service-tubi { background: #7c3aed; color: #fff; }
.service-pluto { background: #ef4444; color: #fff; }
.service-amc { background: #111827; color: #fbbf24; }
.service-starz { background: #18181b; color: #fff; }
.service-showtime { background: #dc2626; color: #fff; }

.status {
  overflow-wrap: anywhere;
}

.address-suggestions {
  margin-top: 0.3rem;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(16, 30, 61, 0.16);
  max-height: 220px;
  overflow-y: auto;
  z-index: 700;
}

.address-suggestion-item {
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--ink);
  border-radius: 0;
  border-bottom: 1px solid #eef2f9;
  padding: 0.55rem 0.65rem;
}

.address-suggestion-item:last-child {
  border-bottom: none;
}

.address-suggestion-item:hover {
  background: #eef4ff;
}

@media (max-width: 760px) {
  .header {
    padding-right: 0;
  }

  .user-banner {
    position: static;
    margin-top: 0.8rem;
    justify-content: space-between;
    border-radius: 10px;
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }

  .show-item {
    flex-direction: column;
  }

  .show-main {
    flex-direction: column;
  }

  .show-poster {
    width: 110px;
    height: 150px;
  }

  .profile-grid {
    grid-template-columns: 1fr;
  }

  .profile-span-2 {
    grid-column: span 1;
  }

  .streaming-grid {
    grid-template-columns: 1fr;
  }

  .show-detail.catalog-detail-popup {
    left: 0.25rem;
    right: 0.25rem;
    top: calc(100% + 0.35rem);
    min-width: 0;
    max-width: none;
  }
}
