/* --- Modal de detall del tiquet (només lectura, amb comentaris) --- */
.ticket-modal {
  position: fixed;
  margin: auto;
  border: none;
  border-radius: 14px;
  padding: 1.75rem;
  width: 90%;
  max-width: 680px;
  box-shadow: 0 24px 64px -12px rgba(22,35,63,0.35);
  font-family: var(--font-ui);
  color: var(--ink);
}
.ticket-modal::backdrop { background: rgba(22,35,63,0.45); }

.ticket-modal input, .ticket-modal textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 0.6rem;
  font-family: var(--font-ui);
  background: var(--card);
  color: var(--ink);
}
.ticket-modal textarea { resize: vertical; }
.ticket-modal input::placeholder, .ticket-modal textarea::placeholder { color: var(--ink-soft); opacity: 1; }
.ticket-modal button {
  background: var(--action);
  color: #fff;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.ticket-modal button:hover { background-color: var(--action-hover); }

/* En escriptori tots els wrappers són transparents al layout: urgència,
   text, botó de tancar i la resta de seccions es comporten exactament
   com abans (tancar és absolut). */
.modal-shell { display: contents; }
.modal-header { display: contents; }
.modal-body { display: contents; }

.modal-close {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: var(--danger); color: #fff; }
.modal-close:active { background: var(--danger-hover); color: #fff; }
.modal-close:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

.modal-urgency { margin-bottom: 0.5rem; }
.modal-urgency .urgency-icon svg { width: 26px; height: 26px; }

.modal-title { font-size: 1.15rem; margin: 0 0 0.2rem; padding-right: 2rem; }
.modal-repo {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-soft);
  border-radius: 5px;
  padding: 0.1rem 0.45rem;
  margin: 0 0.5rem 1.25rem 0;
}

.modal-section { margin: 0 0 1.25rem; }
.modal-section h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin: 0 0 0.4rem;
  font-weight: 700;
}
.modal-description {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}

.modal-screenshots { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.modal-screenshots .modal-screenshot-thumb {
  display: block;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  padding: 0;
  background: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.modal-screenshots .modal-screenshot-thumb:hover { border-color: var(--ink-soft); background: none; }
.modal-screenshots .modal-screenshot-thumb:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.modal-screenshots img { display: block; width: 96px; height: 96px; object-fit: cover; }

.image-lightbox {
  position: fixed;
  margin: auto;
  border: none;
  border-radius: 14px;
  padding: 0;
  max-width: 92vw;
  max-height: 90vh;
  box-shadow: 0 24px 64px -12px rgba(22,35,63,0.35);
  background: var(--card);
}
.image-lightbox::backdrop { background: rgba(22,35,63,0.65); }
.image-lightbox img {
  display: block;
  max-width: 92vw;
  max-height: 90vh;
  object-fit: contain;
}
.image-lightbox .modal-close { background: rgba(22,35,63,0.55); color: #fff; }
.image-lightbox .modal-close:hover { background: var(--danger); }
.image-lightbox-open-new {
  position: absolute;
  top: 0.7rem;
  right: 3.6rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(22,35,63,0.55);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.image-lightbox-open-new:hover { background: rgba(22,35,63,0.8); }
.image-lightbox-open-new:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }

.image-lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(22,35,63,0.35);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}
.image-lightbox-arrow:hover { background: rgba(22,35,63,0.65); opacity: 1; }
.image-lightbox-arrow:focus-visible { outline: 2px solid #fff; outline-offset: -2px; opacity: 1; }
.image-lightbox-prev { left: 0.6rem; }
.image-lightbox-next { right: 0.6rem; }
.image-lightbox-arrow[hidden] { display: none; }

.modal-actions { display: flex; gap: 0.6rem; margin: 0.75rem 0 1rem; }
.modal-actions[hidden] { display: none; }
.modal-github-link {
  display: inline-block;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  background: var(--action);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}
.modal-github-link:hover { background: var(--action-hover); }

.modal-comments { display: flex; flex-direction: column; gap: 0.75rem; max-height: 150px; overflow-y: auto; }
.modal-comments-status { margin: 0; font-size: 0.85rem; color: var(--ink-soft); }
.modal-comment {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}
.modal-comment-head { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.35rem; }
.modal-comment-avatar { width: 20px; height: 20px; border-radius: 50%; }
.modal-comment-author { font-size: 0.82rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.modal-comment-author:hover { text-decoration: underline; }
.modal-comment-date { font-size: 0.75rem; color: var(--ink-soft); margin-left: auto; }
.modal-comment-body { font-size: 0.85rem; color: var(--ink); line-height: 1.45; white-space: pre-wrap; }
.modal-comment-body.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.modal-comment-toggle {
  display: block;
  margin: 0.35rem 0 0;
  padding: 0;
  border: none;
  background: none;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
}
.modal-comment-toggle:hover { color: var(--ink); }

/* --- Modal del comentari sencer --- */
.comment-modal {
  position: fixed;
  margin: auto;
  border: none;
  border-radius: 14px;
  padding: 1.75rem;
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px -12px rgba(22,35,63,0.35);
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--card);
}
.comment-modal::backdrop { background: rgba(22,35,63,0.45); }
.comment-modal-head { display: flex; align-items: center; gap: 0.4rem; margin: 0 1.5rem 0.75rem 0; }
.comment-modal-body {
  font-size: 0.92rem;
  color: var(--ink);
  line-height: 1.55;
  white-space: pre-wrap;
}

.modal-comment-form { margin-top: 0.75rem; }
.modal-comment-form textarea { resize: vertical; min-height: 4.5rem; }
.modal-comment-form button { width: 100%; }
.modal-comment-as { margin: 0 0 0.5rem; font-size: 0.82rem; color: var(--ink-soft); }

.modal-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem 1.5rem;
  margin: 0 0 1.25rem;
}
.modal-meta dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin-bottom: 0.3rem; }
.modal-meta dd { margin: 0; font-size: 0.9rem; color: var(--ink); }
.modal-meta dd a { color: var(--ink); text-decoration: underline; }

.urgency-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem 0.15rem 0.4rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--urgency-color);
  background: color-mix(in srgb, var(--urgency-color) 14%, var(--card));
}
.urgency-badge svg { width: 13px; height: 13px; flex-shrink: 0; }

