/**
 * SGD Widget — Estilos institucionales UNINCCA
 * Paleta: #040537 (azul noche), #EF7F14 (naranja), blanco
 * Compatible con Elementor, Divi, Avada y cualquier tema WordPress.
 * Prefijo .sgd- para evitar conflictos con el tema activo.
 */

/* ── Variables institucionales ─────────────────────────────────────── */
.sgd-root {
  --sgd-primary:        #040537;
  --sgd-primary-mid:    #0a0b5e;
  --sgd-primary-light:  #e8e8f5;
  --sgd-accent:         #EF7F14;
  --sgd-accent-dark:    #c96a0a;
  --sgd-accent-light:   #fef3e6;
  --sgd-white:          #ffffff;
  --sgd-text:           #040537;
  --sgd-text-muted:     #5a5a7a;
  --sgd-border:         #d8d8e8;
  --sgd-bg:             #f5f5fb;
  --sgd-radius:         10px;
  --sgd-shadow:         0 1px 4px rgba(4,5,55,.08), 0 1px 2px rgba(4,5,55,.05);
  --sgd-shadow-hover:   0 8px 24px rgba(4,5,55,.15);
  --sgd-font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-family: var(--sgd-font);
  color: var(--sgd-text);
  line-height: 1.5;
}

.sgd-root *, .sgd-root *::before, .sgd-root *::after {
  box-sizing: border-box;
}

/* ── Encabezado del widget ─────────────────────────────────────────── */
.sgd-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 3px solid var(--sgd-accent);
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.sgd-title-block {
  flex: 1;
}

.sgd-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--sgd-primary);
  margin: 0 0 4px;
  line-height: 1.3;
}

.sgd-subtitle {
  font-size: 13px;
  color: var(--sgd-text-muted);
  margin: 0;
}

/* ── Controles de búsqueda y filtro ────────────────────────────────── */
.sgd-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.sgd-search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.sgd-search-ico {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--sgd-text-muted);
  pointer-events: none;
}

.sgd-search {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1.5px solid var(--sgd-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--sgd-font);
  color: var(--sgd-text);
  background: var(--sgd-white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.sgd-search:focus {
  border-color: var(--sgd-accent);
  box-shadow: 0 0 0 3px rgba(239,127,20,.15);
}

.sgd-search::placeholder {
  color: #9898b8;
}

.sgd-select {
  padding: 9px 32px 9px 12px;
  border: 1.5px solid var(--sgd-border);
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--sgd-font);
  color: var(--sgd-text);
  background: var(--sgd-white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%235a5a7a'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  min-width: 160px;
  transition: border-color .15s;
  outline: none;
}

.sgd-select:focus {
  border-color: var(--sgd-accent);
  box-shadow: 0 0 0 3px rgba(239,127,20,.15);
}

/* ── Barra de resultados ───────────────────────────────────────────── */
.sgd-results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  min-height: 28px;
}

.sgd-count {
  font-size: 13px;
  color: var(--sgd-text-muted);
  font-weight: 500;
}

.sgd-clear {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border: 1px solid var(--sgd-accent);
  border-radius: 100px;
  background: var(--sgd-white);
  color: var(--sgd-accent-dark);
  font-size: 12px;
  font-family: var(--sgd-font);
  cursor: pointer;
  transition: all .15s;
}

.sgd-clear:hover {
  background: var(--sgd-accent-light);
  color: var(--sgd-accent-dark);
}

/* ── Grid de tarjetas ──────────────────────────────────────────────── */
.sgd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

/* ── Tarjeta de documento ──────────────────────────────────────────── */
.sgd-card {
  background: var(--sgd-white);
  border: 1px solid var(--sgd-border);
  border-top: 3px solid var(--sgd-primary);
  border-radius: var(--sgd-radius);
  box-shadow: var(--sgd-shadow);
  display: flex;
  flex-direction: column;
  transition: transform .2s, box-shadow .2s, border-top-color .2s;
  overflow: hidden;
}

.sgd-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--sgd-shadow-hover);
  border-top-color: var(--sgd-accent);
}

/* Top de la tarjeta */
.sgd-card-top {
  padding: 14px 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sgd-ext-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  flex-shrink: 0;
}

.sgd-ext-icon {
  font-size: 14px;
  line-height: 1;
}

.sgd-ext-label {
  font-size: 10px;
}

