/* 
 * MAIN STYLES - ON-SITE ENGRAVING SYSTEM
 * Organized CSS with reduced redundancy and improved maintainability
 */

/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
    /* Brand Colors - can be dynamically overridden via JavaScript */
    --brand-primary: #007bff;
    --brand-primary-hover: #0056b3;
    --brand-primary-active: #004085;
    --brand-secondary: #6c757d;
    --brand-secondary-hover: #5a6268;
    
    /* Dynamic Header Height - updated by JavaScript */
    --header-height: 90px;
}

/* ===== GENERAL STYLES ===== */
* {
    box-sizing: border-box; /* Universal box-sizing */
}

body {
    font-family: Arial, sans-serif;
    background-color: #f9f9f9;
    color: #333;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Dark mode transition class */
.dark-mode-transition {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Classes for temporary mode toggle */
.temp-mode-active {
    opacity: 1;
}

.temp-mode-fade-in {
    animation: tempModeFadeIn 0.3s forwards;
}

.temp-mode-fade-out {
    animation: tempModeFadeOut 0.3s forwards;
}

@keyframes tempModeFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes tempModeFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

p {
    margin-block-start: 0.1em;
    margin-block-end: 0.2em;
}

h1 {
    font-size: 2em;
    margin-block-start: 0.1em;
    margin-block-end: 0.1em;
}

/* ===== LAYOUT COMPONENTS ===== */
/* Header */
header {
    position: fixed;
    top: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #333;
    color: white;
    padding: 5px;
    left: 0;
    z-index: 1000;
}

#eventLogo {
    margin-right: 15px;
    max-height: 60px;
    border-radius: 8px;
    display: none; /* Hidden by default until loaded */
}

#eventName {
    margin-left: 10px;
    font-size: 1.3em;
    font-weight: bold;
}

/* Main content area */
main {
    width: 100%; /* Allow width to grow */
    max-width: 400px; /* Keep constraints unless overridden */
    margin: 90px auto;
    padding: 20px 20px 10px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    flex: 1;
}

/* Footer */
footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
    padding: 12px 0;
    background-color: #333;
    color: white;
    font-size: 1.1em;
    margin-top: auto;
    left: 0;
    cursor: pointer;
    transition: background-color 0.2s ease, padding 0.2s ease;
}

footer:hover {
    background-color: #444;
    padding: 14px 0;
}

footer a {
    transition: opacity 0.2s ease;
}

footer a:hover {
    opacity: 0.9;
}

/* ===== FORMS & INPUTS ===== */
form {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

label {
    font-weight: bold;
    margin-bottom: 2px;
}

input {
    padding:10px;
    font-size: 1em;
    border: 1px solid #ddd;
    border-radius: 5px;
}

input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 5px color-mix(in srgb, var(--brand-primary) 50%, transparent);
}

/* ===== BUTTONS ===== */
.buttons-container {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

button {
    background-color: #333;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #555;
}

.buttons-container button {
    flex: 1;
    padding: 12px;
    font-size: 1em;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Specific button styles */
#submitButton {
    background-color: var(--brand-primary) !important;
}

#submitButton:hover {
    background-color: var(--brand-primary-hover) !important;
}

#submitButton:active {
    background-color: var(--brand-primary-active) !important;
}

button#lookupButton {
    background-color: var(--brand-secondary);
}

button#lookupButton:hover {
    background-color: var(--brand-secondary-hover);
}

#backButton {
    background-color: var(--brand-primary);
}

#backButton:hover {
    background-color: var(--brand-primary-hover);
}

/* ===== DISPLAY IMAGE ===== */
#displayImageContainer {
    width: 100%;
    max-width: 600px;
    margin: 15px auto;
    padding: 0;
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
}

#displayImage {
    max-width: 60%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: block;
    margin: 0 auto;
}

/* ===== PRODUCT CANVAS (ADVANCED CUSTOMIZATION) ===== */
#productCanvasContainer {
    width: 100%; /* Fill available width */
    max-width: 100%;
    margin: 0 auto 0.3rem;
    padding: 0;
    display: none;
    justify-content: center;
    align-items: center;
    position: relative;
}

