/* ==========================================================================
   DMX Library Downloads — Stylesheet v2.1
   Mobile-first responsive design
   ========================================================================== */

/* ==========================================================================
   Encapsulación total: todos los estilos scoped bajo .dmx-library-widget
   para evitar herencia del tema WordPress (dark mode, colores de inputs, etc.)
   ========================================================================== */

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --dmx-bg:            #ffffff;
  --dmx-border:        #d8d8d8;
  --dmx-border-light:  #eeeeee;
  --dmx-header-bg:     #1a1a1a;
  --dmx-header-color:  #e8e8e8;
  --dmx-row-alt:       #f9f9f9;
  --dmx-accent:        #0073aa;
  --dmx-accent-hover:  #005a87;
  --dmx-accent2:       #00a0d2;
  --dmx-text:          #1a1a1a;
  --dmx-text-muted:    #666666;
  --dmx-radius:        8px;
  --dmx-radius-sm:     4px;
  --dmx-shadow:        0 2px 12px rgba(0, 0, 0, 0.08);
  --dmx-shadow-lg:     0 8px 32px rgba(0, 0, 0, 0.22);
  --dmx-font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Reset de herencia del tema para todo lo que hay dentro del widget */
.dmx-library-widget,
.dmx-library-widget *,
.dmx-library-widget *::before,
.dmx-library-widget *::after {
  box-sizing: border-box;
}

.dmx-library-widget {
  /* Fuerza un contexto de color neutro independiente del tema */
  color: var(--dmx-text) !important;
  background: var(--dmx-bg) !important;
}

/* ── Widget container ──────────────────────────────────────────────────────── */
.dmx-library-widget {
  font-family: var(--dmx-font);
  font-size: 14px;
  color: var(--dmx-text);
  background: var(--dmx-bg);
  border: 1px solid var(--dmx-border);
  border-radius: var(--dmx-radius);
  padding: 20px 16px 16px;
  margin: 16px 0;
  box-shadow: var(--dmx-shadow);
}

/* ── Barra de búsqueda ─────────────────────────────────────────────────────── */
.dmx-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.dmx-search-input {
  flex: 1 1 220px !important;
  min-width: 0 !important;
  padding: 10px 14px !important;
  border: 1px solid var(--dmx-border) !important;
  border-radius: var(--dmx-radius-sm) !important;
  font-family: var(--dmx-font) !important;
  font-size: 14px !important;
  color: var(--dmx-text) !important;
  background-color: #ffffff !important;
  box-shadow: none !important;
  transition: border-color 0.15s, box-shadow 0.15s !important;
  -webkit-appearance: none !important;
}

.dmx-search-input:focus {
  outline: none !important;
  border-color: var(--dmx-accent) !important;
  box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.15) !important;
  background-color: #ffffff !important;
}

.dmx-search-input::placeholder { color: #999 !important; }

.dmx-search-button {
  flex-shrink: 0;
  min-height: 44px;
  padding: 10px 20px;
  background: var(--dmx-accent);
  color: #fff;
  border: none;
  border-radius: var(--dmx-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.dmx-search-button:hover  { background: var(--dmx-accent-hover); }
.dmx-search-button:active { opacity: 0.85; }

/* ── Meta de resultados (contador, estado) ─────────────────────────────────── */
.dmx-results-meta {
  font-size: 12px;
  color: var(--dmx-text-muted);
  margin-bottom: 10px;
  min-height: 18px;
}

/* ── Estado de carga ───────────────────────────────────────────────────────── */
.dmx-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 0;
  color: var(--dmx-text-muted);
  font-size: 13px;
}

.dmx-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--dmx-border);
  border-top-color: var(--dmx-accent);
  border-radius: 50%;
  animation: dmx-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes dmx-spin {
  to { transform: rotate(360deg); }
}

/* ── Tabla — Desktop ≥641px ────────────────────────────────────────────────── */
.dmx-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}

.dmx-table th,
.dmx-table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--dmx-border-light);
}

.dmx-table th {
  background: var(--dmx-header-bg) !important;
  color: var(--dmx-header-color) !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
  white-space: nowrap !important;
}

/* Cancelar cualquier color heredado en links dentro de th */
.dmx-table th a,
.dmx-table th span {
  color: var(--dmx-header-color) !important;
}

.dmx-table th:first-child { border-radius: var(--dmx-radius-sm) 0 0 0; }
.dmx-table th:last-child  { border-radius: 0 var(--dmx-radius-sm) 0 0; }

