/* Reset y Variables */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2563eb;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --bg-color: #f8fafc;
  --sidebar-bg: #1e293b;
  --text-color: #1e293b;
  --border-color: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
}

/* Login Page */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-box {
  background: white;
  border-radius: 8px;
  padding: 40px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-header h1 {
  font-size: 2rem;
  margin-bottom: 10px;
}

.login-header p {
  color: var(--secondary-color);
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-footer {
  text-align: center;
  margin-top: 20px;
  color: var(--secondary-color);
}

/* App Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: white;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 {
  font-size: 1.3rem;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: all 0.3s;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.nav-link span {
  font-size: 1.2rem;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 2rem;
}

/* Search Card - Diseño Moderno */
.channels-search-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  margin-bottom: 16px;
}

.search-main {
  flex: 1;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 16px;
  color: #94a3b8;
  pointer-events: none;
  z-index: 1;
}

.search-input-modern {
  width: 100%;
  padding: 14px 50px 14px 50px;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  outline: none;
  background: white;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.search-input-modern:focus {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.search-input-modern::placeholder {
  color: #94a3b8;
}

.clear-btn-modern {
  position: absolute;
  right: 12px;
  background: #f1f5f9;
  border: none;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
}

.clear-btn-modern:hover {
  background: #e2e8f0;
  color: #ef4444;
  transform: scale(1.1);
}

.search-filter {
  min-width: 220px;
}

.category-filter-select {
  width: 100%;
  padding: 14px 16px;
  font-size: 0.95rem;
  border: none;
  border-radius: 10px;
  outline: none;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  font-weight: 500;
  color: #1e293b;
}

.category-filter-select:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
}

.category-filter-select:focus {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.search-results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.results-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #64748b;
  font-weight: 500;
}

.results-info svg {
  color: #8b5cf6;
}

@media (max-width: 768px) {
  .search-row {
    grid-template-columns: 1fr;
  }
  
  .search-filter {
    min-width: 100%;
  }
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Dashboard */
.dashboard-container {
  max-width: 1400px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  padding: 25px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 20px;
}

.stat-icon {
  font-size: 3rem;
}

.stat-info h3 {
  font-size: 2rem;
  margin-bottom: 5px;
}

.stat-info p {
  color: var(--secondary-color);
}

.dashboard-section {
  margin-top: 30px;
}

.dashboard-section h2 {
  margin-bottom: 20px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.info-card {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.info-card h3 {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-color);
}

/* Forms */
.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 1rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s;
  text-decoration: none;
  display: inline-block;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-info {
  background: #0ea5e9;
  color: white;
}

.btn-info:hover {
  background: #0284c7;
}

.btn-warning {
  background: #f59e0b;
  color: white;
}

.btn-warning:hover {
  background: #d97706;
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

/* Table */
.table-container {
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background: var(--sidebar-bg);
  color: white;
}

.data-table th,
.data-table td {
  padding: 12px;
  text-align: left;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr:hover {
  background: var(--bg-color);
}

.text-center {
  text-align: center !important;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-secondary {
  background: #e2e8f0;
  color: #475569;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
}

.modal.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: white;
  border-radius: 8px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-large {
  max-width: 750px;
}

.modal-extra-large {
  max-width: 96vw;
  width: 96vw;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 1.5rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--secondary-color);
}

.modal form {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Modal Form Layout - Two Columns */
.modal-form-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-bottom: 20px;
}

.modal-form-column {
  display: flex;
  flex-direction: column;
}

/* Categories Selection */
.categories-section {
  padding: 20px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.categories-section h3 {
  margin: 0 0 10px 0;
  font-size: 1.1rem;
  color: #1e293b;
}

.categories-actions {
  display: flex;
  gap: 10px;
  margin: 10px 0 15px 0;
}

.categories-actions .btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  flex: 1;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  overflow-y: auto;
  max-height: 450px;
  padding-right: 10px;
}

.categories-grid::-webkit-scrollbar {
  width: 6px;
}

.categories-grid::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.categories-grid::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.categories-grid::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.category-checkbox {
  display: flex;
  align-items: center;
  padding: 10px;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.category-checkbox:hover {
  border-color: var(--primary-color);
  background: #f8fafc;
}

.category-checkbox input[type="checkbox"] {
  margin-right: 10px;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.category-checkbox label {
  cursor: pointer;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
}

.category-checkbox input[type="checkbox"]:checked + label {
  color: var(--primary-color);
}

/* Error Messages */
.error-message {
  background: #fee2e2;
  color: #991b1b;
  padding: 10px;
  border-radius: 4px;
  margin-bottom: 15px;
}

.success-message {
  background: #d1fae5;
  color: #065f46;
  padding: 10px;
  border-radius: 4px;
  margin-bottom: 15px;
}

/* Channel Logo */
.channel-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 4px;
}

/* Playlist Modal Styles */
.playlist-user-info {
  background: var(--bg-color);
  padding: 15px;
  border-radius: 4px;
  margin-bottom: 20px;
}

.playlist-user-info p {
  margin: 5px 0;
}

.playlist-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-color);
}

.playlist-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--secondary-color);
  font-weight: 500;
  transition: all 0.3s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.playlist-tab:hover {
  color: var(--primary-color);
}

.playlist-tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.playlist-urls {
  margin-bottom: 20px;
}

.url-box {
  margin-bottom: 15px;
}

.url-box label {
  display: block;
  margin-bottom: 8px;
}

.url-input-group {
  display: flex;
  gap: 10px;
}

.url-input-group input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  background: var(--bg-color);
}

.playlist-preview {
  margin-top: 20px;
}

.playlist-preview label {
  display: block;
  margin-bottom: 8px;
}

/* Actions */
.actions {
  display: flex;
  gap: 5px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 300px;
  padding: 15px 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideIn 0.3s ease-out;
  border-left: 4px solid var(--primary-color);
}

.toast.success {
  border-left-color: var(--success-color);
}

.toast.error {
  border-left-color: var(--danger-color);
}

.toast.warning {
  border-left-color: var(--warning-color);
}

.toast-icon {
  font-size: 1.5rem;
}

.toast-content {
  flex: 1;
}

.toast-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--secondary-color);
  padding: 0;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* Confirm Dialog */
.confirm-dialog {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

.confirm-dialog.active {
  display: flex;
}

.confirm-box {
  background: white;
  border-radius: 8px;
  padding: 30px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.confirm-icon {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 20px;
}

.confirm-title {
  font-size: 1.3rem;
  text-align: center;
  margin-bottom: 15px;
  color: var(--text-color);
}

.confirm-message {
  text-align: center;
  color: var(--secondary-color);
  margin-bottom: 25px;
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-actions .btn {
  min-width: 100px;
}

/* Responsive */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .data-table {
    font-size: 0.875rem;
  }

  .data-table th,
  .data-table td {
    padding: 8px;
  }
}

/* Estilos para estados de expiración de usuarios */
.data-table tr.expired {
  background-color: #fee;
}

.data-table tr.critical {
  background-color: #fef3cd;
}

.data-table tr.warning {
  background-color: #fff3cd;
}

.data-table tr.soon {
  background-color: #d1ecf1;
}

.data-table tr.expired:hover,
.data-table tr.critical:hover,
.data-table tr.warning:hover,
.data-table tr.soon:hover {
  opacity: 0.9;
}

/* ── Selector tipo de usuario ───────────────────────────────── */
.user-type-selector {
  display: flex;
  gap: 12px;
}
.user-type-option {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all .2s;
  flex: 1;
  justify-content: center;
}
.user-type-option:has(input:checked) {
  border-color: #6366f1;
  background: #eef2ff;
  color: #4f46e5;
}
.user-type-option input[type="radio"] {
  display: none;
}

/* ── Tabs Xtream ────────────────────────────────────────────── */
.xtream-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.xtream-tab {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid #e2e8f0;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: #f1f5f9;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  transition: all .15s;
}
.xtream-tab.active {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}
.xtream-cat-panel {
  border: 1px solid #e2e8f0;
  border-radius: 0 4px 8px 8px;
  min-height: 200px;
  max-height: 380px;
  overflow-y: auto;
  padding: 4px 0;
}

/* Lista de categorías Xtream (formato fila) */
.xtream-cat-list {
  display: flex;
  flex-direction: column;
}
.xtream-cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background .12s;
  font-size: 0.88rem;
  color: #1e293b;
}
.xtream-cat-row:last-child { border-bottom: none; }
.xtream-cat-row:hover { background: #f0f4ff; }
.xtream-cat-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ── Drag & Drop categorías LIVE ───────────────────────────── */
.live-drag-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 4px;
  border-bottom: 1px solid #f1f5f9;
  transition: background .12s;
  user-select: none;
}
.live-drag-row:last-child { border-bottom: none; }
.live-drag-row:hover { background: #f0f4ff; }
.live-drag-row.live-dragging { opacity: 0.4; background: #e0e7ff; }
.live-drag-row.live-drag-over { background: #dbeafe; border-top: 2px solid #3b82f6; }
.drag-handle {
  cursor: grab;
  color: #94a3b8;
  font-size: 1.1rem;
  flex-shrink: 0;
  padding: 0 2px;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.xtream-cat-row-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  cursor: pointer;
  font-size: 0.88rem;
  color: #1e293b;
}
.xtream-cat-row-inner input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ── Badge Xtream en tabla ──────────────────────────────────── */
.badge-xtream {
  background: #7c3aed;
  color: #fff;
}

/* ── Código de activación ───────────────────────────────────── */
.xtream-code-box {
  display: inline-block;
  background: #1e1b4b;
  color: #a5b4fc;
  font-family: monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  title: "Click para copiar";
}

