/**
 * BRT Camera Viewer - Snowman v3
 * Modern, minimal styling matching BRT Tools aesthetic
 */

/* ============================================
   Reset & Base
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: transparent;
    color: #333;
    line-height: 1.4;
}

/* ============================================
   Camera Viewer Container
   ============================================ */
.camera-viewer {
    width: 100%;
    max-width: 100%;
    background: #f8f9fa;
}

/* Size-specific max widths */
.camera-viewer[data-size="thumb"] {
    max-width: 300px;
}

.camera-viewer[data-size="medium"] {
    max-width: 640px;
}

.camera-viewer[data-size="large"],
.camera-viewer[data-size="full"] {
    max-width: 1280px;
}

/* ============================================
   Camera Container & Image
   ============================================ */
.camera-container {
    position: relative;
    width: 100%;
    background: #1a1a1a;
}

.camera-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
}

.camera-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* ============================================
   Loading State
   ============================================ */
.camera-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #1a1a1a;
    color: #888;
    font-size: 14px;
}

.camera-loading[hidden] {
    display: none;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #333;
    border-top-color: #48bb78;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Offline State
   ============================================ */
.camera-offline {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(26, 26, 26, 0.9);
    color: #dc3545;
    font-size: 16px;
    font-weight: 500;
}

.camera-offline[hidden] {
    display: none;
}

.offline-icon {
    font-size: 32px;
    opacity: 0.8;
}

/* ============================================
   Custom Offline Content (Off Air Mode)
   ============================================ */
.offline-content {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    z-index: 3;
}

.offline-content[hidden] {
    display: none;
}

.offline-content .offline-image {
    width: 100%;
    height: 100%;
    object-fit: cover;  /* Center crop to fill 16:9 area */
}

.offline-content .offline-text-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px 16px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    color: #fff;
    font-size: clamp(18px, 4vw, 32px);
    font-weight: 600;
    text-align: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    line-height: 1.3;
}

/* When only text is shown (no image) */
.offline-content:not(:has(.offline-image)) {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
}

.offline-content:not(:has(.offline-image)) .offline-text-overlay {
    position: static;
    background: none;
    padding: 40px 24px;
    font-size: clamp(20px, 5vw, 36px);
}

/* ============================================
   Refresh Indicator (Green Flash)
   ============================================ */
.refresh-indicator {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: transparent;
    pointer-events: none;
    z-index: 10;
}

.refresh-indicator.flash {
    background: #48bb78;
    box-shadow: 0 0 12px 4px #48bb78;
    animation: pulse 0.6s ease-out;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.8);
        opacity: 0.8;
    }
    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* ============================================
   Countdown Overlay (on image)
   ============================================ */
.countdown-overlay {
    position: absolute;
    bottom: 8px;
    left: 8px;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    pointer-events: none;
    z-index: 5;
}

.countdown-overlay[hidden] {
    display: none;
}

/* ============================================
   Controls Bar (Below Image)
   ============================================ */
.camera-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    min-height: 44px;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls-left {
    flex: 1;
    min-width: 0;
}

/* Time Display */
.camera-time {
    font-size: 13px;
    font-weight: 500;
    color: #495057;
    white-space: nowrap;
}

/* Countdown */
.camera-countdown {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
}

/* ============================================
   Control Buttons
   ============================================ */
.control-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #495057;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 32px;
    min-width: 32px;
    justify-content: center;
}

.control-btn:hover {
    background: #e9ecef;
    border-color: #ced4da;
    color: #212529;
}

.control-btn:active {
    background: #dee2e6;
    transform: translateY(1px);
}

.control-btn svg {
    flex-shrink: 0;
}

.control-btn[hidden] {
    display: none;
}

/* Expand button - primary action, green accent */
#btn-expand {
    background: linear-gradient(to bottom, #48bb78, #38a169);
    border-color: #2f855a;
    color: #fff;
}

#btn-expand:hover {
    background: linear-gradient(to bottom, #38a169, #2f855a);
    border-color: #276749;
    color: #fff;
}

#btn-expand:active {
    background: #2f855a;
}

/* Save button - subtle blue accent */
#btn-save {
    background: linear-gradient(to bottom, #fff, #f0f7ff);
    border-color: #90cdf4;
    color: #2b6cb0;
}

#btn-save:hover {
    background: linear-gradient(to bottom, #ebf8ff, #bee3f8);
    border-color: #63b3ed;
    color: #2c5282;
}

#btn-save:active {
    background: #bee3f8;
}

