/* ============================================
   JP Gestor Documental PDFs — Frontend v5.5.0
   ============================================ */

/* ── Wrapper ── */
.jp-docs-wrap {
  width: 100%;
  font-family: inherit;
  position: relative;
  color: var(--jp-docs-font, inherit);
}

/* ── Search ── */
.jp-docs-search { margin-bottom: 16px; }
.jp-docs-search-input {
  width: 100%;
  max-width: 420px;
  padding: 10px 14px 10px 38px;
  border: 1px solid #d1d5db;
  border-radius: var(--jp-docs-radius, 10px);
  font-size: 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.jp-docs-search-input:focus {
  border-color: var(--jp-docs-btn, #2563eb);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* ── Category filter ── */
.jp-docs-filter {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;
}
.jp-docs-filter-btn {
  border: 1px solid #d1d5db; background: #fff;
  padding: 7px 14px; border-radius: var(--jp-docs-radius, 8px); cursor: pointer;
  font-size: 13px; line-height: 1.2; font-weight: 500;
  color: var(--jp-docs-font, #374151); transition: all .15s;
}
.jp-docs-filter-btn:hover { background: #f9fafb; border-color: #9ca3af; }
.jp-docs-filter-btn.is-active {
  background: var(--jp-docs-btn, #2563eb);
  color: #fff;
  border-color: var(--jp-docs-btn, #2563eb);
}

/* ── Status ── */
.jp-docs-status { font-size: 13px; color: #6b7280; margin-bottom: 12px; }

/* ── Grid ── */
.jp-docs-grid {
  display: grid;
  grid-template-columns: repeat(var(--jp-current-cols, var(--jp-cols, 4)), minmax(0, 1fr));
  gap: 20px; min-height: 120px;
}

/* ── Card ── */
.jp-doc-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 14px;
  padding: 24px 20px 20px; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.03);
  display: flex; flex-direction: column; align-items: center;
  transition: box-shadow .2s, transform .2s;
}
.jp-doc-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); transform: translateY(-2px); }

/* ── PDF Icon ── */
.jp-doc-icon {
  width: 56px; height: 56px; margin: 0 auto 14px;
  background: #fef2f2; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; padding: 10px;
}
.jp-doc-icon svg { width: 100%; height: 100%; }

/* ── Title ── */
.jp-doc-title {
  font-size: 15px; margin: 0 0 6px; font-weight: 700;
  color: var(--jp-docs-font, #111827); line-height: 1.3; word-break: break-word;
}

/* ── Description ── */
.jp-doc-desc { font-size: 13px; margin: 0 0 10px; color: #6b7280; line-height: 1.45; }

/* ── Meta ── */
.jp-doc-meta {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 12px; margin-bottom: 14px; margin-top: auto;
}
.jp-doc-meta-item {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: #9ca3af;
}
.jp-doc-meta-item svg { flex-shrink: 0; }

/* ── Actions ── */
.jp-doc-actions {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; margin-top: auto; width: 100%;
}
.jp-doc-actions .jp-doc-btn {
  width: 100%; max-width: 180px;
}

/* ── Buttons ── */
.jp-doc-btn {
  --_btn-min-h: var(--jp-docs-btn-min-h, 40px);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; min-height: var(--_btn-min-h);
  border-radius: var(--jp-docs-radius, 8px);
  background: var(--jp-docs-btn, #2563eb);
  color: #fff !important; text-decoration: none !important;
  font-weight: 600; font-size: 13px; line-height: 1;
  transition: background .2s, box-shadow .2s, border-color .2s, color .2s;
  border: 1px solid transparent; cursor: pointer;
}
.jp-doc-btn:hover {
  background: var(--jp-docs-btn-hover, color-mix(in srgb, var(--jp-docs-btn, #2563eb) 85%, black));
}
/* Fallback for browsers without color-mix */
@supports not (background: color-mix(in srgb, red, blue)) {
  .jp-doc-btn:hover { filter: brightness(.88); }
}
.jp-doc-btn svg { flex-shrink: 0; }

.jp-doc-btn--secondary {
  background: var(--jp-docs-btn-secondary, #ffffff);
  color: var(--jp-docs-font, #374151) !important;
  border-color: #d1d5db;
}
.jp-doc-btn--secondary:hover {
  background: var(--jp-docs-btn-secondary-hover, #f3f4f6);
  border-color: #9ca3af;
}

.jp-doc-btn.is-disabled {
  background: #e5e7eb; color: #9ca3af !important;
  cursor: not-allowed; border-color: transparent;
}
.jp-doc-btn.is-copied { border-color: #16a34a; color: #16a34a !important; }

/* ── Downloaded state ── */
.jp-doc-card.is-downloaded .jp-doc-btn--download {
  background: #f0fdf4; color: #16a34a !important;
  border-color: #bbf7d0;
}
.jp-doc-card.is-downloaded .jp-doc-btn--download:hover {
  background: #dcfce7;
}

/* ── Empty state ── */
.jp-docs-empty {
  grid-column: 1 / -1; text-align: center;
  padding: 32px 16px; color: #9ca3af; font-size: 14px;
}

/* ── Loading overlay ── */
.jp-docs-loader {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 10; border-radius: 14px;
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
.jp-docs-loader[aria-hidden="false"] { opacity: 1; pointer-events: auto; }
.jp-docs-spinner {
  width: 32px; height: 32px;
  border: 3px solid #e5e7eb; border-top-color: var(--jp-docs-btn, #2563eb);
  border-radius: 50%; animation: jp-spin .6s linear infinite;
}
@keyframes jp-spin { to { transform: rotate(360deg); } }

/* ── Pagination ── */
.jp-docs-pagination {
  display: flex; justify-content: center; align-items: center;
  gap: 4px; margin-top: 24px; flex-wrap: wrap;
}
.jp-docs-page {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 10px;
  border: 1px solid #d1d5db; border-radius: var(--jp-docs-radius, 8px);
  background: #fff; color: var(--jp-docs-font, #374151);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s;
}
.jp-docs-page:hover:not(.is-active):not(.is-disabled):not(.jp-docs-page--dots) {
  background: #f3f4f6; border-color: #9ca3af;
}
.jp-docs-page.is-active {
  background: var(--jp-docs-btn, #2563eb); color: #fff;
  border-color: var(--jp-docs-btn, #2563eb);
}
.jp-docs-page.is-disabled { opacity: .4; cursor: not-allowed; }
.jp-docs-page--dots {
  border: none; background: none; cursor: default;
  min-width: auto; padding: 0 4px; color: #9ca3af;
}
.jp-docs-page--arrow { padding: 0 8px; }
.jp-docs-page--arrow svg { display: block; }

/* ============================================
   PDF.js VIEWER (inside modal)
   ============================================ */
.jp-pdf-viewer { display: flex; flex-direction: column; height: 100%; }

.jp-pdf-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-bottom: 1px solid #eef0f2;
  background: #fbfbfc; flex-shrink: 0;
}
.jp-pdf-btn {
  border: 1px solid #e6e8eb; background: #fff; border-radius: 8px;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; color: #374151;
  transition: background .15s, border-color .15s; padding: 0;
}
.jp-pdf-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
.jp-pdf-page { font-size: 13px; color: #6b7280; white-space: nowrap; }
.jp-pdf-spacer { flex: 1; }

.jp-pdf-canvas-wrap {
  flex: 1; min-height: 0; overflow: auto; background: #f6f7f9;
  display: flex; justify-content: center; align-items: flex-start; padding: 12px;
}
.jp-pdf-canvas-wrap canvas {
  background: #fff; border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
}

/* ============================================
   MODAL
   ============================================ */
.jp-pdf-modal { position: fixed; inset: 0; display: none; z-index: 99999; }
.jp-pdf-modal.is-open { display: flex; align-items: center; justify-content: center; }

.jp-pdf-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }

.jp-pdf-modal__panel {
  position: relative;
  width: min(1000px, 94vw); height: min(85vh, 900px);
  background: #fff; border-radius: 14px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display: flex; flex-direction: column; z-index: 1;
}

.jp-pdf-modal__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid #eef0f2;
  background: #fbfbfc; flex-shrink: 0;
}
.jp-pdf-modal__title {
  font-size: 14px; font-weight: 700; color: #111827;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70%;
}
.jp-pdf-modal__bar-actions { display: flex; align-items: center; gap: 8px; }
.jp-pdf-modal__newtab {
  display: inline-flex; align-items: center;
  color: #6b7280; transition: color .15s;
}
.jp-pdf-modal__newtab:hover { color: #111827; }

.jp-pdf-modal__close {
  appearance: none; border: 0; background: transparent;
  font-size: 26px; line-height: 1; cursor: pointer;
  padding: 2px 6px; color: #6b7280; transition: color .15s;
}
.jp-pdf-modal__close:hover { color: #111827; }

.jp-pdf-modal__body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.jp-pdf-modal__fallback {
  display: none; flex: 1; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 32px; text-align: center; color: #6b7280;
}

html.jp-pdf-modal-open { overflow: hidden; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
  .jp-docs-wrap { --jp-current-cols: var(--jp-cols-tablet, var(--jp-cols, 3)); }
}

@media (max-width: 767px) {
  .jp-docs-wrap { --jp-current-cols: var(--jp-cols-mobile, var(--jp-cols, 2)); }
  .jp-docs-grid { gap: 14px; }
  .jp-doc-card { padding: 18px 14px 16px; }
  .jp-doc-icon { width: 48px; height: 48px; padding: 8px; }
  .jp-doc-title { font-size: 14px; }
  .jp-docs-search-input { max-width: 100%; }
  .jp-pdf-modal__panel { width: 98vw; height: 90vh; border-radius: 10px; }
  .jp-pdf-btn { width: 32px; height: 32px; font-size: 16px; }
}

@media (max-width: 480px) {
  .jp-docs-wrap { --jp-current-cols: var(--jp-cols-phone, var(--jp-cols, 1)); }
  .jp-doc-card {
    flex-direction: row; flex-wrap: wrap; text-align: left;
    gap: 10px; padding: 16px;
  }
  .jp-doc-icon { width: 42px; height: 42px; margin: 0; padding: 7px; flex-shrink: 0; }
  .jp-doc-title { flex: 1; min-width: 0; margin: 0; align-self: center; }
  .jp-doc-desc { width: 100%; margin: 0; }
  .jp-doc-meta { width: 100%; justify-content: flex-start; margin-bottom: 6px; }
  .jp-doc-actions { gap: 8px; }
  .jp-doc-actions .jp-doc-btn { max-width: 100%; font-size: 12px; padding: 8px 10px; min-height: 38px; }
  .jp-pdf-modal__panel { width: 100vw; height: 100vh; border-radius: 0; }
  .jp-pdf-toolbar { padding: 6px 8px; gap: 4px; }
  .jp-pdf-btn { width: 30px; height: 30px; font-size: 15px; border-radius: 6px; }
}


/* Year separators (v4.1) */
.jp-docs-year{margin:18px 0 10px;font-size:1.15em;font-weight:800;}
@media (max-width: 640px){.jp-docs-year{margin:14px 0 8px;}}

/* ============================================
   YEAR GROUP HEADERS
   ============================================ */
.jp-docs-year-group { margin-bottom: 32px; }
.jp-docs-year-group:first-child { margin-top: 0; }
.jp-docs-wrap .jp-docs-grid > .jp-docs-year-group {
  grid-column: 1 / -1;
  width: 100%;
}
.jp-docs-year-header {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 0 0 16px; padding: 8px 18px;
  background: var(--jp-docs-btn, #2563eb); color: #fff;
  font-size: 16px; font-weight: 700;
  border-radius: 8px 8px 0 0;
  border-bottom: 3px solid rgba(0,0,0,.15);
  box-shadow: 0 2px 4px rgba(0,0,0,.06);
}
.jp-docs-wrap .jp-docs-grid-inner {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--jp-current-cols, var(--jp-cols, 4)), minmax(0, 1fr));
  gap: 20px;
}

/* ── Year filter dropdown ── */
.jp-docs-year-filter { margin-bottom: 16px; }
.jp-docs-year-select {
  padding: 8px 14px; border: 1px solid #d1d5db; border-radius: var(--jp-docs-radius, 10px);
  font-size: 14px; background: #fff; cursor: pointer;
  min-width: 180px; outline: none; transition: border-color .2s;
}
.jp-docs-year-select:focus {
  border-color: var(--jp-docs-btn, #2563eb);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

@media (max-width: 1024px) {
  .jp-docs-wrap .jp-docs-grid-inner { grid-template-columns: repeat(var(--jp-current-cols, var(--jp-cols, 3)), minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  .jp-docs-wrap .jp-docs-grid-inner { gap: 14px; }
}
@media (max-width: 480px) {
  .jp-docs-wrap .jp-docs-grid-inner { grid-template-columns: repeat(var(--jp-current-cols, var(--jp-cols, 1)), minmax(0, 1fr)); }
  .jp-docs-year-header { font-size: 14px; padding: 6px 14px; }
  .jp-docs-year-select { width: 100%; }
}

.jp-pdf-modal[aria-busy="true"] .jp-pdf-viewer::before { content: "Cargando PDF…"; padding: 16px; text-align: center; }

/* Keep keyboard and touch controls usable even under theme button resets. */
.jp-docs-wrap :is(button, a, input, select):focus-visible,
.jp-pdf-modal :is(button, a, [tabindex]):focus-visible {
  outline: 3px solid #0a4d8c !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px #fff !important;
}
.jp-doc-actions { flex-wrap: wrap; }
.jp-doc-actions .jp-doc-btn { max-width: 100%; min-height: 44px; }
.jp-docs-search-input { box-sizing: border-box; }
.jp-docs-year-select { box-sizing: border-box; max-width: 100%; }
.jp-docs-year-filter { position: relative; display: inline-block; max-width: 100%; }
.jp-docs-year-filter::after {
  content: ""; position: absolute; right: 16px; top: calc(50% - 5px);
  width: 7px; height: 7px; border-right: 2px solid; border-bottom: 2px solid;
  color: var(--jp-docs-btn, #374151); transform: rotate(45deg); pointer-events: none;
}
.jp-docs-year-select { appearance: none; -webkit-appearance: none; padding-right: 44px; background-image: none; }
@media (max-width: 767px) { .jp-docs-year-filter { display: block; width: 100%; } }
.jp-doc-meta-item { color: #586b7d; }
.jp-docs-search-input::placeholder { color: #586b7d; opacity: 1; }
.jp-pdf-modal__close,
.jp-pdf-modal__newtab {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; border-radius: 6px;
  background: #fff !important; color: var(--jp-pdf-accent, #2563eb) !important;
  border: 1px solid #b8c5d2;
}
.jp-pdf-modal__close:hover,
.jp-pdf-modal__newtab:hover { background: #e3f0fc !important; }
.jp-pdf-btn { min-width: 44px; width: 44px; height: 44px; background: #fff !important; color: #374151 !important; }
.jp-pdf-btn:hover:not(:disabled) { background: #e3f0fc !important; }
.jp-doc-btn.is-copied,
.jp-doc-card.is-downloaded .jp-doc-btn--download { color: #166534 !important; }
.jp-docs-empty { color: #586b7d; }
.jp-pdf-btn:disabled { opacity: .45; cursor: not-allowed; }
.jp-pdf-canvas-wrap { display: block; box-sizing: border-box; }
.jp-pdf-canvas-wrap canvas { display: block; margin: 0 auto; }
.jp-pdf-modal__title { white-space: normal; max-width: none; flex: 1; min-width: 0; line-height: 1.4; }
.jp-pdf-modal__bar { gap: 12px; }
.jp-pdf-modal__bar-actions { flex-shrink: 0; }
@media (max-width: 480px) {
  .jp-pdf-toolbar { gap: 4px; }
  .jp-pdf-modal__panel { height: 100dvh; }
}
@media (prefers-reduced-motion: reduce) {
  .jp-doc-card, .jp-doc-btn, .jp-docs-search-input { transition: none; }
  .jp-doc-card:hover { transform: none; }
  .jp-docs-spinner { animation: none; }
}
