* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100dvh;
    overflow: hidden;
    /* Prevent iOS overscroll bounce */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

.container {
    display: flex;
    height: 100dvh;
    gap: 20px;
    padding: 20px;
}

.scanner-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.scanner-variant-selector {
    display: flex;
    gap: 15px;
    width: 100%;
    max-width: 640px;
    padding: 15px 20px;
    background: #2a2a2a;
    border-radius: 8px;
    align-items: center;
}

.scanner-variant-selector label {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

.scanner-variant-selector select {
    flex: 1;
    background: #1a1a1a;
    color: #fff;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.scanner-variant-selector select:hover {
    border-color: #007bff;
}

.scanner-variant-selector select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

#metrics-toggle-btn {
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

#metrics-toggle-btn:hover {
    background-color: #0056b3;
}

#scanner-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
}

video, canvas.drawingBuffer {
    width: 100%;
    height: auto;
    display: block;
}

canvas.drawingBuffer {
    position: absolute;
    top: 0;
    left: 0;
}

button#replace-btn {
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

button#replace-btn:hover {
    background-color: #0056b3;
}

button#replace-btn:disabled {
    background-color: #666;
    cursor: not-allowed;
}

.chat-section {
    flex: 1;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    background: #2a2a2a;
    border-radius: 12px;
    overflow: hidden;
}

.chat-header {
    background: #007bff;
    color: white;
    padding: 15px 20px;
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#reset-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

#reset-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-placeholder {
    color: #888;
    text-align: center;
    font-style: italic;
    margin-top: 20px;
}

.barcode-message {
    background: #3a3a3a;
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 4px solid #007bff;
    animation: slideIn 0.3s ease;
}

.barcode-code {
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    color: #fff;
    font-weight: 600;
    margin-bottom: 4px;
}

.barcode-format {
    font-size: 0.85rem;
    color: #aaa;
    margin-bottom: 2px;
}

.barcode-time {
    font-size: 0.75rem;
    color: #666;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* Mobile responsive layout for iPhone */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        overflow-y: auto;
    }
    
    .scanner-section {
        gap: 10px;
        flex: none;
    }
    
    .scanner-variant-selector {
        flex-direction: column;
        gap: 8px;
        padding: 12px 15px;
        max-width: 100%;
        align-items: stretch;
    }
    
    .scanner-variant-selector label {
        font-size: 1rem;
        font-weight: 600;
    }
    
    .scanner-variant-selector select {
        width: 100%;
        min-height: 52px;
        font-size: 18px;
        padding: 12px 14px;
        line-height: 1.3;
    }

    .scanner-variant-selector select option,
    .scanner-variant-selector select optgroup {
        font-size: 18px;
    }

    #metrics-toggle-btn {
        width: 100%;
        min-height: 44px;
        font-size: 0.95rem;
    }
    
    #scanner-container {
        max-width: 100%;
        border-radius: 8px;
    }
    
    .chat-section {
        max-width: 100%;
        flex: 1;
        min-height: 200px;
    }
    
    button#replace-btn {
        width: 100%;
        padding: 14px 24px;
        font-size: 1.1rem;
        /* Larger tap target for touch */
        min-height: 48px;
    }
    
    #reset-btn {
        min-height: 44px;
        padding: 8px 16px;
    }
}