/* Hide button - neutral gray */
#btn-hide-overlay {
    background: linear-gradient(to bottom, #fff, #f7fafc);
    border-color: #cbd5e0;
    color: #4a5568;
}

#btn-hide-overlay:hover {
    background: linear-gradient(to bottom, #edf2f7, #e2e8f0);
    border-color: #a0aec0;
    color: #2d3748;
}

.btn-label {
    white-space: nowrap;
}

.btn-label[hidden] {
    display: none;
}

/* Touch-friendly sizing on mobile */
@media (hover: none) and (pointer: coarse) {
    .control-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 14px;
    }
}

/* ============================================
   GPS Panel
   ============================================ */
.gps-panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 16px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #dee2e6;
    font-size: 12px;
}

.gps-panel[hidden] {
    display: none;
}

.gps-row {
    display: flex;
    gap: 6px;
}

.gps-label {
    color: #6c757d;
    font-weight: 500;
}

.gps-value {
    color: #212529;
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, monospace;
}

/* ============================================
   Lightbox
   ============================================ */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox[hidden] {
    display: none;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.lightbox-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    max-width: 95vw;
    max-height: 95vh;
}

.lightbox-image-wrapper {
    position: relative;
}

.lightbox-image {
    max-width: 100%;
    max-height: calc(95vh - 60px);
    object-fit: contain;
    border-radius: 4px;
    display: block;
}

.lightbox-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    color: #fff;
}

.lightbox-controls .controls-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.lightbox-controls .camera-time {
    color: #e9ecef;
}

.lightbox-controls .camera-countdown {
    color: #adb5bd;
    font-size: 13px;
}

.lightbox-controls .control-btn {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.lightbox-controls .control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

/* ============================================
   Size-Specific Adjustments
   ============================================ */

/* Thumb size - minimal controls */
.camera-viewer[data-size="thumb"] .camera-controls {
    padding: 4px 8px;
    min-height: 36px;
}

.camera-viewer[data-size="thumb"] .camera-time {
    font-size: 11px;
}

.camera-viewer[data-size="thumb"] .camera-countdown {
    font-size: 10px;
}

.camera-viewer[data-size="thumb"] .control-btn {
    padding: 4px 6px;
    min-height: 28px;
    min-width: 28px;
}

.camera-viewer[data-size="thumb"] .control-btn svg {
    width: 14px;
    height: 14px;
}

/* Large size - more prominent display */
.camera-viewer[data-size="large"] .camera-controls,
.camera-viewer[data-size="full"] .camera-controls {
    padding: 10px 16px;
}

.camera-viewer[data-size="large"] .camera-time,
.camera-viewer[data-size="full"] .camera-time {
    font-size: 14px;
}

.camera-viewer[data-size="large"] .control-btn,
.camera-viewer[data-size="full"] .control-btn {
    padding: 8px 12px;
}

/* ============================================
   Responsive Breakpoints
   ============================================ */

/* Mobile layout (JS adds .is-mobile class via User Agent detection) */
body.is-mobile .camera-controls {
    flex-wrap: wrap;
    gap: 8px;
}
body.is-mobile .controls-left {
    width: 100%;
    justify-content: space-between;
}
body.is-mobile .controls-right {
    width: 100%;
    justify-content: flex-end;
}
body.is-mobile .gps-panel {
    grid-template-columns: 1fr;
}
body.is-mobile .btn-label {
    display: none;
}

/* Medium screens */
@media (min-width: 481px) and (max-width: 768px) {
    .camera-viewer[data-size="thumb"] .btn-label {
        display: none;
    }
}

/* ============================================
   Dark Mode Support
   ============================================ */
@media (prefers-color-scheme: dark) {
    .camera-viewer {
        background: #1a1a1a;
    }

    .camera-controls {
        background: #212529;
        border-color: #343a40;
    }

    .camera-time {
        color: #e9ecef;
    }

    .camera-countdown {
        color: #adb5bd;
    }

    .control-btn {
        background: #343a40;
        border-color: #495057;
        color: #e9ecef;
    }

    .control-btn:hover {
        background: #495057;
        border-color: #6c757d;
        color: #fff;
    }

    .gps-panel {
        background: #212529;
        border-color: #343a40;
    }

    .gps-label {
        color: #adb5bd;
    }

    .gps-value {
        color: #e9ecef;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .camera-controls,
    .lightbox {
        display: none !important;
    }

    .camera-viewer {
        max-width: 100%;
    }
}
