/* ==========================================================================
   LASA — Item Detail View Styles
   Covers all classes used in ItemDetail.js
   Uses CSS custom properties defined in main.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Card — generic surface container
   -------------------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4) var(--space-4);
}

@media (min-width: 640px) {
  .card {
    padding: var(--space-5) var(--space-6);
  }
}

/* --------------------------------------------------------------------------
   2. Section container (.item-section used with .card on SectionCard)
   -------------------------------------------------------------------------- */

.item-section {
  margin-bottom: var(--space-5);
}

.item-section__title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  line-height: var(--leading-tight);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

/* --------------------------------------------------------------------------
   3. Item Detail layout elements
   -------------------------------------------------------------------------- */

/* Back-button nav bar above the header card */
.item-detail__nav {
  display: flex;
  align-items: center;
  margin-bottom: var(--space-4);
}

/* Header card (wraps icon + article-id + status badge + meta) */
.item-detail__header {
  margin-bottom: var(--space-5);
}

/* Sticky save bar pinned to bottom of viewport */
.item-detail__save-bar {
  position: sticky;
  bottom: 0;
  z-index: var(--z-raised);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  box-shadow: 0 -2px 8px 0 rgb(0 0 0 / 0.08);
  margin-top: var(--space-6);
}

@media (min-width: 640px) {
  .item-detail__save-bar {
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    padding: var(--space-3) var(--space-6);
  }
}

/* --------------------------------------------------------------------------
   4. Item header layout (icon + ID + badge in a row, meta below)
   -------------------------------------------------------------------------- */

.item-header__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

/* Symbol glyph (cross / star of david) */
.item-header__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  font-size: var(--text-xl);
  background-color: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: var(--radius-md);
  flex-shrink: 0;
  line-height: 1;
}

/* Article ID heading */
.item-header__id {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-text);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  line-height: var(--leading-tight);
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Secondary meta line (cemetery name, fallen name, etc.) */
.item-header__meta {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--color-muted);
}

/* --------------------------------------------------------------------------
   5. Form field containers
   -------------------------------------------------------------------------- */

/* Generic field wrapper (label + input stacked) */
.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.form-field:last-child {
  margin-bottom: 0;
}

/* Read-only variant — label above, plain value below */
.form-field--readonly {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-field--readonly:last-child {
  margin-bottom: 0;
}

/* Label styling within read-only fields — smaller, muted text */
.form-field--readonly .form-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-1);
}

/* Plain-text value rendered for read-only fields */
.form-value {
  font-size: var(--text-base);
  color: var(--color-text);
  padding: var(--space-2) 0;
  min-height: 2rem;
}

/* --------------------------------------------------------------------------
   6. Photo slot indicators (progress dots / circles)
   -------------------------------------------------------------------------- */

