:root {
    /* Light Theme */
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #1a1a1a;
    --text-muted: #666666;
    --primary-color: #0056b3;
    --primary-hover: #004494;
    --secondary-color: #e9ecef;
    --secondary-hover: #dee2e6;
    --border-color: #ced4da;
    --error-color: #dc3545;
    --success-color: #28a745;
    --focus-ring: 0 0 0 3px rgba(0, 86, 179, 0.4);
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    
    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --text-color: #f8f9fa;
    --text-muted: #adb5bd;
    --primary-color: #4dabf7;
    --primary-hover: #339af0;
    --secondary-color: #2b2b2b;
    --secondary-hover: #3b3b3b;
    --border-color: #495057;
    --focus-ring: 0 0 0 3px rgba(77, 171, 247, 0.4);
    --shadow: 0 4px 6px rgba(0,0,0,0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    z-index: 1000;
    transition: top var(--transition-fast);
}
.skip-link:focus {
    top: 0;
}

a, button, input, select {
    color: inherit;
    font-family: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

button:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: 4px;
}

.hidden {
    display: none !important;
}

/* Header */
.site-header {
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 2px;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.locale-switcher select {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 0.25rem;
    border-radius: 4px;
    margin-right: 0.5rem;
}

#theme-toggle {
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color var(--transition-fast);
}
#theme-toggle:hover {
    background-color: var(--secondary-color);
}

#cart-toggle {
    font-weight: bold;
    padding: 0.5rem 1rem;
    background-color: var(--secondary-color);
    border-radius: 20px;
    transition: background-color var(--transition-fast);
}
#cart-toggle:hover {
    background-color: var(--secondary-hover);
}

/* Main Layout */
main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.page {
    display: none;
    animation: fadeIn var(--transition-normal);
}
.page.active {
    display: block;
}

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

/* Product Page */
.product-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 768px) {
    .product-layout {
        grid-template-columns: 1fr 1fr;
    }
}

.canvas-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--surface-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

#webgl-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}
#webgl-canvas:active {
    cursor: grabbing;
}

.canvas-fallback {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--surface-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    display: none;
}
.fallback-image {
    width: 200px;
    height: 200px;
    background: url('fallback.svg') center/contain no-repeat;
    margin-bottom: 1rem;
}
@media (prefers-reduced-motion: reduce) {
    /* We'll handle this in JS to show static fallback or pause animation */
}

.canvas-controls {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
}
.canvas-controls button {
    background: rgba(0,0,0,0.5);
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.product-details h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.product-price-row {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}
.original-price {
    text-decoration: line-through;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.product-description {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.stock-status {
    color: var(--success-color);
    font-weight: bold;
    margin-bottom: 1.5rem;
}
.stock-status.out {
    color: var(--error-color);
}

.config-form fieldset {
    border: none;
    margin-bottom: 1.5rem;
}
.config-form legend {
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.options-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.option-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    border-radius: 20px;
    transition: all var(--transition-fast);
}
.option-btn:hover:not(:disabled) {
    border-color: var(--primary-color);
}
.option-btn.selected {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}
.option-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    text-decoration: line-through;
}

.size-recommender {
    margin-bottom: 1.5rem;
    background: var(--surface-color);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.size-recommender button {
    color: var(--primary-color);
    font-weight: bold;
    text-decoration: underline;
}
#size-guide-content {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
#size-guide-content input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
}

.add-to-cart-section {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.quantity-selector {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
}
.quantity-selector button {
    padding: 0.75rem 1rem;
    font-size: 1.2rem;
}
.quantity-selector input {
    width: 50px;
    text-align: center;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 1rem;
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    font-weight: bold;
    flex-grow: 1;
    text-align: center;
    transition: background var(--transition-fast);
}
.primary-btn:hover {
    background: var(--primary-hover);
}
.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.secondary-btn {
    background: var(--secondary-color);
    color: var(--text-color);
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    font-weight: bold;
    transition: background var(--transition-fast);
}
.secondary-btn:hover {
    background: var(--secondary-hover);
}

/* Related Products */
.related-products {
    margin-top: 4rem;
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
}

.bundle-offer {
    background: var(--surface-color);
    border: 2px dashed var(--primary-color);
    padding: 1.5rem;
    border-radius: 8px;
    margin: 1.5rem 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}
.bundle-items {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.bundle-plus {
    font-size: 2rem;
    color: var(--text-muted);
}
.bundle-action {
    text-align: right;
}

.catalog-search input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 1.5rem;
    background: var(--surface-color);
    color: var(--text-color);
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}
.catalog-item {
    background: var(--surface-color);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    text-align: center;
}
.catalog-item h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}
.catalog-item .price {
    font-weight: bold;
    margin-bottom: 1rem;
    display: block;
}

/* Cart Drawer */
.cart-drawer {
    position: fixed;
    top: 0;
    right: -400px;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    background: var(--surface-color);
    box-shadow: -4px 0 15px rgba(0,0,0,0.1);
    z-index: 1000;
    transition: right var(--transition-normal);
    display: flex;
    flex-direction: column;
}
.cart-drawer.open {
    right: 0;
}

.cart-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity var(--transition-normal);
}
.cart-overlay.show {
    display: block;
    opacity: 1;
}

.cart-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.cart-header button {
    font-size: 2rem;
    line-height: 1;
}

.cart-shipping-progress {
    padding: 1rem 1.5rem;
    background: var(--secondary-color);
    font-size: 0.9rem;
    text-align: center;
}
.progress-bar {
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    margin-top: 0.5rem;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--success-color);
    width: 0%;
    transition: width var(--transition-normal);
}