.dmx-table tbody tr { background: #ffffff !important; }
.dmx-table tbody tr:nth-child(even) { background: var(--dmx-row-alt) !important; }
.dmx-table tbody tr:hover            { background: #edf5fa !important; }

/* Texto de celdas: neutralizar herencia del tema */
.dmx-table td {
  color: var(--dmx-text) !important;
  font-size: 13px !important;
}

/* Columna CH: centrada, ancha fija */
.dmx-table .dmx-col-ch { text-align: center !important; width: 46px !important; color: var(--dmx-text) !important; }

/* Enlace de fixture: color sobrio, no el cyan del tema */
.dmx-fixture-anchor {
  color: var(--dmx-accent) !important;
  text-decoration: none !important;
  font-weight: 500 !important;
}
.dmx-fixture-anchor:hover {
  text-decoration: underline !important;
  color: var(--dmx-accent-hover) !important;
}

/* ── Botón Ver ─────────────────────────────────────────────────────────────── */
.dmx-view-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  min-width: 52px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: #00bcd4;
  color: #fff;
  border: none;
  border-radius: var(--dmx-radius-sm);
  transition: background 0.15s;
  white-space: nowrap;
}

.dmx-view-button:hover { background: #0097a7; }

/* ── Selector de formato ───────────────────────────────────────────────────── */
/* !important necesario para neutralizar temas WP con dark mode o reset agresivo */
.dmx-format-select {
  display: block !important;
  width: 100% !important;
  max-width: 210px !important;
  padding: 7px 30px 7px 10px !important;
  border: 1px solid var(--dmx-border) !important;
  border-radius: var(--dmx-radius-sm) !important;
  /* Fondo blanco explícito + flecha SVG personalizada */
  background-color: #ffffff !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23555555'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 10px center !important;
  background-size: 9px 5px !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  font-family: var(--dmx-font) !important;
  font-size: 12px !important;
  line-height: 1.4 !important;
  color: #333333 !important;
  cursor: pointer !important;
  transition: border-color 0.15s, box-shadow 0.15s !important;
  box-shadow: none !important;
}

.dmx-format-select:focus {
  outline: none !important;
  border-color: var(--dmx-accent) !important;
  box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.12) !important;
}

.dmx-format-select option {
  background-color: #ffffff !important;
  color: #333333 !important;
}

/* ── Botón Descargar ───────────────────────────────────────────────────────── */
.dmx-download-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 5px 12px;
  background: var(--dmx-accent);
  color: #fff;
  border-radius: var(--dmx-radius-sm);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, box-shadow 0.15s;
}

.dmx-download-link:hover {
  background: var(--dmx-accent-hover);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(0, 115, 170, 0.35);
}

/* ── Mensaje vacío ─────────────────────────────────────────────────────────── */
.dmx-empty {
  padding: 32px 0;
  text-align: center;
  color: var(--dmx-text-muted);
  font-size: 14px;
}

/* ── Paginación ────────────────────────────────────────────────────────────── */
.dmx-pagination,
.dmx-ssr-pagination {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  margin-top: 16px !important;
  flex-wrap: wrap !important;
  padding: 0 !important;
  list-style: none !important;
  border: none !important;
  background: transparent !important;
}

/* ── Botones de paginación JS (dmx-page-btn) y SSR (dmx-page-link) ─────────
   Se usan <a> en lugar de <button> para evitar la guerra de especificidad
   con temas WP que inyectan background/color en button con !important.
   ──────────────────────────────────────────────────────────────────────── */
.dmx-page-btn,
.dmx-ssr-pagination .dmx-page-link {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 34px !important;
  min-width: 42px !important;
  padding: 5px 14px !important;
  border: 1px solid var(--dmx-border) !important;
  border-radius: var(--dmx-radius-sm) !important;
  background-color: #ffffff !important;
  color: var(--dmx-accent) !important;
  font-family: var(--dmx-font) !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  text-decoration: none !important;
  cursor: pointer !important;
  box-shadow: none !important;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

.dmx-page-btn:hover,
.dmx-ssr-pagination .dmx-page-link:hover {
  background-color: var(--dmx-accent) !important;
  color: #ffffff !important;
  border-color: var(--dmx-accent) !important;
  text-decoration: none !important;
}

/* Página actual */
.dmx-page-btn--current {
  background-color: var(--dmx-accent) !important;
  color: #ffffff !important;
  border-color: var(--dmx-accent) !important;
  cursor: default !important;
}

.dmx-page-btn--current:hover {
  background-color: var(--dmx-accent-hover) !important;
}

/* Deshabilitado (Prev en página 1, Next en última) */
.dmx-page-btn--disabled {
  background-color: #f5f5f5 !important;
  color: #aaaaaa !important;
  border-color: #e0e0e0 !important;
  cursor: default !important;
  pointer-events: none !important;
  opacity: 0.6 !important;
}

/* Separador "…" */
.dmx-page-ellipsis,
.dmx-ssr-pagination span {
  font-size: 13px !important;
  color: var(--dmx-text-muted) !important;
  padding: 0 4px !important;
  background: transparent !important;
  border: none !important;
  line-height: 34px !important;
  display: inline-block !important;
}

/* ── Modal Visor de fixture ────────────────────────────────────────────────── */
.dmx-viewer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 16px;
  box-sizing: border-box;
}

.dmx-viewer-backdrop.dmx-viewer-visible { display: flex; }

