/* ==========================================================================
   Lego Phone Case Configurator - Style Sheet
   Theme: Sleek Dark Glassmorphism, Outfit Typography, Vibrant LEGO Accent Glows
   ========================================================================== */

:root {
    --bg-main: #0B0E14;
    --bg-card: rgba(18, 22, 32, 0.65);
    --bg-input: rgba(30, 36, 50, 0.5);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #F3F4F6;
    --text-secondary: #9CA3AF;
    
    /* Lego Theme Accent Colors */
    --accent-orange: #FF6B00;
    --accent-orange-glow: rgba(255, 107, 0, 0.35);
    --accent-blue: #00A3FF;
    --accent-green: #00E575;
    --accent-red: #FF3B30;
    
    --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Grid scaling factor: 1mm = 4px */
    --scale: 4px;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* App Layout Grid */
.app-container {
    display: grid;
    grid-template-columns: 340px 1fr 340px;
    height: 100vh;
    background: radial-gradient(circle at 50% 50%, #161B26 0%, #0B0E14 100%);
}

/* ==========================================================================
   SIDEBAR: Tile Catalogue
   ========================================================================== */
.sidebar {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow: hidden;
    height: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-shrink: 0; /* Prevents logo from squishing */
}

.logo-icon {
    font-size: 28px;
    animation: bounce 2s infinite ease-in-out;
}

.brand h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #FFF 0%, #9CA3AF 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Search Box */
.search-box-container {
    margin-bottom: 16px;
    flex-shrink: 0; /* Prevents search bar from squishing */
}

#search-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: var(--transition-smooth);
}

#search-input:focus {
    border-color: var(--accent-orange);
    box-shadow: 0 0 12px var(--accent-orange-glow);
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    margin-bottom: 20px;
    padding-bottom: 8px;
    flex-shrink: 0; /* Prevents tab list from squishing */
}

.category-tabs::-webkit-scrollbar {
    height: 4px;
}

.category-tabs::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.tab-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition-smooth);
}

.tab-btn:hover, .tab-btn.active {
    background: rgba(255, 107, 0, 0.1);
    border-color: var(--accent-orange);
    color: var(--text-primary);
}

/* Catalog Card Grid */
.catalog-grid {
    flex-grow: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: max-content; /* Critical fix: Prevents collapsing grid items */
    gap: 12px;
    padding-right: 4px;
}

.catalog-grid::-webkit-scrollbar {
    width: 6px;
}

.catalog-grid::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Catalog Card */
.catalog-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--transition-smooth);
}

.catalog-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-blue);
    background: rgba(0, 163, 255, 0.03);
}

.catalog-card.selected {
    border-color: var(--accent-orange);
    background: rgba(255, 107, 0, 0.06);
    box-shadow: 0 0 15px rgba(255, 107, 0, 0.12);
}

.catalog-card .tile-preview {
    width: 60px;
    height: 60px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.catalog-card h4 {
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 4px;
    text-align: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.2px;
}

.catalog-card .tile-meta {
    font-size: 10px;
    color: var(--text-secondary);
}

/* ==========================================================================
   CANVAS: Phone Case Workspace
   ========================================================================== */
.canvas-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
}

.canvas-header {
    text-align: center;
    margin-bottom: 30px;
}

.canvas-header h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
}

.canvas-header p {
    font-size: 13px;
    color: var(--text-secondary);
}

.case-wrapper {
    position: relative;
    padding: 20px;
}

/* CMF Phone 2 Pro Shell */
.phone-case-shell {
    width: calc(78 * var(--scale));
    height: calc(164 * var(--scale));
    background: linear-gradient(145deg, #E65A00 0%, #B84800 100%);
    border-radius: calc(9 * var(--scale));
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5), inset 0 2px 4px rgba(255,255,255,0.2);
    position: relative;
    overflow: hidden;
    border: 3px solid #993B00;
}

/* Excluded cutouts */
.cutout {
    position: absolute;
    background: var(--bg-main);
    border: 2px solid #993B00;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.8);
    pointer-events: none;
}

/* Main Camera Pill */
.camera-main {
    width: calc(20 * var(--scale));
    height: calc(41 * var(--scale));
    left: calc(1.25 * var(--scale));
    top: calc(2.2 * var(--scale));
    border-radius: calc(9.5 * var(--scale));
}

/* Camera Sensor Pill */
.camera-sensor {
    width: calc(10.60 * var(--scale));
    height: calc(22 * var(--scale));
    left: calc(22.55 * var(--scale));
    top: calc(12.7 * var(--scale));
    border-radius: calc(5.0 * var(--scale));
}

/* Dial Recess Cutout (Bottom Right) */
.dial-recess {
    width: calc(20 * var(--scale));
    height: calc(20 * var(--scale));
    left: calc(58 * var(--scale));
    bottom: calc(0 * var(--scale));
    border-radius: 50%;
}