@media (max-width: 560px) {
  .modal-meta { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .modal-meta { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  /* El <dialog> natiu no toca el seu display (alguns Safari/Chrome mòbils
     gestionen malament el .close() quan es sobreescriu a flex): tota la
     lògica de columna flex i el scroll viuen a .modal-shell, un div
     normal a dins. Així el diàleg mai té scroll propi (les cantonades
     arrodonides es veuen sempre senceres) i .modal-body és l'únic que
     es desplaça. */
  .ticket-modal {
    padding: 0;
    overflow: hidden;
  }
  .modal-shell {
    display: flex;
    flex-direction: column;
    /* dvh (no vh): en mòbil la barra d'adreces del navegador amaga/mostra
       dinàmicament, i 100vh es calcula sobre l'alçada màxima (amb la
       barra amagada), tapant les cantonades quan la barra és visible. */
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow: hidden;
  }
  .modal-header {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    flex-shrink: 0;
    padding: 1rem 2.75rem 1rem 1.75rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
  }
  .modal-body {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 1.25rem 1.75rem 1.75rem;
  }
  .modal-header .modal-urgency { margin-bottom: 0; padding-top: 0.1rem; }
  .modal-header-text { flex: 1; min-width: 0; }
  .modal-header .modal-title { padding-right: 0; }
  .modal-header .modal-repo { margin: 0; }
  /* Torna al mateix patró absolut, provat, que ja funciona a escriptori:
     un botó com a fill directe d'un flex amb overflow:hidden pot no
     rebre bé els tocs en alguns mòbils (Safari/Chrome iOS). */
  .modal-header .modal-close {
    position: absolute;
    top: 0.7rem;
    right: 0.7rem;
    margin: 0;
    touch-action: manipulation;
  }
}
