/* ============================================
   Photo Capture Component Styles
   iOS PWA-First Design
   ============================================ */

/* Photo Capture Container */
.photo-capture-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 
   iOS PWA Camera Fix:
   The wrapper contains both the styled button and the transparent file input.
   The input is overlaid on top so iOS sees a direct tap on the input element.
*/
.photo-capture-wrapper {
    position: relative;
    display: inline-flex;
}

/* The transparent file input overlaid on the button */
.photo-input-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    /* CRITICAL: These ensure iOS can interact with the input */
    -webkit-appearance: none;
    appearance: none;
    /* Ensure it's above the styled button */
    z-index: 2;
    /* iOS-specific: Don't use pointer-events: none or display: none */
    /* The input must be "tappable" for iOS to allow camera access */
}

/* Legacy hidden input class (keep for backwards compatibility) */
.photo-input-hidden {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Camera Capture Button (works as button or label) */
.photo-capture-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--bb-primary, #007AFF);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    /* Make label behave like a button */
    user-select: none;
    -webkit-user-select: none;
    text-align: center;
    /* iOS PWA: Ensure touch events work properly */
    touch-action: manipulation;
    /* Ensure full width in wrapper */
    width: 100%;
}

.photo-capture-btn:active:not(:disabled):not(.disabled) {
    transform: scale(0.98);
    opacity: 0.9;
}