#productCanvas {
    width: 100% !important; /* Force fill container */
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 !important;
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    background: #ffffff;
}

.dark-mode #productCanvas {
    background: #1f2937;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

#productCanvasContainer.loading {
    position: relative;
    min-height: 300px;
}

#productCanvasContainer.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: canvas-spin 0.8s linear infinite;
}

@keyframes canvas-spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

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

#productCanvas.loaded {
    animation: canvas-fade-in 0.3s ease-out;
}

/* ===== TICKET VIEW ===== */
#ticketView {
    display: none;
    margin: calc(var(--header-height) + 10px) auto 70px; /* Dynamic header height + 10px gap */
    padding: 1px 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    text-align: center;
    width: 90%;
    max-width: 340px;
    border: 1px solid #ccc;
    position: relative;
    overflow: hidden;
    animation: ticketAppear 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

#ticketView h2 {
    font-size: 2em;
    margin-top: 0.6px;
    margin-bottom: 0.1px;
    color: var(--brand-primary);
}

.ticket-info h2 {
    font-size: 1.5em;
    margin-bottom: 1px;
}

.perforated-line {
    border-top: 2px dashed #ccc;
    position: relative;
}

#ticketNumber {
    display: inline-block;
    font-family: monospace;
    letter-spacing: 1px;
    font-weight: bold;
    font-size: 1.5em;
    background-color: #f0f0f0;
    padding: 0px 5px;
    border-radius: 5px;
    color: #333;
    border: 1px dashed #ccc;
}

#completionStatus {
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 4px;
}

#completionStatus.pending {
    color: #dc3545;
}

#completionStatus.complete {
    color: #28a745;
}

#completionStatus.local-only {
    color: #ff8c00;
    background-color: rgba(255, 140, 0, 0.1);
    border: 1px dashed #ff8c00;
    padding: 2px 6px;
}

/* ===== TICKET DETAILS ===== */
.ticket-detail {
    min-width: 100%;
    width: 100%;
    flex-shrink: 0;
    margin-top: 0.3rem;
    margin-bottom: 0.3rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #f9f9f9;
    text-align: center;
    padding: 5px;
    transition: transform 0.2s;
    overflow: hidden;
}

.ticket-detail p {
    margin: 2px 0;
    font-size: 1.1em;
    font-weight: bold;
    word-break: break-all;
}

/* ===== QR CODE STYLING ===== */
.qr-code {
    margin: 2px auto;
    padding: 5px;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    width: fit-content;
    max-width: 100%;
    overflow: hidden;
}

.qr-code img {
    display: block;
    width: 240px;
    height: 240px;
    max-width: 100%;
    object-fit: contain;
}

/* ===== CAROUSEL STYLING ===== */
.qr-carousel-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    margin: 0.2rem 0;
    clip-path: inset(0 0 0 0);
}

.qr-carousel {
    display: flex;
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    width: 100%;
    flex-wrap: nowrap;
}

/* Dot indicators */
.carousel-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 0.6rem 0;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #ccc;
    border: 1px solid #999;
}

.dot.active {
    background-color: #555;
    border-color: #555;
}

/* Spring effect */
.carousel-spring-effect {
    transition-timing-function: cubic-bezier(0.2, 0.82, 0.4, 0.94);
}

/* Touch area for swiping */
.carousel-touch-area {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 5;
}

/* ===== ANIMATIONS ===== */
.fade-in {
    animation: fadeIn 0.5s ease-out;
    animation-fill-mode: both;
}

.slide-up {
    animation: slideUp 0.4s ease-out;
    animation-fill-mode: both;
}

.scale-in {
    animation: scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation-fill-mode: both;
}

.slide-in-right {
    animation: slideInRight 0.4s ease-out;
    animation-fill-mode: both;
}

.slide-in-left {
    animation: slideInLeft 0.4s ease-out;
    animation-fill-mode: both;
}

/* Animation delays */
.animation-delay-1 { animation-delay: 0.05s; }
.animation-delay-2 { animation-delay: 0.15s; }
.animation-delay-3 { animation-delay: 0.25s; }
.animation-delay-4 { animation-delay: 0.35s; }

