/* Unified Overlay Styles */
.overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(3px);
    background: rgba(0, 0, 0, 0.35);
}

.overlay.is-open {
    display: flex;
}

/* Handle nested overlays if needed */
.overlay.is-open + .overlay.is-open {
    z-index: 10000;
}

.overlay-card {
    position: relative;
    max-width: 720px;
    width: min(92vw, 720px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.35);
    padding: 20px;
    z-index: 1;
    max-height: 90vh;
    overflow-y: auto;
    /* Prevent content from jumping during transitions */
    box-sizing: border-box;
}

.overlay-title {
    margin: 0 0 12px;
    font: 600 18px/1.3 system-ui, sans-serif;
    color: #333;
}

.overlay-body {
    max-height: 70vh;
    overflow: auto;
    margin-bottom: 16px;
}

.overlay-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

.overlay-close {
    position: absolute;
    top: 10px;
    right: 10px;
    cursor: pointer;
    border: none;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    color: #666;
    padding: 5px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.overlay-close:hover {
    background: #f0f0f0;
    color: #333;
}

/* Overlay specific styles */
#product-category-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
}

#product-category-list li {
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: #fff;
}

#product-category-list li:hover {
    background: #f8f9fa;
    border-color: #007cba;
    transform: translateY(-1px);
}

.manual-entry-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.manual-entry-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-weight: 600;
    color: #555;
}

.manual-entry-form input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.manual-entry-form input:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.1);
}

/* Unified Button System for Overlays - SINGLE DEFINITION */
.overlay button,
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-sizing: border-box;
}

/* Primary button styles (main actions) */
.overlay button.btn-primary,
.overlay button[id*="method-"]:not(#method-back),
.btn-primary {
    background: #007cba;
    color: white;
    border: 1px solid #007cba;
}

.overlay button.btn-primary:hover,
.overlay button[id*="method-"]:not(#method-back):hover,
.btn-primary:hover {
    background: #005a87;
    border-color: #005a87;
    transform: translateY(-1px);
}

/* Secondary button styles (cancel, close) */
.overlay button.btn-secondary,
.overlay button[data-overlay-close],
.btn-secondary {
    background: #6c757d;
    color: white;
    border: 1px solid #6c757d;
}

.overlay button.btn-secondary:hover,
.overlay button[data-overlay-close]:hover,
.btn-secondary:hover {
    background: #545b62;
    border-color: #545b62;
    transform: translateY(-1px);
}

/* Success button styles (back, confirm) */
.overlay button#method-back,
.btn-success {
    background: #28a745;
    color: white;
    border: 1px solid #28a745;
}

.overlay button#method-back:hover,
.btn-success:hover {
    background: #1e7e34;
    border-color: #1e7e34;
    transform: translateY(-1px);
}

/* Outline button styles */
.btn-outline {
    background: transparent;
    color: #6c757d;
    border: 1px solid #6c757d;
}

.btn-outline:hover {
    background: #6c757d;
    color: white;
}

/* Disabled state for all buttons */
.overlay button:disabled,
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.overlay button:disabled:hover,
.btn:disabled:hover {
    transform: none;
}

/* Loading state */
.btn.loading {
    opacity: 0.7;
    cursor: wait;
}

.btn.loading::after {
    content: "...";
    animation: loading 1s infinite;
}

@keyframes loading {
    0%, 33% { content: "..."; }
    34%, 66% { content: ".."; }
    67%, 100% { content: "."; }
}

/* Method selection specific styles */
.method-buttons {
    display: grid;
    gap: 12px;
    margin: 16px 0;
}

.method-buttons button {
    padding: 16px 20px;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.2s;
    cursor: pointer;
    color: #495057;
}

.method-buttons button:hover {
    background: #e9ecef;
    border-color: #007cba;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 124, 186, 0.15);
    color: #007cba;
}

.method-buttons button:active {
    transform: translateY(0);
}

/* Ensure method buttons override default button styles */
#method-manual,
#method-takeoff {
    background: #f8f9fa !important;
    color: #495057 !important;
    border: 2px solid #dee2e6 !important;
}

#method-manual:hover,
#method-takeoff:hover {
    background: #e9ecef !important;
    color: #007cba !important;
    border-color: #007cba !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .overlay-card {
        width: 95vw;
        margin: 20px;
        max-height: calc(100vh - 40px);
        padding: 16px;
    }
    
    .overlay-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .overlay button,
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .overlay-close {
        top: 8px;
        right: 8px;
    }
}

@media (max-width: 480px) {
    .overlay-card {
        width: 100vw;
        height: 100vh;
        max-height: none;
        border-radius: 0;
        margin: 0;
    }
    
    .overlay-body {
        max-height: calc(100vh - 140px);
    }
}
