/* ================================================================ */
/* RECEIPT UPLOAD (REST) - PAGE-SPECIFIC STYLES                     */
/* Base styles loaded from: _base-receipt-styles.css               */
/* ================================================================ */

/* ================================================================ */
/* CONTAINER CENTERING - OVERRIDE THEME                            */
/* ================================================================ */

.container {
  max-width: 1200px !important;
  margin: auto !important;
}

/* ================================================================ */
/* EDITABLE FIELDS                                                  */
/* ================================================================ */

.user-info {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-field-group {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.user-input {
  width: 100% !important;
  max-width: 100% !important;
}

.editable-field {
  width: 100%;
  border: none;
  border-bottom: 1px solid #f0f0f0;
  padding: 4px 0;
  font-family: 'Jost', sans-serif;
  font-size: 15px;
  color: #666;
  background: transparent;
  transition: border-color 0.2s ease;
}

.editable-field:focus {
  outline: none;
  border-bottom: 1px solid #999;
}

.editable-field:not(:focus) {
  cursor: text;
}

.editable-field::placeholder {
  color: #ccc;
  font-style: italic;
}

.editable-field.invalid {
  border-bottom-color: #e74c3c;
}

select.editable-field {
  cursor: pointer;
}

/* ================================================================ */
/* DELETE BUTTON                                                    */
/* ================================================================ */

.record-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
}

.delete-btn {
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  color: #333;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.delete-btn:hover {
  color: #000;
}

.delete-btn:active {
  color: #666;
}

/* ================================================================ */
/* SUMMARY CARD                                                     */
/* ================================================================ */

.summary-card {
  display: none;
  transition: opacity 0.3s ease;
}

.summary-card.visible {
  display: block;
}

.summary-footer {
  display: flex !important;
}

/* ================================================================ */
/* THUMBNAIL SYSTEM - UNIFIED                                       */
/* ================================================================ */

.thumbnail-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 4px;
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumbnail-actual, 
.thumbnail-placeholder {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center center;
  transition: opacity 0.3s ease;
  opacity: 0;
  background: #fff;
  border-radius: 4px;
}

.thumbnail-actual.loaded {
  opacity: 1;
}

.thumbnail-actual.error {
  opacity: 0.3;
  filter: grayscale(100%);
}

.thumbnail-actual.optimized {
  border: 2px solid #4caf50;
  box-sizing: border-box;
}

.thumbnail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ================================================================ */
/* PDF-SPECIFIC STYLING                                             */
/* ================================================================ */

.thumbnail-container[data-file-type="pdf"] {
  background: #f8f9fa;
  width: 100%;
  height: 100%;
}

.pdf-thumbnail-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 4px;
}

.pdf-thumbnail-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  background: white;
  border: none;
}

.pdf-placeholder {
  font-size: 48px;
  color: #d32f2f;
  background: #ffebee;
}

.pdf-label {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin-top: 8px;
  letter-spacing: 1px;
}

/* ================================================================ */
/* OTHER FILE TYPES                                                 */
/* ================================================================ */

.thumbnail-container[data-file-type="image"] {
  background: #fff;
}

.thumbnail-container[data-file-type="heic"] {
  background: #fff3e0;
}

.heic-placeholder {
  font-size: 36px;
  color: #ff9800;
  background: #fff3e0;
}

.heic-converting {
  font-size: 10px;
  color: #666;
  margin-top: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

.file-type {
  font-size: 10px;
  font-weight: 600;
  color: #666;
  margin-top: 4px;
  letter-spacing: 1px;
}

/* ================================================================ */
/* PROCESSING OVERLAY                                               */
/* ================================================================ */

.thumbnail-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 10;
}

.thumbnail-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.processing-indicator {
  color: white;
  font-size: 12px;
  text-align: center;
  animation: pulse 1.5s ease-in-out infinite;
  padding: 8px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 4px;
}

.error-indicator {
  color: #ff6b6b;
  font-size: 11px;
  text-align: center;
  padding: 8px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 4px;
}

/* ================================================================ */
/* ANIMATIONS                                                       */
/* ================================================================ */

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ================================================================ */
/* RESPONSIVE DESIGN - UPLOAD PAGE SPECIFIC                         */
/* ================================================================ */