/* Animation keyframes */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.85);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes ticketAppear {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    40% { opacity: 0.7; }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ===== DARK MODE CLASSES ===== */
/* Dark mode styles */
body.dark-mode {
    background-color: #1a1a1a;
    color: #ffffff;
}

body.dark-mode header {
    background-color: #000000;
}

body.dark-mode main {
    background-color: #2d2d2d;
}

body.dark-mode input {
    background-color: #333333;
    color: #ffffff;
    border-color: #444444;
}

body.dark-mode button {
    background-color: #444;
}

body.dark-mode button:hover {
    background-color: #555;
}

/* Removed: #submitButton already uses brand colors, no need for dark mode override */

body.dark-mode footer {
    background-color: #000000;
    color: #ffffff;
}

body.dark-mode #ticketView {
    background-color: #2d2d2d;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    border-color: #444;
}

body.dark-mode #ticketView h2 {
    color: #66b3ff;
}

body.dark-mode .perforated-line {
    border-top-color: #555;
}

body.dark-mode .ticket-detail {
    background-color: #333;
    border-color: #444;
}

body.dark-mode .ticket-detail p {
    color: #fff;
}

/* Removed: #backButton already uses brand colors, no need for dark mode override */

body.dark-mode #ticketNumber {
    background-color: #333;
    color: #fff;
    border-color: #555;
}

body.dark-mode #completionStatus.pending {
    color: #ff6b6b;
}

body.dark-mode #completionStatus.complete {
    color: #5cb85c;
}

body.dark-mode #completionStatus.local-only {
    color: #ffa500;
    background-color: rgba(255, 165, 0, 0.15);
    border-color: #ffa500;
}

body.dark-mode .dot {
    background-color: #444;
    border-color: #555;
}

body.dark-mode .dot.active {
    background-color: #aaa;
    border-color: #aaa;
}

/* ===== RESPONSIVE STYLING ===== */
@media (max-width: 600px) {
    /* Add padding to body to account for fixed header */
    body {
        padding-top: var(--header-height);
        overflow-x: hidden;
        position: relative;
    }
    
    header {
        flex-direction: column;
        text-align: center;
        padding: 8px 1px;
    }

    #eventLogo {
        margin: 0 0 2px 0;
        max-height: 40px;
    }

    #eventName {
        margin: 0;
        font-size: 1.2em;
    }

    /* All containers aligned to canvas width */
    #displayImageContainer {
        margin: 0 auto 10px;
    }

    #displayImage {
        width: 100%;
        max-width: 90%;
    }
    
    #productCanvasContainer {
        margin: 2px 0 8px 0;
    }
    
    #productCanvas {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Lighter shadow on mobile */
    }
    
    #svgSelectorContainer {
        width: 90%;
        max-width: 90%;
        margin: 0 auto 8px;
    }

    main {
        width: 100%;
        max-width: 100%;
        padding: 0 5% 60px 5%;
        margin: 0;
        background: transparent !important;
        border-radius: 0;
        box-shadow: none;
    }
    
    body.dark-mode #productCanvas {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    }
    
    #engravingForm,
    #fieldsContainer,
    .field,
    .buttons-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
    }
    
    #engravingForm {
        overflow: visible;
    }
    
    .field {
        margin-bottom: 15px;
    }
    
    .field label {
        display: block;
        width: 100%;
        margin: 0 0 5px 0;
    }
    
    input {
        width: 100%;
        display: block;
        margin: 0;
        /* Keep default padding from base styles (10px) */
    }
    
    .buttons-container {
        display: flex;
        flex-direction: row;
        gap: 10px;
        margin: 10px 0; /* Restore vertical margins */
    }

    button {
        font-size: 1.4em;
        padding: 15px 18px;
    }
    
    .qr-code img {
        width: 200px;
        height: 200px;
    }
}

@media (max-width: 380px) {
    #displayImage {
        max-width: 90%;
    }
    
    .qr-code img {
        width: 180px;
        height: 180px;
    }
}

/* ===== CUSTOMIZATION MODE TOGGLE ===== */
#fieldsContainer.collapsed {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0;
    margin: 0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#fieldsContainer:not(.collapsed) {
    max-height: none;
    overflow: visible;
    opacity: 1;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Show text toggle when fields are collapsed */
