/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 50%, #e2e8f0 100%);
    min-height: 100vh;
    color: #0f172a;
    overflow-x: hidden;
}

/* Consent Popup */
#popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 480px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.15);
    border-radius: 24px;
    padding: 30px;
    z-index: 1000;
    display: none;
    color: #334155;
}

#popup .title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: #0f172a;
    background: linear-gradient(45deg, #6d28d9, #db2777);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#popup .popcontent {
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 25px;
    color: #64748b;
}

#popup .popcontent ul {
    margin-top: 10px;
}

#popup .popcontent li {
    margin-bottom: 8px;
}

#popup .ji {
    display: flex;
    justify-content: flex-end;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 30px 20px;
    min-height: 100vh;
    animation: fadeIn 0.6s ease-out;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 10px 0;
}

header h1 {
    font-size: 3.2rem;
    font-weight: 700;
    background: linear-gradient(45deg, #6d28d9, #db2777, #2563eb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    letter-spacing: -1px;
}

header p {
    font-size: 1.1rem;
    color: #475569;
    font-weight: 300;
}

/* Main Content Grid Layout - Three-Panel System */
.main-content {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 30px;
    align-items: start;
}

/* Unified Frame Panel Base Style */
.frame-panel {
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 24px;
    padding: 25px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.06);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.frame-panel:hover {
    border-color: rgba(124, 58, 237, 0.2);
    box-shadow: 0 20px 40px rgba(124, 58, 237, 0.06);
}

/* Frame 1: Preview specific styles */
.frame-preview {
    position: sticky;
    top: 30px;
    z-index: 10;
}

.frame-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.frame-header-title h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #0f172a;
}

.frame-header-title .material-icons {
    color: #7c3aed;
    font-size: 1.5rem;
}

/* Image Container & Webcam */
.image-container {
    position: relative;
    border-radius: 18px;
    overflow: hidden;
    background: #f8fafc;
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(15, 23, 42, 0.06);
}

#webcam-container {
    width: 100%;
    height: 100%;
    position: relative;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#webcam, #uploaded-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #f8fafc;
    border-radius: 18px;
}

#uploaded-image {
    display: none;
    z-index: 1;
}

/* Guide Stencil Canvas */
#guide-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* Alignment Guide HUD */
.alignment-guide {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    padding: 8px 18px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 5;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.1);
    border: 1px solid rgba(15, 23, 42, 0.08);
    width: max-content;
    max-width: 90%;
    pointer-events: none;
    transition: all 0.3s ease;
}

.alignment-guide.hidden {
    opacity: 0;
    transform: translate(-50%, -10px);
}

.alignment-light {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #ef4444;
    box-shadow: 0 0 10px #ef4444;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.alignment-light.red {
    background-color: #ef4444;
    box-shadow: 0 0 10px #ef4444;
    animation: pulse-red 1s infinite alternate;
}

.alignment-light.orange {
    background-color: #f59e0b;
    box-shadow: 0 0 10px #f59e0b;
    animation: pulse-orange 1s infinite alternate;
}

.alignment-light.green {
    background-color: #10b981;
    box-shadow: 0 0 12px #10b981;
}

#alignment-message {
    color: #0f172a;
    font-size: 0.85rem;
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
}

.alignment-text-red {
    color: #dc2626 !important;
}

.alignment-text-orange {
    color: #d97706 !important;
}