/* Container for the row of 4 slot indicators */
.photo-slots {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

/* Individual slot */
.photo-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  flex-shrink: 0;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

/* Slot with photo uploaded */
.photo-slot--filled {
  background-color: var(--color-success-bg);
  color: var(--color-success);
  border: 2px solid var(--color-success);
}

/* Slot still waiting for a photo */
.photo-slot--empty {
  background-color: var(--color-bg);
  color: var(--color-muted);
  border: 2px dashed var(--color-border);
}

/* Check-mark or number inside a slot */
.photo-slot__icon {
  line-height: 1;
  display: inline-block;
}

/* --------------------------------------------------------------------------
   7. Photo progress block (slots + counter)
   -------------------------------------------------------------------------- */

.photo-progress {
  margin-bottom: var(--space-4);
}

.photo-counter {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin: 0;
}

/* --------------------------------------------------------------------------
   8. Photo thumbnail grid
   -------------------------------------------------------------------------- */

.photo-thumbs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

@media (min-width: 480px) {
  .photo-thumbs-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 768px) {
  .photo-thumbs-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Single thumbnail card */
.photo-thumb {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* The actual <img> inside a thumbnail */
.photo-thumb__img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

/* Date caption below the thumbnail image */
.photo-thumb__date {
  font-size: var(--text-xs);
  color: var(--color-muted);
  padding: var(--space-1) var(--space-2) var(--space-2);
  text-align: center;
}

/* --------------------------------------------------------------------------
   9. Photo upload control (label acts as the visible button)
   -------------------------------------------------------------------------- */

.photo-upload {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* The <label> styled as a button (pairs with a hidden <input type=file>) */
.photo-upload__label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  cursor: pointer;
  align-self: flex-start;
}

/* The hidden file input (visually hidden via .sr-only in main.css, but we
   define the class here so the intent is documented) */
.photo-upload__input {
  /* Handled by .sr-only in main.css — this rule exists for specificity safety */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* --------------------------------------------------------------------------
   10. Button semantic variants (extend .btn from main.css)
   -------------------------------------------------------------------------- */

/* btn--success is defined in main.css — no override needed here */

/* Red / error button */
.btn--error {
  background-color: var(--color-error);
  color: #ffffff;
  border-color: var(--color-error);
}

.btn--error:hover:not(:disabled) {
  background-color: #991b1b;
  border-color: #991b1b;
  text-decoration: none;
}

.btn--error:active:not(:disabled) {
  background-color: #7f1d1d;
}

/* Active / selected toggle state (combined with a colour variant) */
.btn--active {
  box-shadow: inset 0 0 0 2px rgb(0 0 0 / 0.15);
  font-weight: var(--font-bold);
}

/* --------------------------------------------------------------------------
   11. Button group (flex row of toggle buttons)
   -------------------------------------------------------------------------- */

.btn-group {
  display: inline-flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   12. Item detail view wrapper
   -------------------------------------------------------------------------- */

.item-detail-view {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-width: var(--max-width-md);
  margin: 0 auto;
  padding-bottom: var(--space-16);  /* room for sticky save-bar */
}

/* --------------------------------------------------------------------------
   13. Unsaved-changes indicator (shown in the save bar when dirty)
   -------------------------------------------------------------------------- */

.unsaved-indicator {
  color: var(--color-warning, #f59e0b);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  align-self: center;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   14. Form content width constraint
   -------------------------------------------------------------------------- */

.form-content {
  max-width: 680px;
}

@media (max-width: 640px) {
  .form-content {
    max-width: 100%;
  }
}

/* Constrain form inputs on item detail to prevent full-width stretch */
.item-detail-view .form-input,
.item-detail-view .form-textarea {
  max-width: 680px;
}

@media (max-width: 640px) {
  .item-detail-view .form-input,
  .item-detail-view .form-textarea {
    max-width: 100%;
  }
}

/* --------------------------------------------------------------------------
   15. Detail view tab bar
   -------------------------------------------------------------------------- */

.detail-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-4);
  overflow-x: auto;
  /* Prevent tab bar itself from shrinking on very small screens */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}

.detail-tabs::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.detail-tab {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color var(--transition-fast), border-bottom-color var(--transition-fast);
  /* Ensure a comfortable tap target on mobile */
  min-height: 2.5rem;
  display: inline-flex;
  align-items: center;
}

.detail-tab:hover:not(.active) {
  color: var(--color-text);
}

.detail-tab:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.detail-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: var(--font-semibold);
}

/* --------------------------------------------------------------------------
   16. Tab panels
   -------------------------------------------------------------------------- */

.tab-panel {
  /* No additional styling needed — the SectionCard/card classes handle it */
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* --------------------------------------------------------------------------
   17. Lightbox overlay
   -------------------------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox__img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  cursor: default;
  border-radius: var(--radius-md);
  /* Override the global img rule so the lightbox image can shrink properly */
  display: block;
}

.lightbox__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  font-size: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
}

.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.lightbox__close:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.lightbox__prev,
.lightbox__next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  font-size: 2rem;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
}

.lightbox__prev:hover,
.lightbox__next:hover {
  background: rgba(255, 255, 255, 0.28);
}

.lightbox__prev:focus-visible,
.lightbox__next:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.lightbox__prev {
  left: 1rem;
}

.lightbox__next {
  right: 1rem;
}

.lightbox__counter {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: #ffffff;
  font-size: var(--text-sm);
  background: rgba(0, 0, 0, 0.5);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* Clickable photo thumbnails — visual affordance */
.photo-thumb[style*="cursor:pointer"]:hover .photo-thumb__img {
  opacity: 0.85;
  transition: opacity var(--transition-fast);
}

/* --------------------------------------------------------------------------
   18. Upload progress bar (shown while XHR upload is in progress)
   -------------------------------------------------------------------------- */

.upload-progress {
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin-top: 0.5rem;
  overflow: hidden;
  width: 100%;
}

.upload-progress__bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  transition: width 0.1s linear;
  min-width: 0;
}

/* --------------------------------------------------------------------------
   19. Photo thumbnail delete button overlay
   -------------------------------------------------------------------------- */

/* Wrapper that positions the ✕ button relative to the thumbnail */
.photo-thumb-wrapper {
  position: relative;
  display: inline-block;
  /* Allow the wrapper to take the full grid-cell width */
  width: 100%;
}

/* ✕ delete button — appears on hover (or always on touch devices) */
.photo-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(220, 38, 38, 0.85);
  color: #ffffff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background-color 0.15s;
  z-index: 2;
  padding: 0;
}

.photo-thumb-wrapper:hover .photo-delete-btn {
  opacity: 1;
}

.photo-delete-btn:hover {
  background: rgba(185, 28, 28, 0.95);
}

.photo-delete-btn:focus-visible {
  opacity: 1;
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

/* Always show on touch / non-hover devices */
@media (hover: none) {
  .photo-delete-btn {
    opacity: 1;
  }
}