#engravingForm.collapsed #textCustomizationToggle {
    display: flex !important;
}

#engravingForm:not(.collapsed) #textCustomizationToggle {
    display: none !important;
}

/* ===== SVG SELECTOR STYLES ===== */
#svgSelectorContainer {
    padding: 0;
    max-width: 100%;
    width: 100%;
    margin: 4px auto 8px;
    overflow: visible;
}

/* Shared toggle button styles */
.svg-selector-toggle {
    width: 100%;
    padding: 1px 10px;
    margin-bottom: 8px;
    background: color-mix(in srgb, var(--brand-primary) 2%, transparent);
    border: 1px dashed color-mix(in srgb, var(--brand-primary) 30%, transparent);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: var(--brand-primary);
    display: none;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.svg-selector-toggle:hover {
    background: color-mix(in srgb, var(--brand-primary) 5%, transparent);
    border-color: var(--brand-primary);
    border-style: solid;
}

body.dark-mode .svg-selector-toggle {
    background: color-mix(in srgb, var(--brand-primary) 3%, transparent);
    border-color: color-mix(in srgb, var(--brand-primary) 40%, transparent);
}

body.dark-mode .svg-selector-toggle:hover {
    background: color-mix(in srgb, var(--brand-primary) 8%, transparent);
    border-color: var(--brand-primary);
}

/* Toggle visibility */
#svgSelectorContainer.collapsed .svg-selector-toggle {
    display: flex;
}

/* Content wrapper */
.svg-selector-content {
    padding: 2px;
    max-height: none; /* Remove height constraint */
    overflow: visible;
    opacity: 1;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#svgSelectorContainer.collapsed .svg-selector-content {
    max-height: 0;
    padding: 0;
    opacity: 0;
}

.svg-selector-container:not(:last-child) {
    margin-bottom: 4px;
}

.svg-selector-grid {
    display: flex;
    gap: 8px;
    padding: 2px;
    overflow-x: auto;
    overflow-y: visible;
    justify-content: center;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* Hide scrollbar completely */
.svg-selector-grid::-webkit-scrollbar {
    display: none;
}

.svg-selector-option {
    flex-shrink: 0;
    width: 53px;
    height: 53px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand-primary) 0%, transparent);
    transform: scale(1);
}

.svg-selector-option:hover {
    border-color: var(--brand-primary);
    background: color-mix(in srgb, var(--brand-primary) 3%, transparent);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--brand-primary) 15%, transparent);
    transform: scale(1.08);
}

.svg-selector-option.selected {
    border-width: 2.5px;
    border-color: var(--brand-primary);
    background: color-mix(in srgb, var(--brand-primary) 8%, transparent);
    filter: drop-shadow(0 0 8px color-mix(in srgb, var(--brand-primary) 50%, transparent));
    transform: scale(1.05);
}

body.dark-mode .svg-selector-option {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode .svg-selector-option:hover {
    border-color: var(--brand-primary);
    background: color-mix(in srgb, var(--brand-primary) 8%, transparent);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--brand-primary) 20%, transparent);
}

body.dark-mode .svg-selector-option.selected {
    border-width: 2.5px;
    border-color: var(--brand-primary);
    background: color-mix(in srgb, var(--brand-primary) 12%, transparent);
    filter: drop-shadow(0 0 10px color-mix(in srgb, var(--brand-primary) 60%, transparent));
}

.svg-selector-thumbnail {
    width: 100%;
    height: 100%;
    padding: 6px;
    object-fit: contain;
    background: white;
    border-radius: 4px;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.svg-selector-option:hover .svg-selector-thumbnail {
    opacity: 0.85;
}

.svg-selector-option.selected .svg-selector-thumbnail {
    opacity: 1;
}

.svg-selector-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 18px;
    font-weight: bold;
    color: #999;
}

body.dark-mode .svg-selector-placeholder {
    color: #666;
}

@media (max-width: 480px) {
    
    .svg-selector-option {
        width: 52px;
        height: 52px;
    }
    
    .svg-selector-grid {
        gap: 6px;
    }
}
