:root {
    --bg-dark: #0a0a0c;
    --card-bg: rgba(255, 255, 255, 0.05);
    --accent-color: #00e5ff;
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --glass-border: rgba(255, 255, 255, 0.1);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: scroll;
}

.app-container {
    position: relative;
    /* Added relative for fixed overlay */
    text-align: center;
    width: 100vw;
    max-width: 100vw;
}

h1 {
    font-weight: 300;
    letter-spacing: 2px;
    margin-bottom: 2rem;
    color: var(--accent-color);
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.canvas-wrapper {
    position: relative;
    border-radius: 16px;
    overflow: auto;
    /* Changed from hidden to auto */
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--glass-border);
    height: 70vh;
    /* Fixed height for scrolling */
    background: #000;
}

#webgl-canvas {
    display: block;
    cursor: crosshair;
}

.ui-overlay {
    position: relative;
    margin-top: 2px;
    padding: 0 2px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    z-index: 10;
}

.menu-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 0px 0px;
    display: flex;
    gap: 20px;
    z-index: 1000;
    border-radius: 0;
    border-top: none;
    border-left: none;
    border-right: none;
}

.menu-item {
    position: relative;
    cursor: pointer;
}

.menu-trigger {
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.menu-trigger:hover {
    color: var(--accent-color);
}

.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 100px;
    margin-top: 0px;
    padding: 0px 0;
    z-index: 1001;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-content a {
    display: block;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.3s;
}

.dropdown-content > a {
    padding: 4px 10px;
}

.dropdown-content a:hover {
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-color);
}

/* Nested submenu (e.g. Draw → Arc → …) opens to the right */
.dropdown-submenu-item {
    position: relative;
}

.submenu-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5em;
    padding: 4px 10px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: default;
    user-select: none;
    transition: background 0.3s, color 0.3s;
}

.submenu-trigger:hover {
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-color);
}

.submenu-chevron {
    display: inline-block;
    margin-left: 0.35em;
    opacity: 0.75;
    font-size: 1.1em;
    line-height: 1;
}

.dropdown-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    margin-left: 2px;
    min-width: 110px;
    padding: 4px 0;
    z-index: 1002;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.dropdown-submenu-item:hover .dropdown-submenu {
    display: block;
}

.dropdown-submenu a {
    display: block;
    padding: 4px 12px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.3s, color 0.3s;
}

.dropdown-submenu a:hover {
    background: rgba(0, 229, 255, 0.1);
    color: var(--accent-color);
}

.menu-divider {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 4px 0;
}

.coordinate-box,
.color-box,
.zoom-box,
.unit-box {
    display: flex;
    flex-direction: column;
    padding: 12px 20px;
    align-items: flex-start;
    gap: 8px;
    min-width: 150px;
    pointer-events: auto;
}

.color-box-row {
    min-width: 180px;
}

.coordinate-box {
    min-width: 300px;
}

#line-color,
#aci-select,
#unit-selector {
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    width: 100%;
    height: 30px;
    cursor: pointer;
    padding: 0 5px;
    color: var(--text-primary);
    outline: none;
}

#aci-select {
    cursor: default;
    font-size: 0.8rem;
}

#aci-select option {
    background: #1a1a1f;
    color: var(--text-primary);
}

#unit-selector option {
    background: #1a1a1f;
    color: var(--text-primary);
}

#line-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

#line-color::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.glass {
    background: rgba(15, 15, 20, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
}

.label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

#coord-input {
    background: transparent;
    border: none;
    color: var(--accent-color);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 1rem;
    width: 100%;
    outline: none;
    text-shadow: 0 0 5px rgba(0, 229, 255, 0.2);
}

.instruction {
    margin-top: 2rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

#coord-input:focus {
    animation: pulse 2s infinite ease-in-out;
}

/* Command Prompt Area */
.command-box {
    margin-top: 10px;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    text-align: left;
    width: auto;
    max-width: 100%;
}

.command-history {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-height: 80px;
    overflow-y: auto;
    width: 100%;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

.command-history div {
    margin-bottom: 2px;
}

.command-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.95rem;
}

.command-label {
    color: var(--accent-color);
    font-weight: bold;
}

#command-prompt-text {
    color: var(--accent-color);
    white-space: nowrap;
}

.command-input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.95rem;
    width: 100%;
    outline: none;
    caret-color: var(--accent-color);
}

.command-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.command-history::-webkit-scrollbar {
    width: 4px;
}

.command-history::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 2px;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    width: 400px;
    max-width: 90%;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.3s ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.modal-header h3 {
    margin: 0;
    font-weight: 400;
    font-size: 1rem;
    color: var(--accent-color);
}

#close-modal-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

#close-modal-btn:hover {
    color: var(--accent-color);
}

.modal-body {
    max-height: 300px;
    overflow-y: auto;
}

/* Hatch pattern picker: scrollable list fills modal (override generic .modal-body 300px cap). */
.hatch-pattern-modal-content {
    max-height: min(88vh, 100dvh - 2.5rem);
    display: flex;
    flex-direction: column;
}

.modal-body.hatch-pattern-modal-body {
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: 0.25rem;
}

.hatch-pattern-list {
    flex: 1 1 auto;
    min-height: 12rem;
    max-height: min(72vh, calc(100dvh - 10rem));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    font-size: 0.8rem;
    text-align: left;
    outline: none;
}

.hatch-pattern-row {
    padding: 6px 10px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.hatch-pattern-row:hover {
    background: rgba(0, 229, 255, 0.08);
}

.hatch-pattern-row.selected {
    background: rgba(0, 229, 255, 0.18);
    color: var(--accent-color);
}

.hatch-pattern-modal-footer {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 0.5rem;
}

.layer-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    /* Reduced font size */
}

.layer-table th {
    text-align: left;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 500;
    padding: 8px;
    border-bottom: 1px solid var(--glass-border);
    letter-spacing: 0.5px;
}

.layer-table td {
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.layer-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 0.5rem;
}

.ui-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.ui-button:hover {
    background: rgba(0, 229, 255, 0.2);
    border-color: var(--accent-color);
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Idle entity selection — properties popup (right-click on selection) */
.entity-props-popup {
    position: fixed;
    z-index: 2000;
    min-width: 220px;
    max-width: min(360px, calc(100vw - 16px));
    padding: 0;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    pointer-events: auto;
}

.entity-props-popup[hidden] {
    display: none !important;
}

.entity-props-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-color);
}

.entity-props-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
}

.entity-props-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.entity-props-body {
    padding: 10px 12px 12px;
    font-size: 0.82rem;
    color: var(--text-primary);
}

.entity-props-body dl {
    margin: 0;
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    gap: 6px 10px;
}

.entity-props-body dt {
    margin: 0;
    color: var(--text-secondary);
    font-weight: 500;
}

.entity-props-body dd {
    margin: 0;
    word-break: break-word;
}
.osnap-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 10px;
}

.osnap-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
    color: #ccc;
    transition: color 0.2s;
}

.osnap-options label:hover {
    color: #fff;
}

.osnap-options input[type='checkbox'] {
    accent-color: #00ffff;
    width: 16px;
    height: 16px;
}
