/* ========================================
   MasaTasarla - Design System
   Professional 3D Table Designer
   ======================================== */

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

:root {
    --primary: #667eea;
    --primary-dark: #5568d3;
    --secondary: #764ba2;
    --accent: #f093fb;
    --success: #4CAF50;
    --warning: #FF9800;
    --danger: #f44336;
    --dark: #1a1a2e;
    --light: #f8f9fa;
    --border: #e0e0e0;
    --radius: 16px;
    --shadow: 0 10px 40px rgba(0,0,0,0.1);
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.15);
    --gradient: linear-gradient(135deg, var(--primary), var(--secondary));
}

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== TOP NAVIGATION ===== */
.top-nav {
    background: rgba(255,255,255,0.97);
    padding: 12px 5%;
    box-shadow: 0 2px 20px rgba(0,0,0,0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(12px);
}

.logo {
    font-size: 24px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-actions { display: flex; gap: 12px; }

.nav-btn {
    padding: 10px 22px;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    font-family: inherit;
}

.nav-btn.primary {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.nav-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.nav-btn.secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.nav-btn.secondary:hover {
    background: var(--primary);
    color: white;
}

/* ===== MAIN LAYOUT ===== */
.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 3%;
}

.app-grid {
    display: grid;
    grid-template-columns: 360px 1fr 360px;
    gap: 24px;
}

@media (max-width: 1400px) {
    .app-grid { grid-template-columns: 340px 1fr; }
    #right-panel { display: none; }
}
@media (max-width: 900px) {
    .app-grid { grid-template-columns: 1fr; }
    #left-panel { order: 2; }
    #viewer-panel { order: 1; }
}

/* ===== PANELS ===== */
.panel {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

.panel h3 {
    font-size: 18px;
    margin-bottom: 18px;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }
.panel::-webkit-scrollbar-thumb { background: var(--gradient); border-radius: 10px; }

/* ===== UPLOAD ZONE ===== */
.upload-zone {
    border: 3px dashed var(--primary);
    border-radius: var(--radius);
    padding: 36px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: linear-gradient(135deg, #f8f9ff, #fff);
    position: relative;
    overflow: hidden;
}
.upload-zone::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: linear-gradient(45deg, transparent, rgba(102,126,234,0.05), transparent);
    animation: shimmer 3s infinite;
}
@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}
.upload-zone:hover {
    border-color: var(--secondary);
    background: linear-gradient(135deg, #e8edff, #f8f9ff);
    transform: scale(1.02);
}
.upload-icon {
    font-size: 44px;
    margin-bottom: 12px;
    animation: bounce 2s infinite;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* ===== IMAGE GRID ===== */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    gap: 8px;
    margin-top: 16px;
}
.image-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    border: 3px solid var(--border);
    cursor: pointer;
    transition: all 0.3s;
}
.image-thumb:hover { border-color: var(--primary); transform: scale(1.05); }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }
.image-thumb .remove {
    position: absolute; top: 4px; right: 4px;
    background: var(--danger); color: white; border: none;
    border-radius: 50%; width: 22px; height: 22px;
    font-size: 14px; cursor: pointer; opacity: 0;
    transition: opacity 0.3s; display: flex; align-items: center; justify-content: center;
}
.image-thumb:hover .remove { opacity: 1; }

/* ===== BUTTONS ===== */
.btn {
    width: 100%;
    padding: 13px 20px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    font-family: inherit;
}
.btn-primary {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-secondary:hover { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #43a047; }
.btn-ar {
    background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}
.btn-ar:hover { transform: translateY(-2px); }

/* ===== SECTIONS ===== */
.section {
    margin-bottom: 22px;
    padding-bottom: 22px;
    border-bottom: 2px solid #f0f0f0;
}
.section:last-child { border-bottom: none; }
.section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== PROFESSIONAL SLIDER ===== */
.slider-container { margin-bottom: 18px; }
.slider-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.slider-label-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--dark);
}
.slider-value {
    background: var(--gradient);
    color: white;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    min-width: 55px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
.slider-wrapper {
    position: relative;
    margin-bottom: 6px;
}
.slider-track {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    border-radius: 10px;
    background: var(--gradient);
    pointer-events: none;
    transition: width 0.15s;
    z-index: 1;
}
.custom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 10px;
    background: #e8e8e8;
    outline: none;
    position: relative;
}
.custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--gradient);
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.4);
    transition: all 0.2s;
    position: relative;
    z-index: 2;
}
.custom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 5px 16px rgba(102, 126, 234, 0.6);
}
.custom-slider::-moz-range-thumb {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--gradient);
    cursor: pointer;
    border: none;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.4);
}
.slider-ticks {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    padding: 0 10px;
}
.slider-tick { font-size: 10px; color: #aaa; }

/* ===== DIMENSION INPUTS ===== */
.dimension-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}
.dimension-input {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px 10px;
    text-align: center;
    border: 2px solid var(--border);
    transition: all 0.3s;
}
.dimension-input:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}
.dimension-input label {
    display: block;
    font-size: 10px;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.dimension-input input {
    width: 100%;
    border: none;
    background: none;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--dark);
    font-family: inherit;
    outline: none;
}
.dimension-input span {
    font-size: 11px;
    color: #999;
    font-weight: 500;
}