.alignment-text-green {
    color: #059669 !important;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 4px #ef4444; }
    100% { box-shadow: 0 0 12px #ef4444; }
}

@keyframes pulse-orange {
    0% { box-shadow: 0 0 4px #f59e0b; }
    100% { box-shadow: 0 0 12px #f59e0b; }
}

/* Control Buttons Overlay */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 15px;
    margin-bottom: 5px;
    z-index: 5;
}

.control-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(15, 23, 42, 0.08);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
}

.control-btn:hover {
    background: #a78bfa;
    color: #ffffff;
    border-color: #a78bfa;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(167, 139, 250, 0.3);
}

.control-btn .material-icons {
    font-size: 18px;
}

/* Actions - Upload & Camera */
.control-actions {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.upload-section {
    flex: 1;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, #7c3aed 0%, #a78bfa 100%);
    color: white;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(124, 58, 237, 0.45);
    background: linear-gradient(135deg, #6d28d9 0%, #8b5cf6 100%);
}

.upload-btn .material-icons {
    font-size: 20px;
}

#file-upload {
    display: none;
}

/* Jewelry Options Column */
.jewelry-options-column {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Jewelry Category Header */
.type-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.type-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
}

.type-header .material-icons {
    color: #db2777;
    font-size: 1.4rem;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: 0.4s;
    border-radius: 28px;
    border: 1px solid rgba(15, 23, 42, 0.05);
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.1);
}

input:checked + .slider {
    background: linear-gradient(135deg, #7c3aed, #db2777);
}

input:checked + .slider:before {
    transform: translateX(22px);
    background-color: #ffffff;
}

/* Card Selection Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}

.items {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 16px;
    padding: 14px;
    border: 1px solid rgba(15, 23, 42, 0.04);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.items:hover {
    transform: translateY(-4px);
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 12px 25px rgba(15, 23, 42, 0.05);
    border-color: rgba(124, 58, 237, 0.15);
}

.Jewelry-btn {
    width: 100%;
    height: 110px;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 12px;
    cursor: pointer;
    overflow: hidden;
    background: rgba(248, 250, 252, 0.6);
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.Jewelry-btn img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    transition: all 0.3s ease;
}

.Jewelry-btn:hover img {
    transform: scale(1.05);
}

.Jewelry-btn.selected {
    border-color: #7c3aed;
    box-shadow: 0 0 15px rgba(124, 58, 237, 0.15);
    background: rgba(124, 58, 237, 0.05);
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: center;
}

.item-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-price {
    font-size: 0.8rem;
    font-weight: 600;
    color: #f472b6;
}

.buynow-btn {
    padding: 8px 12px;
    background: linear-gradient(135deg, #f472b6 0%, #a78bfa 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(244, 114, 182, 0.2);
}

.buynow-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(244, 114, 182, 0.35);
    background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
}

/* Loading Spinner */
.loading-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 10;
    border-radius: 18px;
}

.loading-indicator p {
    font-size: 0.9rem;
    font-weight: 500;
    color: #475569;
}

.spin {
    animation: rotate 1s linear infinite;
    font-size: 28px;
    color: #7c3aed;
}

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

/* Upload message inside preview */
.upload-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #64748b;
    z-index: 1;
}

.upload-message .material-icons {
    font-size: 3rem;
    color: #94a3b8;
}

/* Camera state helper */
#webcam-container::before {
    content: "Starting camera feed...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #64748b;
    font-size: 0.95rem;
    text-align: center;
    z-index: 1;
    pointer-events: none;
    display: none; /* Hidden by default */
}

#webcam-container.active::before {
    display: block; /* Show only when active */
}

#webcam-container.active:has(#uploaded-image[style*="display: block"])::before,
#webcam-container.active:has(#webcam:not([style*="display: none"]))::before {
    display: none; /* Hide when we have active content */
}

/* Fade In Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Styles */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 25px;
    }
    
    .frame-preview {
        position: relative;
        top: 0;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header {
        margin-bottom: 20px;
    }

    header h1 {
        font-size: 2.2rem;
    }
    
    header p {
        font-size: 0.95rem;
    }
    
    .main-content {
        gap: 15px;
    }

    /* Sticky Mobile Preview Panel */
    .frame-preview {
        position: sticky;
        top: 0;
        z-index: 100;
        padding: 12px 16px 16px 16px;
        border-radius: 0 0 20px 20px;
        box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
        background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
        border: 1px solid rgba(15, 23, 42, 0.05);
        border-top: none;
    }
    
    .frame-preview .image-container {
        width: 100%;
        max-width: 360px;
        margin: 0 auto 12px auto;
        aspect-ratio: 1;
    }
    
    .frame-preview .frame-header-title {
        display: none;
    }
    
    .control-actions {
        display: flex;
        gap: 10px;
        margin-top: 0;
    }
    
    .upload-section {
        margin-bottom: 0;
        flex: 1;
    }
    
    .upload-btn {
        padding: 10px 15px;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    .alignment-guide {
        top: 10px;
        padding: 4px 12px;
        gap: 8px;
    }

    .alignment-light {
        width: 10px;
        height: 10px;
    }

    #alignment-message {
        font-size: 0.75rem;
    }

    .frame-panel {
        padding: 20px;
        border-radius: 18px;
    }
    
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 12px;
    }
    
    .items {
        padding: 10px;
        border-radius: 12px;
    }
    
    .Jewelry-btn {
        height: 90px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.8rem;
    }
    
    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .Jewelry-btn {
        height: 80px;
    }
}