.dmx-viewer-dialog {
  background: #111;
  width: 100%;
  max-width: 960px;
  max-height: 88vh;
  border-radius: var(--dmx-radius);
  box-shadow: var(--dmx-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dmx-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #2a2a2a;
  background: #1a1a1a;
  flex-shrink: 0;
}

.dmx-viewer-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #f0f0f0;
}

.dmx-viewer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: #bbb;
  cursor: pointer;
  border-radius: var(--dmx-radius-sm);
  transition: background 0.15s, color 0.15s;
}

.dmx-viewer-close:hover { background: #333; color: #fff; }

.dmx-viewer-content {
  padding: 16px;
  overflow: auto;
  flex: 1;
}

/* ── Vista de canales del fixture ──────────────────────────────────────────── */
.dmx-fixture-view {
  background: #111;
  color: #f0f0f0;
}

.dmx-fixture-header {
  margin-bottom: 12px;
}

.dmx-fixture-title-main {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.dmx-fixture-title-sub {
  font-size: 12px;
  color: #aaa;
  margin-top: 2px;
}

.dmx-fixture-channels {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 8px;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
}

.dmx-channel {
  flex: 0 0 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 10px;
  scroll-snap-align: start;
}

.dmx-channel-icon { font-size: 14px; margin-bottom: 4px; }

.dmx-channel-slider { flex: 1; display: flex; align-items: stretch; margin: 2px 0; }

.dmx-channel-slider-track {
  position: relative;
  width: 10px;
  border-radius: 4px;
  background: linear-gradient(to top, #1a1a1a, #2a2a2a);
  overflow: hidden;
  height: 90px;
}

.dmx-channel-slider-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--dmx-accent2);
  transition: height 0.3s;
}

.dmx-channel-slider-handle {
  position: absolute;
  left: -4px; right: -4px;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
}

.dmx-channel-label  { margin-top: 4px; font-weight: 700; color: #ccc; }
.dmx-channel-role   { text-align: center; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; max-width: 100%; color: #aaa; }

/* ==========================================================================
   MOBILE — cards (≤640px)
   ========================================================================== */
@media (max-width: 640px) {

  .dmx-library-widget { padding: 14px 12px 12px; }

  /* Ocultar cabecera de la tabla */
  .dmx-table thead { display: none; }

  /* Cada fila = tarjeta */
  .dmx-table,
  .dmx-table tbody { display: block; }

  .dmx-table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "name    view"
      "meta    meta"
      "actions actions";
    border: 1px solid var(--dmx-border);
    border-radius: var(--dmx-radius);
    margin-bottom: 10px;
    padding: 12px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    gap: 4px 8px;
  }

  .dmx-table tbody tr:hover { background: #f5fafd; }

  /* Celda: Nombre */
  .dmx-table td[data-label="Name"] {
    grid-area: name;
    font-weight: 700;
    font-size: 14px;
    padding: 0;
    border: none;
    align-self: center;
  }

  /* Celda: View */
  .dmx-table td[data-label="View"] {
    grid-area: view;
    padding: 0;
    border: none;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
  }

  /* Celda: meta — solo Manufacturer (model y CH ya están en el nombre del fixture) */
  .dmx-table td[data-label="Manufacturer"] {
    grid-area: meta;
    font-size: 12px;
    color: var(--dmx-text-muted) !important;
    padding: 0;
    border: none;
    display: block;
  }

  /* Model y CH ocultos en mobile: su info ya aparece en el título "(16CH)" */
  .dmx-table td[data-label="Model"],
  .dmx-table td[data-label="CH"] {
    display: none !important;
  }

  /* Celda: Format + Download como fila de acciones */
  .dmx-table td[data-label="Format"] {
    grid-area: actions;
    padding: 8px 0 0;
    border: none;
    border-top: 1px solid var(--dmx-border-light);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .dmx-table td[data-label="Download"] {
    display: none; /* El download link se mueve a la celda Format en mobile */
  }

  /* En mobile, el download link se inserta dentro de la celda Format */
  .dmx-format-select { flex: 1 1 140px; max-width: none; }

  .dmx-download-link {
    flex-shrink: 0;
    min-height: 40px;
    padding: 8px 16px;
    font-size: 13px;
  }

  .dmx-view-button {
    min-height: 36px;
    min-width: 64px;
    font-size: 12px;
  }
}

/* ==========================================================================
   TABLET — 641px – 900px
   ========================================================================== */
@media (min-width: 641px) and (max-width: 900px) {

  /* Ocultar columna Manufacturer (visible en tooltip via title) */
  .dmx-table th:nth-child(2),
  .dmx-table td:nth-child(2) { display: none; }

  .dmx-format-select { max-width: 160px; font-size: 11px; }

  .dmx-download-link { padding: 5px 10px; font-size: 11px; }
}

/* ==========================================================================
   DESKTOP — ≥901px — Sticky header
   ========================================================================== */
@media (min-width: 901px) {

  .dmx-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
  }
}