.photo-capture-btn:disabled,
.photo-capture-btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.photo-capture-btn.capturing {
    background: var(--bb-bg-tertiary, #E5E5EA);
    color: var(--bb-text-secondary, #8E8E93);
}

.photo-capture-btn i {
    font-size: 20px;
}

.photo-capture-btn.outline {
    background: transparent;
    border: 2px solid var(--bb-primary, #007AFF);
    color: var(--bb-primary, #007AFF);
}

.photo-capture-btn.small {
    padding: 10px 16px;
    font-size: 14px;
    min-height: 40px;
}

.photo-capture-btn.small i {
    font-size: 16px;
}

/* Photo Preview */
.photo-preview {
    margin-top: 12px;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.photo-preview img {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    display: block;
}

.preview-actions {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bb-bg-secondary, #F2F2F7);
}

[data-bs-theme="dark"] .preview-actions {
    background: var(--bb-bg-secondary, #1c1c1e);
}

.btn-retake,
.btn-use {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    transition: transform 0.15s ease;
}

.btn-retake:active,
.btn-use:active {
    transform: scale(0.98);
}

.btn-retake {
    background: var(--bb-bg-tertiary, #E5E5EA);
    color: var(--bb-text-primary, #000);
}

[data-bs-theme="dark"] .btn-retake {
    background: var(--bb-bg-tertiary, #2c2c2e);
    color: var(--bb-text-primary, #fff);
}

.btn-use {
    background: var(--bb-success, #34C759);
    color: white;
}

/* ============================================
   Photo Grid (Gallery)
   ============================================ */

.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 8px;
}

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

.photo-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bb-bg-tertiary, #E5E5EA);
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}

.photo-thumb:active img {
    transform: scale(1.05);
}

.photo-thumb .delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-size: 14px;
}

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

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

.photo-thumb .delete-btn:active {
    background: var(--bb-danger, #FF3B30);
}

/* ============================================
   Photo Viewer Modal (Full Screen)
   ============================================ */

.photo-viewer-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.photo-viewer-modal img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 4px;
}

.viewer-caption {
    color: white;
    text-align: center;
    padding: 12px 20px;
    font-size: 14px;
    max-width: 90%;
}

.viewer-close {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.viewer-close:active {
    background: rgba(255, 255, 255, 0.4);
}

/* ============================================
   Service Task Photos Section
   ============================================ */

.service-task-photos {
    background: var(--bs-body-bg, white);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

[data-bs-theme="dark"] .service-task-photos {
    background: var(--bb-bg-secondary, #1c1c1e);
}

.photos-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--bb-border-color, #E5E5EA);
}

[data-bs-theme="dark"] .photos-header {
    border-bottom-color: var(--bb-border-color, #38383A);
}

.photos-header h4 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}

.photo-counts {
    font-size: 13px;
    color: var(--bb-text-secondary, #8E8E93);
}

.photo-section {
    margin-bottom: 16px;
}

.photo-section:last-child {
    margin-bottom: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--bb-text-primary, #000);
    display: flex;
    align-items: center;
    gap: 6px;
}

[data-bs-theme="dark"] .section-title {
    color: var(--bb-text-primary, #fff);
}

.section-title i {
    color: var(--bb-primary, #007AFF);
}

/* No Photos State */
.no-photos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    color: var(--bb-text-muted, #8E8E93);
    background: var(--bb-bg-tertiary, #E5E5EA);
    border-radius: 8px;
    margin-top: 8px;
}

[data-bs-theme="dark"] .no-photos {
    background: var(--bb-bg-tertiary, #2c2c2e);
}

.no-photos i {
    font-size: 24px;
    opacity: 0.5;
}

/* ============================================
   Photo Capture Page Styles
   ============================================ */

.photo-capture-page {
    min-height: 100vh;
    background: var(--bb-bg-secondary, #F2F2F7);
}

[data-bs-theme="dark"] .photo-capture-page {
    background: var(--bb-bg-primary, #000);
}

.photo-capture-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bs-body-bg, white);
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--bb-border-color, #E5E5EA);
    display: flex;
    align-items: center;
    gap: 12px;
}

[data-bs-theme="dark"] .photo-capture-header {
    background: var(--bb-bg-secondary, #1c1c1e);
    border-bottom-color: var(--bb-border-color, #38383A);
}

.photo-capture-header .back-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bb-bg-tertiary, #E5E5EA);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: var(--bb-primary, #007AFF);
}

[data-bs-theme="dark"] .photo-capture-header .back-btn {
    background: var(--bb-bg-tertiary, #2c2c2e);
}

.photo-capture-header h1 {
    flex: 1;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.photo-capture-content {
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* Add Photo Button - Large CTA */
.add-photo-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    background: var(--bs-body-bg, white);
    border: 2px dashed var(--bb-border-color, #C7C7CC);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 20px;
}

[data-bs-theme="dark"] .add-photo-cta {
    background: var(--bb-bg-secondary, #1c1c1e);
    border-color: var(--bb-border-color, #38383A);
}

.add-photo-cta:active {
    border-color: var(--bb-primary, #007AFF);
    background: rgba(0, 122, 255, 0.05);
}

.add-photo-cta i {
    font-size: 48px;
    color: var(--bb-primary, #007AFF);
}

.add-photo-cta span {
    font-size: 16px;
    font-weight: 600;
    color: var(--bb-primary, #007AFF);
}

.add-photo-cta .hint {
    font-size: 13px;
    color: var(--bb-text-muted, #8E8E93);
    font-weight: normal;
}

/* Photo List */
.photo-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.photo-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bs-body-bg, white);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] .photo-list-item {
    background: var(--bb-bg-secondary, #1c1c1e);
}

.photo-list-item img {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
}

.photo-list-item .photo-info {
    flex: 1;
}

.photo-list-item .photo-time {
    font-size: 14px;
    font-weight: 500;
}

.photo-list-item .photo-caption {
    font-size: 13px;
    color: var(--bb-text-muted, #8E8E93);
}

.photo-list-item .delete-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 59, 48, 0.1);
    color: var(--bb-danger, #FF3B30);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.photo-list-item .delete-btn:active {
    background: var(--bb-danger, #FF3B30);
    color: white;
}

/* ============================================
   Debug Section (for iOS troubleshooting)
   ============================================ */

.photo-debug-section {
    margin-top: 16px;
    padding: 12px;
    background: var(--bb-bg-tertiary, #E5E5EA);
    border-radius: 8px;
    border: 1px dashed var(--bb-border-color, #C7C7CC);
}

[data-bs-theme="dark"] .photo-debug-section {
    background: var(--bb-bg-tertiary, #2c2c2e);
    border-color: var(--bb-border-color, #38383A);
}

.photo-debug-section .btn {
    font-size: 13px;
}

.photo-debug-section small {
    font-size: 11px;
    font-family: monospace;
}