/* Screw Holes */
.screw-hole {
    position: absolute;
    width: calc(4.6 * var(--scale));
    height: calc(4.6 * var(--scale));
    border-radius: 50%;
    background: #252830;
    border: 1px solid #1E2026;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
    pointer-events: none;
    transform: translate(-50%, 50%); /* Match bottom-left translate logic */
}

/* Coordinates from bottom-left */
.sh-bl { left: calc(3.9 * var(--scale)); bottom: calc(18.10 * var(--scale)); }
.sh-tl { left: calc(3.9 * var(--scale)); bottom: calc(116.53 * var(--scale)); }
.sh-tr { left: calc(73.9 * var(--scale)); bottom: calc(116.53 * var(--scale)); }
.sh-tm { left: calc(23.96 * var(--scale)); bottom: calc(160.11 * var(--scale)); }
.sh-br { left: calc(68.0 * var(--scale)); bottom: calc(10.0 * var(--scale)); }

/* Studs Grid Overlay */
.studs-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Stud */
.stud {
    position: absolute;
    width: calc(4.85 * var(--scale));
    height: calc(4.85 * var(--scale));
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.15);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    transform: translate(-50%, 50%); /* Fits coordinates */
    cursor: pointer;
    transition: var(--transition-smooth);
}

.stud:hover {
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

.stud.disabled {
    background: transparent;
    border: 1px dashed rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

/* Placement Preview States */
.stud.preview-valid {
    background: rgba(0, 229, 117, 0.4) !important;
    border-color: var(--accent-green) !important;
    box-shadow: 0 0 10px var(--accent-green) !important;
}

.stud.preview-invalid {
    background: rgba(255, 59, 48, 0.4) !important;
    border-color: var(--accent-red) !important;
    box-shadow: 0 0 10px var(--accent-red) !important;
}

/* Placed Tiles Layer */
.placed-tiles-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.placed-tile {
    position: absolute;
    border-radius: 6px;
    border: 1.5px solid rgba(0,0,0,0.45);
    box-shadow: 0 6px 14px rgba(0,0,0,0.35);
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease-out;
}

.placed-tile:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 18px rgba(0,0,0,0.45);
    z-index: 10;
}

.placed-tile.selected {
    outline: 2px solid var(--accent-orange);
    box-shadow: 0 0 18px rgba(255, 107, 0, 0.55);
}

/* ==========================================================================
   CONTROL PANEL: Inspector & Exporter
   ========================================================================== */
.control-panel {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow: hidden;
    height: 100%;
}

.panel-section {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
}

.panel-section.flex-grow {
    flex-grow: 1;
    overflow: hidden;
}

.panel-section h3 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Inspector Card */
.inspector-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.placeholder-text {
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    line-height: 1.5;
}

.inspector-details-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inspector-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.inspector-label {
    color: var(--text-secondary);
}

.inspector-value {
    font-weight: 600;
}

/* Exporter Code Panel */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.section-header h3 {
    margin-bottom: 0;
}

.copy-btn {
    background: rgba(255, 107, 0, 0.15);
    border: 1px solid var(--accent-orange);
    color: var(--accent-orange);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.copy-btn:hover {
    background: var(--accent-orange);
    color: var(--text-primary);
}

.code-export-container {
    flex-grow: 1;
    background: #06090F;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    overflow: auto;
    font-family: 'Courier New', Courier, monospace;
}

.code-export-container pre {
    margin: 0;
}

.code-export-container code {
    font-size: 11px;
    line-height: 1.6;
    color: #00E575;
}

/* Buttons */
.btn-primary {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition-smooth);
}

.btn-primary:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--accent-red);
    color: #FF8F8F;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--accent-red);
    color: #FF8F8F;
    padding: 8px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    transition: var(--transition-smooth);
}

.btn-danger:hover {
    background: var(--accent-red);
    color: var(--text-primary);
}

/* Notification Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #00E575;
    color: #000;
    font-weight: 700;
    padding: 12px 24px;
    border-radius: 30px;
    box-shadow: 0 10px 20px rgba(0, 229, 117, 0.3);
    z-index: 1000;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* SVG Rendering Icons inside UI */
.svg-icon {
    width: 100%;
    height: 100%;
}

/* Shake animation for invalid stud placement */
@keyframes shake {
    0%, 100% { transform: translate(-50%, 50%); }
    20%, 60% { transform: translate(-55%, 50%); }
    40%, 80% { transform: translate(-45%, 50%); }
}
.stud.shake {
    animation: shake 0.3s ease-in-out;
    border-color: var(--accent-red);
    box-shadow: 0 0 10px rgba(255, 59, 48, 0.6);
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}