/* Mobile Portrait - Enforce 1:1 aspect ratios and proper borders */
@media (max-width: 768px) {
  .record-card {
    width: 100%;
    margin: 0 0 8px 0;
    overflow: visible;
  }
  
  .record-layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr; /* Equal height rows for squares */
    min-height: auto; /* Remove fixed height to let aspect-ratio work */
    aspect-ratio: 1 / 2; /* Container: twice as tall as wide for two stacked squares */
  }
  
  .record-info {
    padding: 20px; /* Simplified padding */
    line-height: 0; /* ADD THIS LINE */
    min-height: auto;
    aspect-ratio: 1 / 1; /* Enforce perfect square */
    position: relative;
    order: 1;
    border-right: none; /* Remove right border for vertical stacking */
    border-bottom: 1px solid #f0f0f0; /* Add bottom border as separator between panels */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    background: white;
  }
  
  .field-group:first-child {
    margin-top: 10px;
  }
  
  .record-thumbnail {
    min-height: auto;
    aspect-ratio: 1 / 1; /* Enforce perfect square */
    order: 2;
    border-left: none; /* Remove left border for vertical stacking */
    border-top: none; /* No top border needed (separator is on record-info bottom) */
    background: #fafafa;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
  }
  
  .summary-footer {
    justify-content: center;
    margin-top: 20px;
  }
  
  .submit-btn {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }
  
}

/* ================================================================ */
/* ENFORCE 1:1 SQUARES FOR ALL HORIZONTAL (SIDE-BY-SIDE) LAYOUTS   */
/* ================================================================ */

/* Mobile Landscape: 569px-768px landscape */
@media (min-width: 569px) and (max-width: 768px) and (orientation: landscape) {
  .record-layout {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-template-rows: 1fr !important;
    aspect-ratio: 2 / 1 !important; /* Container: 2:1 ratio for side-by-side squares */
    min-height: auto !important;
  }
  
  .record-info {
    order: 1 !important;
    aspect-ratio: 1 / 1 !important; /* ENFORCE PERFECT SQUARE */
    padding: 20px 50px 20px 20px !important;
    border-right: 1px solid #f0f0f0 !important;
    border-bottom: none !important;
    background: white !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
  }
  
  .record-thumbnail {
    order: 2 !important;
    min-height: auto !important;
    aspect-ratio: 1 / 1 !important; /* ENFORCE PERFECT SQUARE */
    border-left: 1px solid #f0f0f0 !important;
    background: #fafafa !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
  }
}

/* Desktop: 769px and up - All horizontal layouts */
@media (min-width: 769px) {
  .qr-btn {
    display: block;
  }
  
  .record-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
    aspect-ratio: 2 / 1; /* Container: 2:1 ratio for side-by-side squares */
    min-height: auto; /* Let aspect-ratio control height */
  }
  
  .record-info {
    order: 1;
    aspect-ratio: 1 / 1; /* ENFORCE PERFECT SQUARE */
    line-height: .1; /* ADJUST HEIGHT TO FIT SQUARE */
    padding: 30px;
    background: white;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 18px;
    border-right: 1px solid #f0f0f0;
    position: relative;
  }
  
  .record-thumbnail {
    order: 2;
    aspect-ratio: 1 / 1; /* ENFORCE PERFECT SQUARE */
    background: #fafafa;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-left: 1px solid #f0f0f0;
  }
}

/* Touch Device Optimizations */
@media (max-width: 768px) and (pointer: coarse) and (hover: none) {
  .record-delete {
    position: absolute !important;
    top: 10px !important;
    right: 45px !important;
    z-index: 100 !important;
  }
  
  .delete-btn {
    width: 28px !important;
    height: 28px !important;
    font-size: 28px !important;
    color: #333 !important;
    background: transparent !important;
    border: none !important;
  }
  
  .record-info {
    padding: 20px !important;
    padding-right: 45px !important;
    overflow: visible !important;
  }
  
  .record-card {
    overflow: hidden !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* iOS-specific fixes - Upload page additions */
@supports (-webkit-touch-callout: none) {
  .add-record-btn,
  .qr-btn,
  .summary-card {
    box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);
    -webkit-box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);
  }
  
  .header {
    margin-bottom: 8px;
  }
  
  .record-card {
    margin-bottom: 8px;
  }
  
  .add-record-btn {
    margin-bottom: 8px;
    margin-top: 0;
  }
  
  .qr-btn {
    margin-bottom: 8px;
    margin-top: 0;
  }
  
  .summary-card {
    margin-top: 0;
  }

  .record-card:hover {
    transform: translateY(-2px) scale(1.01);
  }
}

