/* Receipt Gallery Styles - Enhanced */
.receipt-gallery-dialog {
  width: min(95vw, 1000px);
  max-width: 1000px;
  max-height: 95vh;
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
}

.receipt-gallery-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.receipt-gallery-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.receipt-gallery-header-actions {
  display: flex;
  gap: 8px;
}

.receipt-gallery-toolbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-muted);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: var(--input-bg);
}

.receipt-gallery-selected-count {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}

.receipt-gallery-bulk-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.receipt-gallery-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-height: 0;
}

.receipt-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

.receipt-gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--input-bg);
  border: 2px solid var(--border-muted);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.receipt-gallery-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(43, 212, 255, 0.2);
  border-color: var(--accent);
}

.receipt-gallery-item.selection-mode {
  cursor: default;
}

.receipt-gallery-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.receipt-gallery-item-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 4px;
}

.receipt-gallery-item.selection-mode .receipt-gallery-item-checkbox {
  opacity: 1;
}

.receipt-gallery-item.selected .receipt-gallery-item-checkbox {
  opacity: 1;
  background: var(--accent);
}

.receipt-gallery-item-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  margin: 0;
  accent-color: var(--accent);
}

.receipt-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.receipt-gallery-item-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  padding: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.receipt-gallery-item:not(.selection-mode):hover .receipt-gallery-item-overlay {
  opacity: 1;
  pointer-events: auto;
}

.receipt-gallery-item.selection-mode .receipt-gallery-item-overlay {
  display: none;
}

.receipt-gallery-item-actions .btn {
  flex: 1;
  padding: 4px 8px;
  font-size: 11px;
}

/* Receipt Viewer Styles - Enhanced */
.receipt-viewer-dialog {
  width: min(95vw, 100vw);
  max-width: 100vw;
  max-height: 100vh;
  height: 100vh;
  padding: 0;
  border: none;
  border-radius: 0;
  background: var(--bg);
  box-shadow: none;
  display: flex;
  flex-direction: column;
  margin: 0;
}

.receipt-viewer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: var(--panel);
}

.receipt-viewer-nav {
  flex: 1;
  text-align: center;
}

.receipt-viewer-counter {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 500;
}

.receipt-viewer-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.receipt-viewer-image-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  cursor: grab;
  touch-action: pan-x pan-y pinch-zoom;
}

.receipt-viewer-image-container:active {
  cursor: grabbing;
}

.receipt-viewer-image-container img {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s ease-out;
  user-select: none;
  -webkit-user-drag: none;
}

.receipt-viewer-actions {
  padding: 16px 20px;
  border-top: 1px solid var(--border-muted);
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
  background: var(--panel);
}

.receipt-viewer-actions .btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 13px;
}

/* Hide old buttons inside chip selectors */
.chip-selector-option .receipt-gallery-btn {
  display: none !important;
}

/* Receipt gallery button in storage selector */
.receipt-gallery-btn.chip-selector-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.receipt-gallery-btn.chip-selector-option:hover {
  background: color-mix(in srgb, var(--input-bg) 90%, var(--accent)) !important;
  border-color: color-mix(in srgb, var(--border-muted) 70%, var(--accent)) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(43, 212, 255, 0.2);
}

.receipt-gallery-btn.chip-selector-option:active {
  transform: translateY(0);
}

/* Loading spinner animation */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.receipt-migration-spinner {
  animation: spin 1s linear infinite;
}

/* Sync badge for synced receipts - cloud icon indicates cloud sync */
.receipt-gallery-sync-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: linear-gradient(135deg, var(--accent) 0%, #00a3cc 100%);
  color: white;
  border-radius: 6px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.receipt-gallery-sync-badge svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.5;
}

/* Expense info dialog */
.receipt-expense-info-dialog {
  width: min(95vw, 500px);
  max-width: 500px;
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Clear receipts dialog */
.clear-receipts-dialog {
  width: min(95vw, 500px);
  max-width: 500px;
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Glowing effect for cloud sync storage box during migration */
#receiptStorageOnline.processing {
  position: relative;
  animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 0 rgba(43, 212, 255, 0);
    border-color: var(--border-muted);
  }
  50% {
    box-shadow: 0 0 20px rgba(43, 212, 255, 0.6), 0 0 40px rgba(43, 212, 255, 0.4);
    border-color: var(--accent);
  }
}

/* Mobile responsive */
@media (max-width: 600px) {
  .receipt-gallery-dialog {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }
  
  .receipt-gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }
  
  .receipt-gallery-item-overlay {
    opacity: 1; /* Always show on mobile */
  }
  
  .receipt-viewer-dialog {
    width: 100vw;
    height: 100vh;
  }
  
  .receipt-viewer-actions {
    padding: 12px;
    gap: 6px;
  }
  
  .receipt-viewer-actions .btn {
    flex: 1;
    min-width: 0;
    padding: 8px;
    font-size: 12px;
  }
  
  .receipt-viewer-actions .btn svg {
    width: 16px;
    height: 16px;
  }
}

/* Safe area support for mobile devices */
@supports (padding: env(safe-area-inset-top)) {
  .receipt-viewer-dialog {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .receipt-viewer-header {
    padding-left: calc(20px + env(safe-area-inset-left, 0px));
    padding-right: calc(20px + env(safe-area-inset-right, 0px));
  }
  
  .receipt-viewer-actions {
    padding-left: calc(20px + env(safe-area-inset-left, 0px));
    padding-right: calc(20px + env(safe-area-inset-right, 0px));
  }
}
