* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent page horizontal overflow caused by large images or long strings */
html, body {
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Ensure container doesn't allow children to overflow horizontally */
.container {
    width: 100%;
    box-sizing: border-box;
}

/* Make all images responsive and never exceed their parent's width */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
}

.card h2 {
    color: #4a5568;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.camera-container {
    position: relative;
    max-width: 100%;
    margin-bottom: 20px;
    text-align: center;
}

#camera-feed {
    width: 100%;
    max-width: 600px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

#captured-image {
    width: 100%;
    max-width: 600px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.camera-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(72, 187, 120, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #a0aec0 0%, #718096 100%);
    color: white;
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(160, 174, 192, 0.4);
}

.processing-status {
    text-align: center;
    padding: 30px 0;
}

.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.vin-display {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

#vin-input {
    flex: 1;
    min-width: 300px;
    padding: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    letter-spacing: 2px;
    text-align: center;
    text-transform: uppercase;
}

#vin-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.specs-container {
    display: grid;
    gap: 15px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

/* Allow grid items to shrink below their content size when needed */
.specs-container > * {
    min-width: 0;
}

/* Ensure the grid itself cannot cause horizontal overflow */
.specs-container {
    width: 100%;
    box-sizing: border-box;
}

.spec-group {
    background: #f7fafc;
    padding: 20px;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

/* Make sure spec group content wraps and cannot force horizontal scroll */
.spec-group {
    overflow: hidden;
    word-wrap: break-word;
    -ms-word-break: break-word;
    word-break: break-word;
    hyphens: auto;
    min-width: 0;
}

/* Prevent internal elements from forcing the group wider */
.spec-group * {
    min-width: 0;
}

.spec-group h3 {
    color: #2d3748;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.spec-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
    gap: 8px;
    align-items: center;
    word-break: break-word;
}

.spec-item:last-child {
    border-bottom: none;
}

.spec-label {
    font-weight: 600;
    color: #4a5568;
}

.spec-value {
    color: #2d3748;
    text-align: right;
    max-width: 50%;
}

/* Ensure value can shrink and wrap on small screens */
.spec-value {
    overflow-wrap: break-word;
    white-space: normal;
    min-width: 0;
}

/* Aggressive wrapping for long tokens (URLs, long reference strings) */
.spec-value, .spec-label {
    word-break: break-word;
    overflow-wrap: anywhere;
}

.error {
    border-left: 4px solid #e53e3e;
    background: #fed7d7;
}

.error h2 {
    color: #c53030;
}

#error-message {
    color: #742a2a;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

/* Responsive Design */
@media (max-width: 600px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .card {
        padding: 20px;
    }
    
    .camera-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        width: 100%;
        max-width: 300px;
    }
    
    .vin-display {
        flex-direction: column;
    }
    
    #vin-input {
        min-width: unset;
        width: 100%;
    }
}

/* Animation for sections appearing */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Modal for selecting multiple targets */
.modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-content {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 720px;
    max-height: 80vh;
    overflow: auto;
}

.target-card img { border-radius: 6px; }

/* Image gallery for vehicle images */
.image-gallery {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.image-gallery .main-image {
    width: 100%;
    max-width: 720px; /* cap width to prevent overflow */
    height: auto;
    max-height: 360px;
    object-fit: contain;
    border-radius: 8px;
    background: #f3f4f6;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

/* Ensure modal/target cards don't overflow */
.modal-content, #targets-list, .target-card {
    box-sizing: border-box;
    max-width: 100%;
    overflow-wrap: break-word;
}

/* Safety: prevent any large fixed-width element from creating horizontal scroll */
* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

/* Ensure the gallery never overflows its parent */
.image-gallery {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.image-gallery .thumbs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.image-gallery .thumb {
    width: 72px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
}

.image-gallery .thumb:hover {
    border-color: #667eea;
}

