:root {
  --bg: #0c0d14;
  --bg-soft: #12141f;
  --panel: #161a28;
  --panel-2: #1c2133;
  --border: #262c42;
  --text: #e8eaf3;
  --muted: #8f97b3;
  --accent: #6d5cf6;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(109, 92, 246, 0.14);
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(109, 92, 246, 0.18), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(59, 130, 246, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-2);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 1.45rem;
}
h2 {
  font-size: 1.1rem;
}
h3 {
  font-size: 0.98rem;
}

p {
  margin: 0 0 0.75rem;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 0.84rem;
}
.mono {
  font-family: var(--mono);
  font-size: 0.84rem;
}
.nowrap {
  white-space: nowrap;
}
.center {
  text-align: center;
}

/* ---------------------------------------------------------------- */
/* Arranque                                                          */
/* ---------------------------------------------------------------- */

.boot {
  display: grid;
  place-items: center;
  height: 100vh;
  gap: 14px;
  color: var(--muted);
}
.boot-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.12); opacity: 1; }
}

/* ---------------------------------------------------------------- */
/* Login                                                             */
/* ---------------------------------------------------------------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.auth-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  flex: none;
}
.auth-card h1 {
  font-size: 1.2rem;
}
.auth-card .sub {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 2px 0 0;
}

/* ---------------------------------------------------------------- */
/* Layout                                                            */
/* ---------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: rgba(18, 20, 31, 0.75);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(6px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 6px;
}
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  flex: none;
}
.brand-name {
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 550;
  font-size: 0.92rem;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.nav-item:hover {
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}
.nav-item.active {
  background: var(--accent-soft);
  border-color: rgba(109, 92, 246, 0.35);
  color: #cfc9ff;
}
.nav-item .ico {
  width: 18px;
  text-align: center;
  opacity: 0.9;
}
.nav-badge {
  margin-left: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0 7px;
  font-size: 0.72rem;
  color: var(--muted);
}
.sidebar-footer {
  margin-top: auto;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-footer button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  text-align: left;
  font-family: inherit;
  font-size: 0.82rem;
}
.sidebar-footer button:hover {
  color: var(--text);
}

.main {
  padding: 26px 30px 60px;
  max-width: 1400px;
  width: 100%;
}
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head .sub {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 4px;
}

/* ---------------------------------------------------------------- */
/* Tarjetas y grids                                                  */
/* ---------------------------------------------------------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card + .card {
  margin-top: 16px;
}
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title h2 {
  font-size: 0.98rem;
}
.card-title .hint {
  color: var(--muted);
  font-size: 0.8rem;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
}
.stat .value small {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}
.stat .foot {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.bar {
  height: 8px;
  background: var(--panel-2);
  border-radius: 20px;
  overflow: hidden;
  margin-top: 10px;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ---------------------------------------------------------------- */
/* Formularios                                                       */
/* ---------------------------------------------------------------- */

label.field {
  display: block;
  margin-bottom: 14px;
}
label.field > span {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 550;
}
label.field .help {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 5px;
  display: block;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 92, 246, 0.16);
}
textarea {
  resize: vertical;
  min-height: 80px;
}
select {
  cursor: pointer;
}

.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-wrap input {
  padding-right: 58px;
}
.pw-eye {
  position: absolute;
  right: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  font-size: 0.72rem;
  padding: 4px 8px;
  cursor: pointer;
  font-family: inherit;
}
.pw-eye:hover {
  color: var(--text);
  border-color: var(--accent);
}

