:root {
  color-scheme: light;
  --accent: #2f5bea;
  --on-accent: #fff;
  --bg: #f5f6f8;
  --surface: #fff;
  --surface-2: #f0f2f5;
  --line: #e2e5ea;
  --line-strong: #cdd2da;
  --text: #171a21;
  --muted: #5f6775;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #92560a;
  --warn-soft: #fdf3dd;
  --ok: #157347;
  --ok-soft: #e4f5ec;
  --accent-text: color-mix(in srgb, var(--accent) 88%, #000);
  --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
  --shadow: 0 1px 2px rgb(20 24 32 / 6%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #20242b;
    --line: #2a2e36;
    --line-strong: #3a3f49;
    --text: #eef0f3;
    --muted: #9aa2af;
    --danger: #f97066;
    --danger-soft: #3a1a18;
    --warn: #f5b94d;
    --warn-soft: #33270f;
    --ok: #4ac98a;
    --ok-soft: #12291e;
    --accent-text: color-mix(in srgb, var(--accent) 55%, #fff);
    --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #20242b;
  --line: #2a2e36;
  --line-strong: #3a3f49;
  --text: #eef0f3;
  --muted: #9aa2af;
  --danger: #f97066;
  --danger-soft: #3a1a18;
  --warn: #f5b94d;
  --warn-soft: #33270f;
  --ok: #4ac98a;
  --ok-soft: #12291e;
  --accent-text: color-mix(in srgb, var(--accent) 55%, #fff);
  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
  --shadow: none;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}

a {
  color: var(--accent-text);
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Marca */
.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.brand-logo {
  display: block;
  max-width: 100%;
  max-height: 44px;
  object-fit: contain;
}

.brand-name {
  font-weight: 650;
  letter-spacing: -0.01em;
}

.solo-oscuro {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .solo-claro {
    display: none;
  }

  :root:not([data-theme="light"]) .solo-oscuro {
    display: block;
  }
}

:root[data-theme="dark"] .solo-claro {
  display: none;
}

:root[data-theme="dark"] .solo-oscuro {
  display: block;
}

/* Páginas de los alumnos */
.pagina {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.page-brand {
  margin-bottom: 18px;
}

.ver-cabecera {
  display: grid;
  gap: 2px;
  margin-bottom: 14px;
}

.ver-cabecera h1 {
  font-size: clamp(1.2rem, 2.4vw, 1.6rem);
}

.ver-cabecera p {
  color: var(--muted);
}

/* El aviso queda detrás del iframe y se retira cuando YouTube ha cargado. */
.ver-marco {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  aspect-ratio: 16 / 9;
  min-height: 200px;
  overflow: hidden;
  border-radius: 14px;
  background: #000;
  box-shadow: 0 10px 30px rgb(0 0 0 / 22%);
}

.ver-marco > * {
  grid-area: 1 / 1;
}

.ver-espera {
  place-self: center;
  padding: 24px;
  color: #c9ced6;
  text-align: center;
}

.ver-video {
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  transition: opacity 0.2s;
}

.ver-listo .ver-video {
  opacity: 1;
}

.ver-listo .ver-espera {
  visibility: hidden;
}

/* Sin JavaScript el vídeo se muestra igual. */
@media (scripting: none) {
  .ver-video {
    opacity: 1;
  }
}

.aviso {
  display: grid;
  gap: 8px;
  justify-items: center;
  max-width: 560px;
  margin: 8vh auto 0;
  padding: 36px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.aviso h1 {
  font-size: 1.35rem;
}

.aviso p {
  color: var(--muted);
}

.pie {
  margin-top: 28px;
  font-size: 0.85rem;
  text-align: center;
}

.pie a {
  color: var(--muted);
}

/* Páginas de la app de iPad: el menú va arriba */
.app-nav {
  margin: 0 0 24px;
}

/* Política de privacidad */
.legal {
  max-width: 760px;
  margin: 0 auto;
  line-height: 1.6;
}

.legal h1 {
  font-size: clamp(1.4rem, 3vw, 1.9rem);
}

.legal h2 {
  margin: 28px 0 8px;
  font-size: 1.15rem;
}

.legal h3 {
  margin: 16px 0 4px;
  font-size: 1rem;
}

.legal p,
.legal ul,
.legal dl {
  margin: 0 0 10px;
}

.legal ul {
  padding-left: 1.25em;
}

.legal li + li {
  margin-top: 6px;
}

.legal a {
  color: var(--accent-text);
  overflow-wrap: anywhere;
}

.legal-sub {
  color: var(--muted);
}

.legal-resumen {
  margin-top: 20px;
  padding: 4px 20px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.legal-datos {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 16px;
}

.legal-datos dt {
  color: var(--muted);
}

.legal-datos dd {
  margin: 0;
}

.legal-pendiente {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
}

@media (max-width: 520px) {
  .legal-datos {
    grid-template-columns: minmax(0, 1fr);
  }

  .legal-datos dd + dt {
    margin-top: 6px;
  }
}

/* Estructura del panel */
.app {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 12px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  min-height: 44px;
  margin-bottom: 20px;
  padding: 0 10px;
}

.sidebar-nav {
  display: grid;
  gap: 2px;
}

.sidebar-foot {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.12s, color 0.12s;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-button {
  width: 100%;
  border: 0;
  background: none;
  cursor: pointer;
}

.nav-count {
  margin-left: auto;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.nav-count.is-strong {
  background: var(--accent);
  color: var(--on-accent);
}

.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: var(--surface-2);
}

.theme-switch button {
  display: grid;
  place-items: center;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.theme-switch button:hover {
  color: var(--text);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 14%);
  color: var(--text);
}

.content {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 32px 32px 56px;
}

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 22px;
}

.view-head p {
  margin-top: 4px;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}

.text-link {
  font-weight: 500;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

/* Avisos */
.toast,
.banner {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  padding: 11px 14px;
  border-radius: 10px;
}

.toast {
  background: var(--ok-soft);
  color: var(--ok);
  font-weight: 500;
}

.toast.is-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.toast.is-static {
  margin: 14px 0 0;
}

.banner {
  background: var(--warn-soft);
  color: var(--warn);
}

/* Bloques */
.card,
.mode-card,
.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card {
  padding: 20px;
}

.card > h2 {
  margin-bottom: 14px;
}

.mode-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 16px;
  padding: 18px 20px;
}

.mode-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--ok-soft);
  color: var(--ok);
}

.mode-card.is-open .mode-icon {
  background: var(--warn-soft);
  color: var(--warn);
}

.mode-text {
  flex: 1 1 260px;
}

.mode-text h2 {
  font-size: 1.1rem;
}

.mode-text p {
  color: var(--muted);
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.stat {
  display: grid;
  padding: 14px 18px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.12s;
}

.stat:hover {
  border-color: var(--line-strong);
}

.stat-value {
  font-size: 1.7rem;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.stat-label {
  color: var(--muted);
  font-size: 0.87rem;
}

/* Formularios */
.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 14px;
}

.help + .field-grid {
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 6px;
  align-content: start;
}

.field label {
  font-size: 0.87rem;
  font-weight: 500;
}

.optional {
  color: var(--muted);
  font-weight: 400;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

input::placeholder {
  color: var(--muted);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card .actions {
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 550;
  cursor: pointer;
  transition: background-color 0.12s, filter 0.12s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent);
  filter: brightness(1.08);
}

.btn-quiet {
  min-height: 34px;
  padding: 0 11px;
}

.btn-danger-quiet {
  color: var(--danger);
}

.btn-danger-quiet:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-block {
  width: 100%;
  margin-top: 16px;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.color-field input {
  width: 46px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.color-field output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Vídeos */
.selection-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgb(15 20 30 / 8%);
}

.check-all {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 500;
  cursor: pointer;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.video-card {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.video-card.is-selectable {
  cursor: pointer;
}

.video-card.is-selectable:hover {
  border-color: var(--line-strong);
}

.video-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.thumb-wrap {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
}

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

.card-check {
  position: absolute;
  top: 9px;
  left: 9px;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 85%);
  border-radius: 4px;
}

.video-card-body {
  display: grid;
  gap: 2px;
  padding: 10px 12px 12px;
}

.video-id {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.9rem;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}

.video-id:hover {
  text-decoration: underline;
}

.video-id .icon {
  width: 13px;
  height: 13px;
}

.meta {
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.meta strong {
  color: var(--text);
}

.search {
  position: relative;
  display: block;
  flex: 0 1 280px;
  min-width: 200px;
}

.search .icon {
  position: absolute;
  top: 11px;
  left: 11px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  padding-left: 36px;
}

.row-list {
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  list-style: none;
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px 10px 10px;
}

.row + .row {
  border-top: 1px solid var(--line);
}

.row-thumb {
  display: block;
  flex: none;
  width: 96px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 7px;
  background: var(--surface-2);
}

.row-main {
  display: grid;
  flex: 1;
  gap: 1px;
  min-width: 0;
}

.row-title {
  overflow: hidden;
  color: var(--text);
  font-weight: 550;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-title:hover {
  color: var(--accent-text);
}

.row form {
  margin: 0;
}

.empty {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 52px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}

.empty .icon {
  width: 26px;
  height: 26px;
  margin-bottom: 6px;
}

.empty h2 {
  color: var(--text);
}

.empty-search {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

/* Ajustes */
.vista > .card + .logo-grid,
.add-form {
  margin-top: 12px;
}

.logo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}

.logo-card > h2 {
  margin-bottom: 2px;
}

.help {
  color: var(--muted);
  font-size: 0.87rem;
}

.logo-preview {
  display: grid;
  place-items: center;
  height: 112px;
  margin: 14px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #808896;
  font-size: 0.87rem;
}

.logo-preview.is-claro {
  background: #fff;
}

.logo-preview.is-oscuro {
  background: #14171c;
}

.logo-preview img {
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}

.file-input {
  width: 100%;
  font-size: 0.87rem;
}

.file-input::file-selector-button {
  margin-right: 10px;
  padding: 6px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

/* Acceso */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}

.login-card {
  width: min(380px, 100%);
  padding: 30px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 34px rgb(15 20 30 / 9%);
}

.login-brand {
  margin-bottom: 22px;
}

.login-card h1 {
  font-size: 1.3rem;
}

.login-card .help {
  margin-top: 4px;
}

.login-card .field {
  margin-top: 18px;
}

/* iPad vertical y móvil */
@media (max-width: 860px) {
  .app {
    display: block;
  }

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    height: auto;
    padding: 12px 16px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-brand {
    min-height: 36px;
    margin: 0;
    padding: 0;
  }

  .brand-logo {
    max-height: 34px;
  }

  .sidebar-foot {
    display: flex;
    align-items: center;
    margin: 0;
  }

  .theme-switch button {
    width: 32px;
  }

  .nav-button {
    width: auto;
  }

  .nav-button span {
    display: none;
  }

  .sidebar-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    gap: 4px;
    margin: 0 -16px;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .sidebar-nav .nav-link {
    flex: none;
    gap: 7px;
    min-height: 36px;
  }

  .content {
    padding: 20px 16px 40px;
  }
}

@media (max-width: 620px) {
  .field-grid,
  .logo-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .stat {
    padding: 12px;
  }

  .stat-value {
    font-size: 1.35rem;
  }

  .search {
    flex: 1 1 100%;
  }

  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .row {
    gap: 10px;
    padding-right: 10px;
  }

  .row-thumb {
    width: 64px;
  }

  .selection-bar .actions {
    width: 100%;
  }

  .selection-bar .btn {
    flex: 1;
    padding: 0 8px;
    font-size: 0.87rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
