/* ============================================================
   VARIABLES
   ============================================================ */
:root{
  --light-blue-color: #007BC4;
  --dark-blue-color: #002B4A;
  --text-button-color: #FFFFFF;
  --text-color: #002B4A;
}

/* ============================================================
   RESETEO E BASE
   ============================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  padding: 0;
  margin: 0;
}

p { margin-bottom: 14px; }

#total {
  margin-top: 20px;
  margin-bottom: 20px;
}

/* ============================================================
   BANDA SUPERIOR
   ============================================================ */
.banda {
  height: 60px;
  background-color: var(--dark-blue-color);
  background-image: url("crg-logo.png");
  background-position: 10px center;
  background-repeat: no-repeat;
  background-size: contain;
  margin-bottom: 20px;
}

/* ============================================================
   CABECEIRA DO CATÁLOGO
   ============================================================ */
.catalog-header {
  text-align: center;
  color: var(--dark-blue-color);
}

/* ============================================================
   CONTEDOR DE TARXETAS
   ============================================================ */
.container {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  ___grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 30px;
  padding: 10px 40px;
}

/* ============================================================
   TARXETAS
   ============================================================ */
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card-header {
  background: var(--light-blue-color);
  padding: 15px 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--text-button-color);
}

.nivel {
  border-right: 2px solid #fff;
  padding: 4px 20px;
  font-size: 1.2em;
}

.materia {
  padding: 4px 20px;
  font-size: 1.2em;
}

.card-body {
  padding: 25px 20px;
}

.card-title {
  font-size: 1.8rem;
  color: #2d3748;
  margin-bottom: 20px;
  line-height: 1.4;
}