.pw-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.pw-meter i {
  display: block;
  flex: 1;
  height: 5px;
  border-radius: 10px;
  background: var(--panel-2);
  position: relative;
  overflow: hidden;
}
.pw-meter i::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 0;
  border-radius: 10px;
  background: var(--red);
  transition: width 0.2s ease, background 0.2s ease;
}
.pw-meter[data-score="1"] i::after { width: 20%; background: var(--red); }
.pw-meter[data-score="2"] i::after { width: 40%; background: var(--amber); }
.pw-meter[data-score="3"] i::after { width: 60%; background: var(--amber); }
.pw-meter[data-score="4"] i::after { width: 80%; background: var(--green); }
.pw-meter[data-score="5"] i::after { width: 100%; background: var(--green); }
.pw-meter b {
  font-weight: 600;
  font-size: 0.76rem;
  color: var(--muted);
  min-width: 78px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.row > * {
  flex: 1 1 200px;
}
.row.tight {
  gap: 8px;
  align-items: center;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 12px;
}
.switch input {
  display: none;
}
.switch .track {
  width: 40px;
  height: 22px;
  border-radius: 20px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
  flex: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s ease, background 0.15s ease;
}
.switch input:checked + .track {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.switch input:checked + .track::after {
  transform: translateX(18px);
  background: var(--accent-2);
}
.switch .label {
  font-size: 0.88rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover {
  filter: brightness(1.12);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.ghost {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--text);
}
.btn.ghost:hover {
  border-color: var(--accent);
}
.btn.danger {
  background: rgba(248, 113, 113, 0.14);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
}
.btn.small {
  padding: 5px 10px;
  font-size: 0.8rem;
  border-radius: 7px;
}
.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- */
/* Tablas                                                            */
/* ---------------------------------------------------------------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 10px 9px;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 10px;
  border-bottom: 1px solid rgba(38, 44, 66, 0.55);
  vertical-align: middle;
}
.table tr:last-child td {
  border-bottom: none;
}
.table tr:hover td {
  background: rgba(28, 33, 51, 0.45);
}
.table-wrap {
  overflow-x: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 20px;
  padding: 2px 9px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.green { color: var(--green); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.1); }
.badge.amber { color: var(--amber); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.1); }
.badge.red { color: var(--red); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.1); }
.badge.blue { color: var(--blue); border-color: rgba(96, 165, 250, 0.35); background: rgba(96, 165, 250, 0.1); }
.badge.purple { color: #c4b5fd; border-color: rgba(139, 92, 246, 0.4); background: rgba(139, 92, 246, 0.12); }

/* ---------------------------------------------------------------- */
/* Videos                                                            */
/* ---------------------------------------------------------------- */

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.video-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.video-thumb {
  aspect-ratio: 16 / 9;
  background: var(--bg-soft) center/cover no-repeat;
  position: relative;
}
.video-thumb .overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px;
  background: linear-gradient(transparent 55%, rgba(0, 0, 0, 0.78));
}
.video-card .body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.video-title {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}
.video-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 6px;
}
.progress {
  height: 5px;
  background: var(--panel-2);
  border-radius: 10px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.4s ease;
}

/* ---------------------------------------------------------------- */
/* Canales                                                           */
/* ---------------------------------------------------------------- */

.group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--panel);
}
.group-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  background: var(--panel-2);
  cursor: pointer;
}
.group-head .name {
  font-weight: 650;
}
.group-head .count {
  color: var(--muted);
  font-size: 0.8rem;
}
.group-body {
  padding: 6px 8px 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 4px;
}
.group.collapsed .group-body {
  display: none;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.channel-item:hover {
  background: var(--panel-2);
}
.channel-item .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-soft) center/cover no-repeat;
  flex: none;
  border: 1px solid var(--border);
}
.channel-item .cname {
  font-size: 0.87rem;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-item .csub {
  font-size: 0.73rem;
  color: var(--muted);
}
.channel-item input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}
.channel-item .spacer {
  flex: 1;
}

/* ---------------------------------------------------------------- */
/* Modal + toasts                                                    */
/* ---------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 12, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
  backdrop-filter: blur(3px);
}
.modal {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.modal h3 {
  margin-bottom: 10px;
}
.modal .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 36px));
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  font-size: 0.87rem;
  animation: slide-in 0.18s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
.toast.warn { border-left-color: var(--amber); }
@keyframes slide-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------------------------------------------------------------- */
/* Utilidades                                                        */
/* ---------------------------------------------------------------- */

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar input,
.toolbar select {
  width: auto;
  min-width: 150px;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 20px;
  padding: 4px 11px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}
.chip:hover { color: var(--text); }
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #cfc9ff;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 42px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(22, 26, 40, 0.4);
}
.log-line {
  display: flex;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(38, 44, 66, 0.5);
  font-size: 0.83rem;
  align-items: baseline;
}
.log-line .ts {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  white-space: nowrap;
}
.log-line .lvl {
  width: 62px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.log-line .lvl.info { color: var(--blue); }
.log-line .lvl.warn { color: var(--amber); }
.log-line .lvl.error { color: var(--red); }
.log-line .msg { flex: 1; }

.code-block {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--mono);
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    gap: 14px;
  }
  .nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .main { padding: 18px 16px 50px; }
}