.sgd-card-cat {
  font-size: 11px;
  color: var(--sgd-primary);
  background: var(--sgd-primary-light);
  padding: 3px 9px;
  border-radius: 100px;
  border: 1px solid rgba(4,5,55,.15);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  font-weight: 600;
}

/* Cuerpo de la tarjeta */
.sgd-card-body {
  padding: 12px 16px 10px;
  flex: 1;
}

.sgd-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--sgd-primary);
  margin: 0 0 6px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sgd-card-desc {
  font-size: 12px;
  color: var(--sgd-text-muted);
  margin: 0 0 10px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sgd-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sgd-meta-dep,
.sgd-meta-date {
  font-size: 11px;
  color: #9898b8;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ── Acciones de la tarjeta ────────────────────────────────────────── */
.sgd-card-actions {
  padding: 10px 14px 14px;
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--sgd-border);
  background: var(--sgd-bg);
}

.sgd-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--sgd-font);
  text-decoration: none;
  transition: all .18s;
  cursor: pointer;
  border: none;
  flex: 1;
  justify-content: center;
}

/* Ver — acento naranja */
.sgd-btn-view {
  background: var(--sgd-accent);
  color: var(--sgd-white);
}

.sgd-btn-view:hover {
  background: var(--sgd-accent-dark);
  color: var(--sgd-white);
  text-decoration: none;
}

/* Descargar — azul institucional */
.sgd-btn-download {
  background: var(--sgd-primary-light);
  color: var(--sgd-primary);
  border: 1px solid rgba(4,5,55,.15);
}

.sgd-btn-download:hover {
  background: var(--sgd-primary);
  color: var(--sgd-white);
  text-decoration: none;
}

/* ── Estado: cargando ──────────────────────────────────────────────── */
.sgd-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
  color: var(--sgd-text-muted);
  font-size: 14px;
}

.sgd-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--sgd-border);
  border-top-color: var(--sgd-accent);
  border-radius: 50%;
  animation: sgd-spin .7s linear infinite;
}

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

/* ── Estado: vacío ─────────────────────────────────────────────────── */
.sgd-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--sgd-text-muted);
  gap: 8px;
}

.sgd-empty h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--sgd-primary);
  margin: 0;
}

.sgd-empty p {
  font-size: 13px;
  margin: 0;
}

/* ── Estado: error ─────────────────────────────────────────────────── */
.sgd-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  text-align: center;
  gap: 12px;
  color: #8b1a1a;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 4px solid var(--sgd-accent);
  border-radius: var(--sgd-radius);
}

.sgd-error p {
  margin: 0;
  font-size: 14px;
}

/* ── Paginación ────────────────────────────────────────────────────── */
.sgd-pagination {
  margin-top: 28px;
}

.sgd-pagination-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sgd-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1.5px solid var(--sgd-border);
  border-radius: 7px;
  background: var(--sgd-white);
  color: var(--sgd-text-muted);
  font-size: 13px;
  font-family: var(--sgd-font);
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}

.sgd-page-btn:hover:not(:disabled) {
  border-color: var(--sgd-accent);
  color: var(--sgd-accent-dark);
  background: var(--sgd-accent-light);
}

.sgd-page-btn.active {
  background: var(--sgd-primary);
  border-color: var(--sgd-primary);
  color: var(--sgd-white);
  font-weight: 700;
}

.sgd-page-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.sgd-page-dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  color: var(--sgd-text-muted);
  font-size: 13px;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .sgd-controls {
    flex-direction: column;
  }

  .sgd-search-wrap {
    min-width: 100%;
  }

  .sgd-select {
    min-width: 100%;
  }

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

  .sgd-title {
    font-size: 18px;
  }

  .sgd-card-actions {
    flex-direction: column;
  }
}

@media (min-width: 601px) and (max-width: 900px) {
  .sgd-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Integración Elementor ─────────────────────────────────────────── */
.elementor-widget-html .sgd-root *,
.elementor-widget-text-editor .sgd-root * {
  box-sizing: border-box;
}

.elementor-widget-html .sgd-card-title,
.elementor-widget-text-editor .sgd-card-title {
  font-size: 14px !important;
  line-height: 1.4 !important;
}

.sgd-root .sgd-btn,
.sgd-root .sgd-btn:visited {
  display: inline-flex !important;
  text-decoration: none !important;
  border-radius: 7px !important;
  font-weight: 600 !important;
}