*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0f1117;
  color: #e4e6eb;
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.header {
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.subtitle {
  color: #8b919a;
  margin-top: 0.25rem;
  font-size: 0.95rem;
}

.alerts {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.alert-success {
  background: #132419;
  border-color: #1f4d35;
  color: #6ee7a0;
}

.alert-error {
  background: #2a1418;
  border-color: #5c232e;
  color: #f87171;
}

.actions {
  margin-bottom: 1.5rem;
}

.detect-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mode-select {
  padding: 0.55rem 0.75rem;
  background: #1a1d27;
  border: 1px solid #2a2f3d;
  border-radius: 8px;
  color: #e4e6eb;
  font-size: 0.9rem;
}

.card {
  background: #1a1d27;
  border: 1px solid #2a2f3d;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 1.25rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  align-items: end;
}

.local-m3u-panel {
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  background: #161a24;
  border: 1px solid #2a2f3d;
  border-radius: 10px;
}

.local-m3u-panel h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: #ffffff;
}

.local-m3u-path {
  font-size: 0.85rem;
  color: #8b919a;
  margin-bottom: 0.75rem;
}

.local-m3u-steps {
  margin: 0 0 1rem 1.25rem;
  color: #b8bcc4;
  font-size: 0.9rem;
}

.local-m3u-steps li {
  margin-bottom: 0.35rem;
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: #8b919a;
}

.field label {
  display: block;
  font-size: 0.8rem;
  color: #8b919a;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: #0f1117;
  border: 1px solid #2a2f3d;
  border-radius: 8px;
  color: #e4e6eb;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: #4f6ef7;
}

.field-action {
  display: flex;
  align-items: flex-end;
}

.btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:hover {
  opacity: 0.9;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: #4f6ef7;
  color: #ffffff;
}

.btn-secondary {
  background: #2a2f3d;
  color: #e4e6eb;
  width: 100%;
}

.btn-small {
  background: #2a2f3d;
  color: #c9cdd4;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.btn-small:hover {
  background: #353b4d;
}

.btn-danger {
  background: #3d1f24;
  color: #f87171;
}

.btn-danger:hover {
  background: #5c232e;
}

.btn-link {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  line-height: 1.6;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.row-disabled {
  opacity: 0.55;
}

.badge-enabled {
  background: #132419;
  color: #6ee7a0;
}

.badge-disabled {
  background: #2a2f3d;
  color: #8b919a;
}

.field-action-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.form-single {
  grid-template-columns: 1fr;
  max-width: 480px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.stat-box {
  background: #0f1117;
  border: 1px solid #2a2f3d;
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
}

.stat-label {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  color: #8b919a;
}

.inline-form {
  display: inline;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  color: #8b919a;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #2a2f3d;
}

tbody td {
  padding: 0.75rem;
  border-bottom: 1px solid #22262f;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #22262f;
}

.mono {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.82rem;
  color: #a0a6b0;
}

.empty {
  color: #6b7280;
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-movie {
  background: #1e2a4a;
  color: #7eb3ff;
}

.badge-series {
  background: #2a1e4a;
  color: #c4a0ff;
}

.badge-season {
  background: #1e3a4a;
  color: #5eead4;
}

.badge-episode {
  background: #3a2e1e;
  color: #fbbf24;
}

.badge-live {
  background: #1e3a2a;
  color: #86efac;
}

.copy-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #132419;
  border: 1px solid #1f4d35;
  color: #6ee7a0;
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 1000;
}

.copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.stat-highlight {
  border-color: #4f6ef7;
}

.stat-footer {
  margin-top: 1rem;
  color: #8b919a;
  font-size: 0.85rem;
}

.panel-section {
  border-left: 3px solid #4f6ef7;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.section-head h2 {
  margin-bottom: 0;
}

.section-count {
  background: #0f1117;
  border: 1px solid #2a2f3d;
  color: #c9cdd4;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.media-card {
  display: flex;
  gap: 1rem;
  background: #0f1117;
  border: 1px solid #2a2f3d;
  border-radius: 12px;
  padding: 1rem;
  transition: border-color 0.15s;
}

.media-card:hover {
  border-color: #4f6ef7;
}

.media-card-poster {
  flex-shrink: 0;
  width: 80px;
  height: 120px;
  border-radius: 8px;
  overflow: hidden;
  background: #1a1d27;
}

.poster-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.poster-placeholder {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8b919a;
  background: #151821;
  text-align: center;
  padding: 0.35rem;
}

.media-card-poster.no-poster .poster-placeholder {
  display: flex;
}

.media-card-poster.no-poster .poster-img {
  display: none;
}

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

.media-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.media-date {
  font-size: 0.72rem;
  color: #8b919a;
}

.media-title {
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.media-meta {
  font-size: 0.82rem;
  color: #a0a6b0;
  margin-bottom: 0.2rem;
}

.media-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.channel-blocks {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.channel-block {
  background: #0f1117;
  border: 1px solid #2a2f3d;
  border-radius: 12px;
  padding: 1.25rem;
}

.channel-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.channel-block-head h3 {
  font-size: 1rem;
  color: #ffffff;
}

.channel-group {
  margin-bottom: 1rem;
}

.channel-group h4 {
  font-size: 0.9rem;
  color: #c9cdd4;
  margin-bottom: 0.4rem;
}

.channel-list {
  list-style: none;
  padding-left: 0.5rem;
}

.channel-list li {
  font-size: 0.88rem;
  color: #a0a6b0;
  padding: 0.15rem 0;
}

.provider-form {
  margin-bottom: 0;
}

.copy-source {
  display: none;
}

.poster-debug {
  font-size: 0.68rem;
  color: #f59e0b;
  margin: 0.25rem 0 0.5rem;
  word-break: break-all;
}

.season-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.5rem 0 0.25rem;
}

.season-chip {
  display: inline-block;
  font-size: 0.75rem;
  color: #c9cdd4;
  background: #1a1d27;
  border: 1px solid #2a2f3d;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.episodes-panel {
  margin-top: 0.85rem;
  padding: 0.85rem;
  background: #151821;
  border: 1px solid #2a2f3d;
  border-radius: 10px;
}

.episodes-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.episodes-panel-head strong {
  color: #ffffff;
  font-size: 0.9rem;
}

.btn-episodes-close {
  background: transparent;
  border: none;
  color: #8b919a;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
}

.btn-episodes-close:hover {
  color: #ffffff;
}

.episodes-season-block + .episodes-season-block {
  margin-top: 0.75rem;
}

.episodes-season-title {
  font-size: 0.85rem;
  color: #c9cdd4;
  margin-bottom: 0.35rem;
}

.episodes-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.25rem 0.5rem;
  padding-left: 0.25rem;
}

.episodes-list li {
  font-size: 0.8rem;
  color: #a0a6b0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.badge-series {
  background: #1f2a44;
  color: #93b4ff;
}

.season-chip-updated {
  color: #6ee7a0;
  border-color: #1f4d35;
}

.season-chip-all {
  color: #93b4ff;
  border-color: #1f2a44;
}

/* --- Plan dashboard --- */

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

.plan-card {
  background: #151821;
  border: 1px solid #2a2f3d;
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.plan-card.plan-inactive {
  opacity: 0.72;
}

.plan-card-head {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.plan-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
}

.plan-slug {
  font-size: 0.8rem;
  color: #8b919a;
}

.plan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.badge-m3u {
  background: #132419;
  color: #6ee7a0;
  border: 1px solid #1f4d35;
}

.badge-warning {
  background: #2a2414;
  color: #fbbf24;
  border: 1px solid #5c4a1a;
}

.badge-count {
  background: #1a1d27;
  color: #c9cdd4;
  border: 1px solid #2a2f3d;
}

.plan-stats-mini {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.82rem;
  color: #8b919a;
}

.plan-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: auto;
}

.upload-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.upload-label {
  cursor: pointer;
}

.upload-input {
  display: none;
}

.plan-create-form {
  max-width: 480px;
}

.plan-header .back-link {
  display: inline-block;
  color: #93b4ff;
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.plan-header .back-link:hover {
  text-decoration: underline;
}

.plan-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
}

.plan-tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}

.plan-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  text-decoration: none;
  color: #c9cdd4;
  background: #151821;
  border: 1px solid #2a2f3d;
  font-size: 0.9rem;
  font-weight: 500;
}

.plan-tab:hover {
  color: #ffffff;
  border-color: #3d4558;
}

.plan-tab-active {
  color: #ffffff;
  background: #1f2a44;
  border-color: #3d5a8a;
}

.tab-badge {
  background: #2a2f3d;
  color: #93b4ff;
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.library-hint {
  margin-bottom: 1rem;
}

.library-episodes-grid {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.media-card-compact .media-title {
  font-size: 0.95rem;
}

.stats-compact {
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.5rem;
}

.stats-compact .stat-footer {
  margin: 0;
}

@media (max-width: 600px) {
  .header h1 {
    font-size: 1.5rem;
  }

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

  .media-card {
    flex-direction: column;
  }

  .media-card-poster {
    width: 100%;
    height: 160px;
  }
}