.records-container {
  gap: 8px;
}

/* ================================================================ */
/* REPLACE Label Functionality                                      */
/* ================================================================ */

.file-attachment.replace-mode .file-name {
  color: #666;
  font-weight: 400;
  animation: none;
  transition: all 0.2s ease;
}

.file-attachment.replace-mode .file-name::after {
  content: "REPLACE";
  font-weight: 400;
  color: #666;
}

.file-attachment.replace-mode:hover {
  background: rgba(128, 128, 128, 0.1);
  cursor: pointer;
}

.file-attachment.replace-mode:hover .file-name {
  color: #555;
}

/* Hidden file input for replacement */
.replace-file-input {
  position: absolute;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
}

/* ================================================================ */
/* BLANK PLACEHOLDER PANEL (extends to viewport bottom)            */
/* ================================================================ */

.placeholder-panel {
  background: white;
  border: none;
  border-radius: 0;
  padding: 60px 30px 60px 30px;
  text-align: center;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);
  transition: all .3s ease;
  opacity: 1;
  transform: translateY(0) scale(1);
  
  /* Extend to bottom of viewport */
  min-height: calc(100vh - var(--panel-offset-from-top, 400px));
  position: relative;
}

/* When panel is being removed */
.placeholder-panel.removing {
  opacity: 0;
  transform: translateY(-30px) scale(.9);
  transition: all .3s ease;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .placeholder-panel {
    padding: 40px 20px 40px 20px;
    top: -16px;
  }
  
  .records-container {
    gap: 0px;
    margin-bottom: 10px;
  }
  
  .record-card {
    margin-bottom: 0px;
  }
  
  .add-record-btn {
    margin-bottom: 0px;
    margin-top: 0px;
  }
  
  .qr-btn {
    margin-bottom: 0px;
    margin-top: 0px;
  }
}

/* When QR button is hidden, adjust placeholder position */
@media (max-width: 600px) {
  .placeholder-panel {
    /* Account for hidden QR button - reduce offset by approx button height + margin */
    min-height: calc(100vh - var(--panel-offset-from-top, 400px) + 56px);
  }
}

/* ================================================================ */
/* DRAG AND DROP FUNCTIONALITY                                      */
/* ================================================================ */

/* Base state - indicate droppable area */
.add-record-btn {
  position: relative;
  transition: all 0.2s ease;
}

/* Drag over state - visual feedback when files are dragged over */
.add-record-btn.drag-over {
  background: #f5f5f5 !important;
  border: 2px dashed #666 !important;
  box-shadow: 0 4px 12px rgba(0,0,0,.15), inset 0 0 20px rgba(0,0,0,.03) !important;
  transform: scale(1.02);
}

.add-record-btn.drag-over .add-icon {
  color: #333 !important;
  transform: scale(1.1);
  transition: all 0.2s ease;
}

.add-record-btn.drag-over .select-files {
  color: #333 !important;
}

/* Add drop hint text during drag */
.add-record-btn.drag-over .select-files::after {
  content: " (drop to upload)";
  font-size: 14px;
  color: #666;
}

/* Pulse animation during drag-over for better UX */
@keyframes dragPulse {
  0% { border-color: #666; }
  50% { border-color: #999; }
  100% { border-color: #666; }
}

.add-record-btn.drag-over {
  animation: dragPulse 1s ease-in-out infinite;
}

/* Invalid file type feedback */
.add-record-btn.drag-invalid {
  background: #fff5f5 !important;
  border: 2px dashed #e74c3c !important;
}

.add-record-btn.drag-invalid .select-files::after {
  content: " (invalid file type)";
  font-size: 14px;
  color: #e74c3c;
}

/* Processing state after drop */
.add-record-btn.drop-processing {
  background: #f0f0f0 !important;
  pointer-events: none;
  opacity: 0.7;
}

.add-record-btn.drop-processing .select-files {
  animation: pulse 1s ease-in-out infinite;
}

/* Responsive adjustments for drag-drop */
@media (max-width: 768px) {
  .add-record-btn.drag-over {
    transform: scale(1.01); /* Smaller scale on mobile */
  }
  
  .add-record-btn.drag-over .select-files::after {
    content: "";
    display: none; /* Hide extra text on mobile to save space */
  }
}
