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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overflow: hidden;
    background: #1a1a1a;
    color: #fff;
}

#app {
    width: 100vw;
    height: 100vh;
    display: grid;
    grid-template-columns: 60px 1fr;
    grid-template-rows: 50px 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar canvas";
}

/* Left Sidebar */
#sidebar {
    grid-area: sidebar;
    background: #252525;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 8px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.tool-button {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 8px;
    background: transparent;
    color: #999;
    transition: all 0.2s ease;
    position: relative;
}

.tool-button:hover {
    background: #333;
    color: #fff;
}

.tool-button.active {
    background: #4488ff;
    color: #fff;
}

.tool-button svg {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

/* Tooltips */
.tool-button::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 65px;
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.tool-button:hover::after {
    opacity: 1;
}

.tool-separator {
    width: 36px;
    height: 1px;
    background: #333;
    margin: 4px 0;
}

/* Top Bar */
#topbar {
    grid-area: topbar;
    background: #2a2a2a;
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    z-index: 50;
}

#units-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #ccc;
}

#units-selector label {
    font-weight: 500;
}

#unitsDropdown {
    padding: 6px 12px;
    background: #333;
    color: #fff;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

#unitsDropdown:hover {
    background: #3a3a3a;
    border-color: #555;
}

#unitsDropdown:focus {
    border-color: #4488ff;
    box-shadow: 0 0 0 2px rgba(68, 136, 255, 0.2);
}

#info {
    display: flex;
    gap: 20px;
    margin-left: auto;
    font-size: 14px;
    color: #ccc;
}

#info span {
    padding: 8px 15px;
    background: #333;
    border-radius: 4px;
}

/* Canvas Container */
#canvas-container {
    grid-area: canvas;
    position: relative;
    overflow: hidden;
}

#canvas3d {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

#labels {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#labels * {
    pointer-events: auto;
}

/* Instructions Panel */
#instructions {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(42, 42, 42, 0.95);
    padding: 20px;
    border-radius: 8px;
    max-width: 350px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
}

#instructions h3 {
    margin-bottom: 15px;
    color: #4488ff;
    font-size: 16px;
}

#instructions ul {
    list-style: none;
    padding: 0;
}

#instructions li {
    margin-bottom: 12px;
    line-height: 1.5;
    font-size: 13px;
    color: #ccc;
}

#instructions li strong {
    color: #fff;
    display: inline;
    margin-right: 4px;
}

/* Editable Measurement Labels */
.measurement-label {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.95);
    padding: 4px 8px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid #4488ff;
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.measurement-label:hover,
.measurement-label:focus-within {
    opacity: 1;
}

.measurement-input {
    width: 60px;
    padding: 4px 6px;
    font-size: 16px;
    font-weight: bold;
    color: #000;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    outline: none;
    font-family: 'Courier New', monospace;
    background: #fff;
}

.measurement-input:focus {
    border-color: #4488ff;
    box-shadow: 0 0 0 2px rgba(68, 136, 255, 0.2);
    background: #f0f8ff;
}

.measurement-input:hover {
    border-color: #66aaff;
}

.measurement-units {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    min-width: 20px;
}

/* Responsive design */
@media (max-width: 768px) {
    #app {
        grid-template-columns: 50px 1fr;
        grid-template-rows: 45px 1fr;
    }

    #sidebar {
        padding: 8px 0;
        width: 50px;
    }

    .tool-button {
        width: 38px;
        height: 38px;
    }

    .tool-button svg {
        width: 20px;
        height: 20px;
    }

    .tool-button::after {
        display: none; /* Hide tooltips on mobile */
    }

    #topbar {
        padding: 0 10px;
    }

    #info {
        gap: 10px;
        font-size: 12px;
    }

    #info span {
        padding: 6px 10px;
    }

    #instructions {
        top: auto;
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        padding: 15px;
    }

    #instructions h3 {
        font-size: 14px;
    }

    #instructions li {
        font-size: 12px;
    }
}

/* Loading state */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    color: #4488ff;
}

/* Keyboard shortcuts hint */
.keyboard-hint {
    color: #888;
    font-size: 11px;
    margin-left: 4px;
}

/* Grid Rotation Controls */
#grid-rotation-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(42, 42, 42, 0.95);
    padding: 10px 12px;
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
}

#grid-rotation-controls h4 {
    margin: 0 0 8px 0;
    color: #4488ff;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.rotation-axis {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-bottom: 4px;
}

.axis-label {
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    min-width: 12px;
    text-align: center;
}

.rotate-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    background: #333;
    color: #fff;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rotate-btn:hover {
    background: #4488ff;
    border-color: #4488ff;
    transform: scale(1.1);
}

.rotate-btn:active {
    transform: scale(0.9);
}

.reset-btn {
    width: 100%;
    padding: 6px;
    margin-top: 6px;
    background: #555;
    color: #fff;
    border: 1px solid #666;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    background: #ff4444;
    border-color: #ff4444;
}

.reset-btn:active {
    transform: scale(0.98);
}