.cart-items {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.cart-item {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.cart-item-details {
    flex-grow: 1;
}
.cart-item-title {
    font-weight: bold;
    margin-bottom: 0.25rem;
}
.cart-item-options {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.cart-item-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.btn-remove {
    color: var(--error-color);
    font-size: 0.85rem;
    text-decoration: underline;
}

.cart-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color);
}

.coupon-section {
    margin-bottom: 1rem;
}
.coupon-input-group {
    display: flex;
    gap: 0.5rem;
}
.coupon-input-group input {
    flex-grow: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
}
.coupon-input-group button {
    padding: 0.5rem 1rem;
    background: var(--secondary-color);
    border-radius: 4px;
}
#coupon-msg {
    display: block;
    font-size: 0.85rem;
    margin-top: 0.25rem;
}
#coupon-msg.success { color: var(--success-color); }
#coupon-msg.error { color: var(--error-color); }

.cart-totals {
    margin-bottom: 1rem;
}
.tot-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.tot-row.total {
    font-weight: bold;
    font-size: 1.2rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
}
.discount-row {
    color: var(--success-color);
}

.checkout-btn {
    width: 100%;
}

/* Checkout Page */
.checkout-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}
@media (min-width: 768px) {
    .checkout-container {
        grid-template-columns: 2fr 1fr;
    }
}

.checkout-header {
    margin-bottom: 2rem;
}
.checkout-steps {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}
.step {
    color: var(--text-muted);
}
.step.active {
    color: var(--primary-color);
    font-weight: bold;
}

.checkout-step {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.checkout-step h3 {
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}
.form-row {
    display: flex;
    gap: 1rem;
}
.form-row .form-group {
    flex: 1;
}
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}
.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
}
.form-group input:invalid:focus {
    border-color: var(--error-color);
}
.error-msg {
    color: var(--error-color);
    font-size: 0.85rem;
    display: block;
    margin-top: 0.25rem;
}

.payment-methods {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.radio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}
.radio-label:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(0, 86, 179, 0.05);
}

.checkout-sidebar {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    align-self: start;
}

/* Confirmation Page */
.confirmation-container {
    text-align: center;
    padding: 4rem 1rem;
    background: var(--surface-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.confirmation-container h2 {
    color: var(--success-color);
    margin-bottom: 1rem;
}
.confirmation-container p {
    margin-bottom: 1rem;
}

/* AI Assistant */
.ai-assistant {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 350px;
    background: var(--surface-color);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal);
    border: 1px solid var(--border-color);
}
.ai-assistant.collapsed {
    transform: translateY(calc(100% - 50px));
}

.ai-header {
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-color), #8e44ad);
    color: white;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.ai-title {
    font-weight: bold;
}

.ai-body {
    display: flex;
    flex-direction: column;
    height: 300px;
}

.ai-chat {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ai-msg, .user-msg {
    padding: 0.75rem;
    border-radius: 8px;
    max-width: 85%;
    font-size: 0.9rem;
}
.ai-msg {
    background: var(--secondary-color);
    align-self: flex-start;
    border-bottom-left-radius: 0;
}
.user-msg {
    background: var(--primary-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 0;
}
.ai-thinking {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.ai-input-area {
    display: flex;
    padding: 0.5rem;
    border-top: 1px solid var(--border-color);
}
.ai-input-area input {
    flex-grow: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px 0 0 4px;
    background: var(--bg-color);
    color: var(--text-color);
}
.ai-input-area button {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border-radius: 0 4px 4px 0;
}

.ai-actions {
    padding: 0.5rem;
    text-align: center;
}
.ai-actions button {
    font-size: 0.8rem;
    color: var(--primary-color);
    text-decoration: underline;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    background: var(--surface-color);
    color: var(--text-color);
    padding: 1rem;
    border-radius: 4px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary-color);
    animation: slideIn var(--transition-normal);
}
@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