/* ===== COLOR PICKER ===== */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 12px;
    margin-bottom: 10px;
}
.color-input {
    width: 50px; height: 50px;
    border: 3px solid white;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0,0,0,0.12);
    transition: all 0.3s;
}
.color-input:hover { transform: scale(1.1); }
.color-info { flex: 1; }
.color-name { font-size: 13px; font-weight: 600; color: var(--dark); margin-bottom: 2px; }
.color-hex { font-size: 11px; color: #999; font-family: 'Courier New', monospace; }

/* ===== PRESET COLORS ===== */
.preset-colors {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-top: 10px;
}
.preset-color {
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    transition: all 0.2s;
    position: relative;
}
.preset-color:hover { transform: scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.preset-color.active::after {
    content: '✓';
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: white; font-size: 16px; font-weight: bold;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* ===== LEG STYLES GRID ===== */
.leg-styles-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 10px;
}
.leg-style-card {
    padding: 14px 8px;
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    background: white;
}
.leg-style-card:hover { border-color: var(--primary); background: #f8f9ff; }
.leg-style-card.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, #f0f3ff, #fff);
    box-shadow: 0 4px 12px rgba(102,126,234,0.15);
}
.leg-style-icon { font-size: 28px; margin-bottom: 6px; }
.leg-style-name { font-size: 11px; font-weight: 600; color: var(--dark); }

/* ===== PART ITEM ===== */
.part-item {
    background: linear-gradient(135deg, #f8f9fa, #fff);
    padding: 18px;
    border-radius: 14px;
    margin-bottom: 12px;
    border-left: 4px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: all 0.3s;
}
.part-item:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.12);
}
.part-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== 3D VIEWER ===== */
#canvas-container {
    border-radius: var(--radius);
    overflow: hidden;
    background: linear-gradient(135deg, #eef1f5, #e2e6ed);
    box-shadow: inset 0 2px 12px rgba(0,0,0,0.08);
    position: relative;
    height: 560px;
}
canvas { display: block; cursor: grab; }
canvas:active { cursor: grabbing; }

.viewer-overlay {
    position: absolute;
    top: 16px; left: 16px;
    background: rgba(255,255,255,0.92);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 12px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 10;
}

.viewer-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 16px;
}

/* ===== STATS GRID ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 14px;
}
.stat-card {
    background: linear-gradient(135deg, #f8f9ff, #fff);
    padding: 12px 8px;
    border-radius: 12px;
    border: 2px solid var(--border);
    text-align: center;
}
.stat-value {
    font-size: 20px;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2px;
}
.stat-label { font-size: 10px; color: #888; font-weight: 600; }

/* ===== TEMPLATES ===== */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 12px;
}
.template-card {
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}
.template-card:hover {
    border-color: var(--primary);
    background: #f8f9ff;
    transform: scale(1.03);
}
.template-icon { font-size: 36px; margin-bottom: 8px; }
.template-name { font-size: 12px; font-weight: 600; color: var(--dark); }

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(6px);
}
.loading-overlay.show { display: flex; }
.loading-content {
    background: white;
    padding: 44px;
    border-radius: 20px;
    text-align: center;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}
.spinner {
    width: 64px; height: 64px;
    margin: 0 auto 20px;
    border: 5px solid #f0f0f0;
    border-top: 5px solid var(--primary);
    border-right: 5px solid var(--secondary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.progress-bar {
    width: 100%; height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 16px;
}
.progress-fill {
    height: 100%;
    background: var(--gradient);
    width: 0%;
    transition: width 0.3s;
}

/* ===== TOOLTIPS ===== */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute; bottom: 100%; left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85); color: white;
    padding: 6px 12px; border-radius: 8px;
    font-size: 11px; white-space: nowrap;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s; margin-bottom: 6px;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ===== MATERIAL GRID ===== */
.material-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}
.material-card {
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}
.material-card:hover { border-color: var(--primary); background: #f8f9ff; }
.material-card.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, #f0f3ff, #fff);
    box-shadow: 0 4px 12px rgba(102,126,234,0.15);
}
.material-icon { font-size: 28px; margin-bottom: 6px; }
.material-name { font-size: 12px; font-weight: 600; color: var(--dark); }

/* ===== ORDER FORM ===== */
.order-form { margin-top: 12px; }
.order-form input, .order-form textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 13px;
    margin-bottom: 10px;
    outline: none;
    transition: border-color 0.3s;
}
.order-form input:focus, .order-form textarea:focus {
    border-color: var(--primary);
}
.order-form textarea { resize: vertical; min-height: 70px; }

/* ===== MOBILE CONTROLS ===== */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 16px; left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 12px 20px;
    border-radius: 50px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    gap: 8px;
    z-index: 100;
}