.card-content {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.card-image { flex-shrink: 0; }

.card-image img {
  margin-top: 10px;
  width: 320px;
  height: 220px;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.card-description {
  flex: 1;
  color: var(--text-color);
}

.card-description p {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 0;   /* antes herdaba o margin global */
}

.card-footer {
  padding: 20px;
  background: #f7fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 15px;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

.btn-primary {
  background: #fff;
  color: var(--text-color);
}

.btn-secondary {
  background: #fff;
  color: var(--text-color);
}

/* ============================================================
   BUSCADOR
   ============================================================ */
.search-container {
  max-width: 1400px;
  margin: 40px auto 30px auto;
  padding: 0 20px;
}

.search-box {
  position: relative;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
}

.search-input {
  flex: 1;
  padding: 6px 50px 6px 20px;
  font-size: 1rem;
  border: 1px solid var(--light-blue-color);
  border-radius: 6px;
  outline: none;
  transition: box-shadow 0.3s ease;
}

.search-input:focus {
  box-shadow: 0 0 0 3px rgba(0, 123, 196, .2);
}

.search-button {
  padding: 15px 25px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  background: var(--light-blue-color);
  color: #fff;
}

.search-button:hover {
  background: var(--dark-blue-color);
}

.reset-button {
  background: #fff;
  color: var(--light-blue-color);
  border: 2px solid var(--light-blue-color);
}

.reset-button:hover {
  background: var(--light-blue-color);
  color: #fff;
}

/* ============================================================
   FILTROS (etiquetas)
   ============================================================ */
#filtrosContainer {
  max-width: 1200px;
  margin: 0 auto 1rem;
  background: #fff;
  padding: 1rem 1.5rem;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.filtros-wrapper {
  display: flex;
  flex-direction: column;
  gap: .8rem;
}

.grupo-filtros {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
}

.etiqueta-grupo {
  font-weight: 700;
  font-size: .8rem;
  color: #555;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-right: .3rem;
  min-width: 70px;
}

.tag {
  padding: .35rem .8rem;
  border: 2px solid var(--light-blue-color);
  background: #fff;
  color: #222;
  border-radius: 999px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  transition: all .15s ease;
}

.tag:hover {
  background: #eaf3fc;
  transform: translateY(-1px);
}

.tag.activo {
  background: var(--light-blue-color);
  color: #fff;
}

/* ============================================================
   ESTADOS
   ============================================================ */
.invisible { display: none !important; }

.no-results {
  text-align: center;
  padding: 40px;
  font-size: 1.2rem;
  color: #555;
  display: none;
}

.no-results.show { display: block; }

/* ============================================================
   INDICADOR DE CARGA
   ============================================================ */
.loading-container {
  text-align: center;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  margin: 20px 0;
}

.spinner {
  border: 4px solid #e0e0e0;
  border-top: 4px solid var(--light-blue-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.progress-bar {
  width: 100%;
  max-width: 400px;
  height: 12px;
  background: #e0e0e0;
  border-radius: 6px;
  margin: 20px auto;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--light-blue-color), var(--dark-blue-color));
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 6px;
}

.loading-container .info       { font-size: 14px; color: #666;  margin: 10px 0; }
.loading-container .info-small { font-size: 12px; color: #999;  margin: 10px 0; }
.loading-container .success    { color: #28a745; font-weight: bold; }
.loading-container .error      { color: #dc3545; font-weight: bold; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .card-content {
    flex-direction: column;
    align-items: center;
    text-align: left;
  }

  .card-footer { flex-direction: column; }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .search-box { flex-direction: column; }

  .search-button { width: 100%; }
}

/* ============================================================
   IMPRESIÓN
   ============================================================ */
@media print {

  @page {
    size: A4;
    margin: 1.5cm;
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10pt;
    line-height: 1.35;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ---------- Ocultamos o que non vai en papel ---------- */
  .banda,
  #loadingIndicator,
  #filtrosContainer,
  #searchContainer,
  .no-results,
  .search-container,
  .search-box,
  .search-input,
  .search-button {
    display: none !important;
  }

  /* ---------- Cabeceira ---------- */
  .catalog-header {
    text-align: center;
    margin-bottom: .4cm;
    padding-bottom: .2cm;
    border-bottom: 2px solid #000000;
  }
  .catalog-header h1 { font-size: 15pt; margin: 0 0 .15cm 0; color: #000 !important; }
  .catalog-header h2 { font-size: 12pt; margin: 0 0 .1cm 0;  color: #000 !important; }
  .catalog-header h3#total {
    font-size: 9pt; font-weight: normal; color: #444 !important; margin: 0;
  }

  /* ---------- Contedor ---------- */
  .container,
  #cardsContainer {
    display: block !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* ---------- Tarxetas ---------- */
  .card {
    width: 100% !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
    break-inside: avoid;
    page-break-inside: avoid;

    box-shadow: none !important;
    border: none;
    border-radius: 0;
    padding: .3cm 0;
    margin: 0;
    background: #fff !important;
    color: #000 !important;

    /* Liña separadora entre tarxetas */
    border-bottom: 1px solid #222222;
  }

  .card:last-child,
  .card:last-of-type {
    border-bottom: none;
  }

  /* ---------- Cabeceira da tarxeta ---------- */
  .card-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ccc;
    padding: 0 0 .12cm 0;
    margin-bottom: .15cm;
    background: none !important;
    color: #000 !important;
  }
  .card-header .nivel,
  .card-header .materia {
    font-size: 9pt;
    font-weight: bold;
    color: #000 !important;
    margin: 0;
    border: none !important;
    padding: 0 !important;
  }

  /* ---------- Título ---------- */
  .card-title {
    font-size: 11pt;
    font-weight: bold;
    margin: 0 0 .15cm 0;
    color: #000 !important;
  }

  /* ---------- Contido ---------- */
  .card-content { display: block !important; }

  .card-image {
    float: left;
    width: 2.4cm;
    height: auto;
    margin: 0 .25cm .15cm 0;
  }
  .card-image img {
    width: 100%;
    height: auto;
    border: 1px solid #ccc;
    border-radius: 3px;
    box-shadow: none !important;
  }

  .card-description {
    font-size: 9pt;
    color: #222 !important;
    text-align: justify;
  }
  .card-description p {
    font-size: 9pt;
    line-height: 1.25;
    margin: 0;
    text-align: justify;
  }

  .card::after {
    content: "";
    display: block;
    clear: both;
  }

  /* ============================================================
     ENLACES ACTIVOS NO PDF
     ============================================================
     Non ocultamos o footer. En vez diso, o convertemos nunha
     liña discreta de texto con dous enlaces activos.
     ============================================================ */

  .card-footer {
    display: block !important;
    background: none !important;
    border-top: none !important;
    padding: .12cm 0 0 0 !important;
    margin: 0 !important;
    text-align: left !important;
    gap: 0 !important;
  }

  .card-footer .btn {
    display: block !important;
    background: none !important;
    color: #222222 !important;         
    padding: 0 !important;
    margin: 0 .4cm 0 0 !important;
    border: none !important;
    border-radius: 0 !important;
    font-size: 8.5pt !important;
    font-weight: normal !important;
    text-decoration: underline !important;
    box-shadow: none !important;
    width: auto !important;
  }



  /* A URL longa non se amosa, pero queda activa no PDF */

  a {
    color: #222222 !important;
    text-decoration: none !important;
  }
}
