/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

/* Home navigation button */
.home-nav {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
}

.home-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background-color: rgba(82, 203, 84, 0.9);
    color: white;
    text-decoration: none;
    border-radius: 50%;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.home-btn:hover {
    background-color: rgba(82, 203, 84, 1);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(82, 203, 84, 0.3);
}



/* Scanner states */
.scanner-state {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.scanner-state.active {
    display: block;
}

/* State 1: Camera Selection */
#camera-selection-state {
    background-color: #222;
    position: relative;
    height: 100vh;
    width: 100vw;
}

.selection-container {
    text-align: center;
    background-color: #333;
    padding: 40px;
    border-radius: 10px;
    max-width: 400px;
    width: 90%;
    border: 1px solid #444;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.selection-container h1 {
    color: #f3f8fb;
    margin-bottom: 10px;
    font-size: 2.5em;
}

.selection-container p {
    color: #f3f8fb;
    margin-bottom: 30px;
    font-size: 1.1em;
}

.camera-selection {
    margin-bottom: 30px;
    text-align: left;
}

.camera-selection label {
    display: block;
    color: #f3f8fb;
    margin-bottom: 8px;
    font-weight: bold;
}

.camera-selection select {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 5px;
    background: #444;
    font-size: 16px;
    color: #f3f8fb;
}

.camera-selection select:focus {
    outline: none;
    border: 2px solid #52cb54;
}

/* State 2: Active Scanning */
#scanning-state {
    background-color: #000;
    position: relative;
    height: 100vh;
    width: 100vw;
}

.scanning-container {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
}

.camera-preview {
    flex: 2; /* Takes up 2/3 of the screen */
    background-color: #000;
    position: relative;
    overflow: hidden;
    border-bottom: 2px solid #333;
}

.viewport {
    width: 100%;
    height: 100%;
    position: relative;
    background-color: #000;
}

/* Ensure the HTML5-QRCode elements are visible */
#reader {
    width: 100% !important;
    height: 100% !important;
}

#reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

.control-panel {
    flex: 1; /* Takes up 1/3 of the screen */
    background-color: #1a1a1a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border-top: 2px solid #333;
}

.scan-status {
    text-align: center;
    margin-bottom: 20px;
}

.scan-status p {
    color: #fff;
    font-size: 1.2em;
    margin-bottom: 10px;
    text-align: center;
}

.scan-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    background-color: #4CAF50;
    border-radius: 50%;
    margin-right: 10px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
    
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

/* State 3: Results Overlay */
.results-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: none;
    align-items: flex-end;
}

.results-overlay.active {
    display: flex;
}

.overlay-content {
    background: white;
    width: 100%;
    height: 75%; /* Exactly 3/4 of the page as specified */
    border-radius: 25px 25px 0 0;
    padding: 30px;
    box-sizing: border-box;
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    /* Ensure the overlay slides from bottom to top covering bottom 3/4 */
    position: relative;
    bottom: 0;
    gap: 20px;
}

.results-overlay.active .overlay-content {
    transform: translateY(0);
}

.overlay-header {
    text-align: center;
    margin-bottom: 30px;
}

.overlay-header h2 {
    margin: 0;
    font-size: 2em;
    color: #333;
}

.ticket-details {
    flex: 1;
    margin-bottom: 30px;
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
    max-height: 300px;
    overflow-y: auto;
    min-height: 200px;
    scrollbar-width: thin;
    scrollbar-color: #8d8d8d #f8f9fa;
}

/* Webkit scrollbar styling */
.ticket-details::-webkit-scrollbar {
    width: 6px;
}

.ticket-details::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 3px;
}

.ticket-details::-webkit-scrollbar-thumb {
    background: #52cb54;
    border-radius: 3px;
}

.ticket-details::-webkit-scrollbar-thumb:hover {
    background: #3fa541;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #e9ecef;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-row .label {
    font-weight: bold;
    color: #495057;
    font-size: 1.1em;
}

.detail-row .value {
    color: #212529;
    font-size: 1.1em;
    text-align: right;
    max-width: 60%;
    word-break: break-word;
    font-weight: 500;
}

/* Overlay Color States */
.results-overlay.valid-first {
    background-color: rgb(80, 124, 82);
}

.results-overlay.valid-repeat {
    background-color: rgb(154, 127, 48);
}

.results-overlay.invalid {
    background-color: rgb(125, 50, 45);
}

.results-overlay.valid-first .overlay-content,
.results-overlay.valid-repeat .overlay-content,
.results-overlay.invalid .overlay-content {
    background: white;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
}

/* Add subtle color hints to the overlay content based on status */
.results-overlay.valid-first .overlay-header h2 {
    color: #2e7d32;
}

.results-overlay.valid-repeat .overlay-header h2 {
    color: #9a7f30;
}

.results-overlay.invalid .overlay-header h2 {
    color: #C62828;
}

/* Buttons */
.primary-button, .secondary-button {
    padding: 15px 30px;
    border: none;
    border-radius: 5px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    min-width: 200px;
    position: relative;
    overflow: hidden;
}

.primary-button {
    background-color: #52cb54;
    color: white;
}

.primary-button:hover {
    background-color: #3fa541;
    transform: translateY(-2px);
}

.primary-button:active {
    transform: translateY(0);
}

.secondary-button {
    background: transparent;
    color: #f3f8fb;
    border: 2px solid #f3f8fb;
}

.secondary-button:hover {
    background: #f3f8fb;
    color: #222;
    transform: translateY(-2px);
}

.secondary-button:active {
    transform: translateY(0);
}

#close-overlay-btn {
    align-self: center;
    margin-top: auto;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: #52cb54;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

/* Responsive Design */
@media (max-width: 768px) {
    .selection-container {
        padding: 30px 20px;
        margin: 20px;
    }
    
    .selection-container h1 {
        font-size: 2em;
    }
    
    .overlay-content {
        padding: 20px;
        gap: 15px;
    }
    
    .overlay-header h2 {
        font-size: 1.5em;
    }
    
    .ticket-details {
        max-height: 280px;
        min-height: 180px;
    }
    
    .detail-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .detail-row .value {
        text-align: left;
        max-width: 100%;
    }
    
    .primary-button, .secondary-button {
        min-width: 150px;
        font-size: 16px;
    }
    
    #close-overlay-btn {
        padding: 18px 25px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .selection-container h1 {
        font-size: 1.8em;
    }
    
    .overlay-content {
        height: 85%;
        padding: 20px 15px;
    }
    
    .ticket-details {
        max-height: 450px;
        min-height: 150px;
        padding: 15px;
    }
    
    .detail-row {
        padding: 12px 0;
    }
    
    .detail-row .label,
    .detail-row .value {
        font-size: 1em;
    }
}

/* Camera loading state */
.camera-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1em;
    background-color: #000;
    z-index: 10;
}

.camera-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #4CAF50;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}