/* Polargraph - Minimal Grey Frame UI */

:root {
    --page-bg: #ffffff;
    --frame-bg: #ebebeb;
    --frame-border: rgba(0,0,0,0.08);
    --body-bg: #ffffff;
    --body-border: rgba(0,0,0,0.08);
    --text-dark: #1a1a1a;
    --text-mid: #555555;
    --text-light: #888888;
    --text-faint: #bbbbbb;
    --border: rgba(0,0,0,0.1);
    --border-light: rgba(0,0,0,0.06);
    --hover: rgba(0,0,0,0.04);
    --active: rgba(0,0,0,0.06);
    --danger-bg: rgba(180, 60, 60, 0.1);
    --danger-text: #a44;
    --success: #4a4;
    --panel-width: 260px;
    --header-height: 40px;
    --frame-padding-top: 14px;
    --frame-padding-side: 8px;
    --frame-padding-bottom: 8px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'SF Mono', 'Monaco', 'Consolas', monospace;
    
    /* Frame colors - light warm beige like reference */
    --wood-color: #e5d7ba;
    --wood-border: rgba(0, 0, 0, 0.06);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 400;
    color: var(--text-dark);
    background: var(--page-bg);
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

/* Outer Frame - grey box on white page */
.outer-frame {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    background: var(--frame-bg);
    border: 1px solid var(--frame-border);
    border-radius: 16px 16px 8px 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header Bar */
.header-bar {
    height: var(--header-height);
    background: var(--frame-bg);
    padding: 0 var(--frame-padding-side);
    padding-right: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    margin-left: 8px;
}

.header-title {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    opacity: 0.5;
    letter-spacing: -0.01em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0;
}

.nav-item {
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 450;
    color: var(--text-mid);
    padding: 6px 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
}

.nav-item:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-dark);
}

.nav-item.active {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-dark);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #dc6b6b;
    margin-left: 12px;
}

.status-dot.connected {
    background: #4aba6a;
}

.status-dot.remote {
    background: #e6a23c;
}

.status-label {
    font-family: var(--font);
    font-size: 12px;
    font-weight: 450;
    color: var(--text-mid);
    margin-left: 6px;
}

/* Main Container */
.main-container {
    flex: 1;
    display: flex;
    min-height: 0;
    padding: 0 var(--frame-padding-side) var(--frame-padding-bottom) var(--frame-padding-side);
}

/* White Body Panel */
.body-panel {
    flex: 1;
    background: var(--body-bg);
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    position: relative;
    overflow: hidden;
    transition: flex 0.25s ease;
}

/* Workspace Container - handles overflow and centering */
.workspace-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
}

/* Transform wrapper for zooming */
.workspace-transform {
    transform-origin: center center;
    transition: transform 0.2s ease;
}

/* Polargraph Frame - vertical rectangle 48x60 ratio */
.polargraph-frame {
    /* 48:60 = 0.8 aspect ratio (width/height) */
    /* Fill ~85% of container height */
    height: 85vh;
    max-height: 700px;
    aspect-ratio: 48 / 60;
    background: var(--wood-color);
    border: 2px solid var(--wood-border);
    padding: 16px;
    box-shadow: 
        0 12px 40px rgba(0, 0, 0, 0.15),
        0 4px 12px rgba(0, 0, 0, 0.08);
    position: relative;
}

/* Paper sheet - A0 proportions (841x1189mm ≈ 0.707 ratio) */
.paper-sheet {
    width: 100%;
    height: 100%;
    background: #fafaf8;
    border-radius: 1px;
    box-shadow: 
        0 1px 4px rgba(0, 0, 0, 0.1),
        inset 0 0 0 1px rgba(0, 0, 0, 0.03);
    overflow: hidden;
}

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

/* Floating Create Menu */
.create-menu {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 240px;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 20px;
    box-shadow: 
        0 12px 40px rgba(0, 0, 0, 0.12),
        0 4px 12px rgba(0, 0, 0, 0.06);
    padding: 16px;
    z-index: 100;
    max-height: 75%;
    overflow-y: auto;
    cursor: default;
    user-select: none;
}

.create-menu.dragging {
    cursor: grabbing;
    opacity: 0.95;
}

.menu-header {
    cursor: grab;
    padding: 2px 0 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-header:active {
    cursor: grabbing;
}

.drag-handle {
    width: 28px;
    height: 3px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 2px;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 16px;
}

.mode-btn {
    flex: 1;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: 9px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 450;
    color: var(--text-mid);
    cursor: pointer;
    transition: all 0.15s;
}

.mode-btn:hover {
    color: var(--text-dark);
}

.mode-btn.active {
    background: #fff;
    color: var(--text-dark);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Menu Content */
.menu-content {
    min-height: 60px;
}

.mode-content {
    display: none;
}

.mode-content.active {
    display: block;
}

.menu-select {
    width: 100%;
    height: 38px;
    padding: 0 14px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 12px;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-dark);
    cursor: pointer;
    margin-bottom: 12px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

.menu-select:focus {
    outline: none;
    background-color: rgba(0, 0, 0, 0.06);
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
}

.menu-options:empty {
    display: none;
    margin: 0;
}

.menu-btn {
    width: 100%;
    height: 38px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 12px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 450;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.12s;
}

.menu-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.menu-btn.primary {
    background: var(--text-dark);
    color: #fff;
}

.menu-btn.primary:hover {
    background: #333;
}

.menu-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Button Spinner */
.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* Upload Drop Zone */
.upload-drop {
    border: 2px dashed rgba(0, 0, 0, 0.12);
    border-radius: 14px;
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}

.upload-drop:hover {
    border-color: rgba(0, 0, 0, 0.2);
    background: rgba(0, 0, 0, 0.02);
}

.upload-drop.dragover {
    border-color: var(--text-mid);
    background: rgba(0, 0, 0, 0.04);
}

.upload-drop span {
    font-size: 12px;
    color: var(--text-light);
}

/* Convert Section */
.convert-section {
    margin-top: 0;
}

.convert-preview {
    aspect-ratio: 4/3;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 14px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: all 0.15s;
}

.convert-preview:hover {
    background: rgba(0, 0, 0, 0.06);
}

.convert-preview:hover::after {
    content: 'Click to replace';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: rgba(0,0,0,0.5);
    background: rgba(255,255,255,0.9);
    padding: 4px 10px;
    border-radius: 10px;
}

.convert-preview.dragover {
    background: rgba(0, 0, 0, 0.08);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15);
}

.convert-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
}

/* File Preview (for G-code/SVG) */
.file-preview {
    text-align: center;
    padding: 20px;
}

.file-icon {
    font-size: 36px;
    margin-bottom: 8px;
}

.file-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 4px;
    word-break: break-all;
}

.file-info {
    font-size: 11px;
    color: var(--text-light);
}

/* Import Mode Selector */
.import-mode-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.import-mode-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
}

.import-mode-option:hover {
    background: rgba(0, 0, 0, 0.06);
}

.import-mode-option input[type="radio"] {
    margin-top: 2px;
    accent-color: var(--text-dark);
}

.import-mode-option .mode-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.import-mode-option .mode-label strong {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dark);
}

.import-mode-option .mode-label small {
    font-size: 10px;
    color: var(--text-light);
    line-height: 1.3;
}

.import-notice {
    background: rgba(74, 170, 74, 0.1);
    color: #3a8a3a;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 11px;
    margin-bottom: 12px;
}

.import-info {
    padding: 8px 0;
}

.import-info p {
    font-size: 11px;
    color: var(--text-light);
    text-align: center;
}

/* Menu Footer */
.menu-footer {
    margin-top: 8px;
}

.menu-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 10px 0;
}

.export-row {
    display: flex;
    gap: 6px;
}

.export-row .menu-btn {
    flex: 1;
    height: 30px;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.zoom-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-mid);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s;
}

.zoom-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-dark);
}

.zoom-level {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-mid);
    min-width: 40px;
    text-align: center;
}

/* Canvas Info */
.canvas-info {
    position: absolute;
    right: 20px;
    bottom: 20px;
    display: flex;
    gap: 10px;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.canvas-info strong {
    color: var(--text-mid);
    font-weight: 500;
}

.info-sep {
    color: var(--text-faint);
}

/* ============================================
   Side Panel Styles (Machine/Console/Settings)
   ============================================ */

/* Side Panel - expands grey border on right */
.side-panel {
    width: 0;
    overflow: hidden;
    transition: width 0.25s ease, padding 0.25s ease;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.side-panel.open {
    width: var(--panel-width);
    padding: 0 0 0 12px;
}

.panel-content {
    display: none;
    flex-direction: column;
    gap: 14px;
    height: 100%;
    overflow-y: auto;
    padding-right: 4px;
}

.panel-content.active {
    display: flex;
}

#panel-console {
    height: 100%;
}

#panel-console .console-box {
    flex: 1;
    min-height: 200px;
}

.panel-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.section-title {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-light);
    margin-bottom: 12px;
}

/* Form Elements - matching floating menu style */
.row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.input-select {
    flex: 1;
    height: 38px;
    padding: 0 14px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 12px;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-dark);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

.input-select:focus {
    outline: none;
    background-color: rgba(0, 0, 0, 0.06);
}

.input-text {
    flex: 1;
    height: 38px;
    padding: 0 14px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 12px;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-dark);
}

.input-text:focus {
    outline: none;
    background-color: rgba(0, 0, 0, 0.06);
}

.input-num {
    width: 80px;
    height: 32px;
    padding: 0 10px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 10px;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-dark);
    text-align: right;
}

.input-num:focus {
    outline: none;
    background-color: rgba(0, 0, 0, 0.06);
}

/* Buttons - matching floating menu style */
.btn {
    height: 38px;
    padding: 0 16px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 12px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 450;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.12s;
}

.btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn.full {
    width: 100%;
}

.btn.primary {
    background: var(--text-dark);
    color: #fff;
}

.btn.primary:hover {
    background: #333;
}

.btn.estop {
    background: var(--danger-bg);
    color: var(--danger-text);
    font-weight: 500;
}

.btn.estop:hover {
    background: rgba(180, 60, 60, 0.15);
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 12px;
    font-size: 14px;
    color: var(--text-mid);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.08);
}

.btn-icon:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Icon buttons */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.icon-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.btn-icon svg {
    width: 14px;
    height: 14px;
}

.play-btn {
    background: var(--text-dark);
    color: #fff;
}

.play-btn:hover {
    background: #333;
}

.estop-section {
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
}

/* Jog Controls */
.jog-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.jog-btn {
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 10px;
    font-size: 14px;
    color: var(--text-mid);
    cursor: pointer;
    transition: all 0.12s;
}

.jog-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.jog-btn:active {
    background: var(--text-dark);
    color: #fff;
}

.jog-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.jog-btn.jogging {
    opacity: 0.5;
    pointer-events: none;
    background: rgba(0, 120, 200, 0.1);
}

.jog-center {
    background: rgba(0, 0, 0, 0.02);
}

.dist-row {
    display: flex;
    gap: 6px;
}

.dist-btn {
    flex: 1;
    height: 28px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 450;
    color: var(--text-mid);
    cursor: pointer;
    transition: all 0.12s;
}

.dist-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.dist-btn.active {
    background: var(--text-dark);
    color: #fff;
}

/* Progress */
.progress-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--text-dark);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-mid);
    min-width: 36px;
}

.plot-btns {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}

.plot-status {
    text-align: center;
    font-size: 11px;
    color: var(--text-light);
}

.plot-eta {
    text-align: center;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-mid);
    margin-top: 4px;
    min-height: 14px;
}

.eta-estimate {
    color: var(--text-light);
}

.eta-elapsed {
    color: var(--accent);
}

.eta-remaining {
    color: var(--text-mid);
}

/* Console - white bg card style matching other panels */
#panel-console {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    display: none;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

#panel-console.active {
    display: flex;
}

.console-box {
    flex: 1;
    min-height: 0;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.7;
    color: var(--text-dark);
    overflow-y: auto;
}

/* All console text in greys/blacks */
.console-box .msg-in { color: #666; }
.console-box .msg-out { color: #333; }
.console-box .msg-error { color: #888; }

.console-row {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.console-row .input-text {
    flex: 1;
    min-width: 0;
}

.console-row .btn {
    flex-shrink: 0;
    width: auto;
    padding: 0 14px;
}

/* Setting Row */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}

.setting-row label {
    font-size: 12px;
    color: var(--text-mid);
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 2px; }

/* Form Group for dynamic options */
.form-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
}

.form-group label {
    font-size: 12px;
    color: var(--text-mid);
    flex: 1;
    text-transform: capitalize;
}

.form-group input[type="number"],
.form-group input[type="text"] {
    width: 80px;
    height: 32px;
    padding: 0 10px;
    background: rgba(0,0,0,0.04);
    border: none;
    border-radius: 10px;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-dark);
    text-align: right;
}

.form-group input:focus {
    outline: none;
    background: rgba(0,0,0,0.06);
}

.form-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--text-dark);
}

/* Collapsible Settings Section */
.collapsible-settings {
    margin-top: 8px;
    border-top: 1px solid var(--border-light);
    padding-top: 8px;
}

.collapsible-settings summary {
    cursor: pointer;
    font-size: 11px;
    color: var(--text-light);
    user-select: none;
    padding: 4px 0;
}

.collapsible-settings summary:hover {
    color: var(--text-mid);
}

.collapsible-settings[open] summary {
    margin-bottom: 4px;
}

.collapsible-settings .settings-container {
    padding-left: 0;
}

/* ============================================
   Color Picker
   ============================================ */

.color-picker-section {
    margin-bottom: 14px;
}

.section-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.active {
    border-color: var(--text-dark);
    box-shadow: 0 0 0 2px rgba(255,255,255,1), 0 0 0 4px rgba(0,0,0,0.15);
}

.color-swatch::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.1);
}

/* ============================================
   Entity List
   ============================================ */

.entity-list-section {
    margin-top: 8px;
}

.entity-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 180px;
    overflow-y: auto;
}

.entity-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.12s;
    border: 2px solid transparent;
}

.entity-item:hover {
    background: rgba(0, 0, 0, 0.06);
}

.entity-item.selected {
    background: rgba(0, 0, 0, 0.06);
    border-color: var(--text-dark);
}

.entity-color {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.1);
}

.entity-name {
    flex: 1;
    font-size: 12px;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: text;
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 3px;
    transition: background 0.15s;
}

.entity-name:hover {
    background: rgba(0, 0, 0, 0.05);
}

.entity-info {
    font-size: 10px;
    color: var(--text-light);
    font-family: var(--font-mono);
}

.entity-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.12s;
}

.entity-item:hover .entity-actions {
    opacity: 1;
}

.entity-action-btn {
    width: 22px;
    height: 22px;
    background: rgba(0,0,0,0.06);
    border: none;
    border-radius: 5px;
    font-size: 11px;
    color: var(--text-mid);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s;
}

.entity-action-btn:hover {
    background: rgba(0,0,0,0.12);
    color: var(--text-dark);
}

.entity-action-btn.delete:hover {
    background: rgba(180, 60, 60, 0.15);
    color: var(--danger-text);
}

/* Entity visibility toggle */
.entity-visibility-btn {
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    padding: 0;
    font-size: 12px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.12s;
    flex-shrink: 0;
}

.entity-visibility-btn:hover {
    opacity: 1;
}

.entity-visibility-btn.visible {
    opacity: 0.8;
}

.entity-item.hidden-entity {
    opacity: 0.5;
}

.entity-item.hidden-entity .entity-name {
    text-decoration: line-through;
    color: var(--text-mid);
}

/* Entity inline rename input */
.entity-name-input {
    flex: 1;
    font-size: 12px;
    font-family: var(--font);
    color: var(--text-dark);
    background: white;
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 2px 6px;
    outline: none;
    min-width: 0;
}

/* ============================================
   Context Menu (Right-click)
   ============================================ */

.context-menu {
    position: absolute;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 12px;
    box-shadow: 
        0 12px 40px rgba(0, 0, 0, 0.15),
        0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 6px;
    z-index: 1000;
    min-width: 180px;
}

.context-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 12px;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.12s;
    text-align: left;
}

.context-item:hover {
    background: rgba(0, 0, 0, 0.06);
}

.context-item.context-delete:hover {
    background: rgba(180, 60, 60, 0.1);
    color: var(--danger-text);
}

.context-icon {
    width: 18px;
    text-align: center;
    font-size: 14px;
    color: var(--text-mid);
}

.context-delete .context-icon {
    color: inherit;
}

.context-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 4px 8px;
}

.context-submenu {
    padding: 8px 12px;
}

.context-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-light);
    margin-bottom: 8px;
    display: block;
}

.context-colors {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.context-color {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.12s;
    position: relative;
}

.context-color:hover {
    transform: scale(1.15);
}

.context-color.active {
    border-color: var(--text-dark);
}

.context-color::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
}

.context-shortcut {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-light);
    font-family: var(--font-mono);
}

.transform-controls {
    display: flex;
    flex-direction: column;
}

.transform-controls .context-item {
    padding: 8px 12px;
}

/* Export info */
.export-info {
    margin-top: 8px;
    font-size: 10px;
    color: var(--text-light);
    text-align: center;
}

/* ============================================
   Entity Selection Highlight on Canvas
   ============================================ */

.entity-selected-indicator {
    pointer-events: none;
    position: absolute;
}

/* Generator dropdown scrollable - not the whole menu */
.menu-bar select {
    max-height: 200px;
}

/* Make the generator select dropdown options scrollable */
.menu-bar select option {
    padding: 4px 8px;
}

/* Style the dropdown to show scroll indicator */
#generatorSelect {
    max-width: 100%;
}


/* Location Map for Geodata Weaving */
.location-map-group {
    display: block !important;
    width: 100% !important;
    margin-bottom: 12px;
    padding: 0 !important;
}

.location-map-group > * {
    width: 100% !important;
}

.location-map-container {
    width: 100% !important;
    height: 160px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
    position: relative;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.location-map-container #locationMap {
    width: 100%;
    height: 100%;
    background: #e8e8e8;
    /* Grayscale filter for the map */
    filter: grayscale(100%) contrast(1.1);
    -webkit-filter: grayscale(100%) contrast(1.1);
}

.location-coords {
    display: block;
    width: 100%;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-light);
    text-align: center;
    margin-bottom: 12px;
    padding: 4px 0;
    font-family: var(--font-mono);
}

/* Override Leaflet default styles for compact map */
.location-map-container .leaflet-control-zoom {
    margin: 5px !important;
}

.location-map-container .leaflet-control-zoom a {
    width: 24px !important;
    height: 24px !important;
    line-height: 24px !important;
    font-size: 14px !important;
}

.location-map-container .leaflet-control-attribution {
    display: none !important;
}

.location-marker-icon {
    background: transparent !important;
    border: none !important;
}

/* ============================================================================
   Modal Styles
   ============================================================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--body-bg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-height: 90vh;
    overflow-y: auto;
    width: 90%;
    max-width: 400px;
}

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

.modal-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-light);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-dark);
}

.modal-body {
    padding: 20px;
}

/* ============================================================================
   Calibration Wizard Styles
   ============================================================================ */

.calibration-step p {
    margin-bottom: 12px;
    line-height: 1.5;
    color: var(--text-mid);
}

.calibration-step p strong {
    color: var(--text-dark);
}

.calibration-jog {
    background: var(--frame-bg);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.jog-grid.mini {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-width: 150px;
    margin: 0 auto 12px;
}

.jog-grid.mini .jog-btn {
    width: 44px;
    height: 44px;
    font-size: 16px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.jog-step-select {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

.jog-step-select label {
    font-size: 11px;
    color: var(--text-light);
}

.jog-step-select select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    background: white;
}

.calib-distance {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-light);
    text-align: center;
    margin: 8px 0 !important;
}

.calib-results {
    background: var(--frame-bg);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.calib-results p {
    margin-bottom: 4px !important;
    font-size: 12px;
}

.calib-results span {
    font-family: var(--font-mono);
    color: var(--text-dark);
}

.calib-input-group {
    margin-bottom: 12px;
}

.calib-input-group label {
    display: block;
    font-size: 12px;
    color: var(--text-mid);
    margin-bottom: 4px;
}

.calib-input-group input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-family: var(--font-mono);
}

/* =========================================================================
   SHEET MUSIC CUSTOM UI
   ========================================================================= */

.sheetmusic-ui {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* MIDI Upload Drop Zone */
.midi-upload-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-light);
}

.midi-upload-zone:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.midi-upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(var(--accent-rgb), 0.1);
    border-style: solid;
}

.midi-upload-zone .upload-icon {
    color: var(--text-mid);
    margin-bottom: 8px;
}

.midi-upload-zone .upload-text {
    font-size: 12px;
    color: var(--text-mid);
}

/* Search Section */
.midi-search-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.midi-search-section label {
    font-size: 12px;
    color: var(--text-mid);
}

.search-input-wrapper {
    position: relative;
}

.midi-search-input {
    width: 100%;
    padding: 8px 10px;
    padding-right: 30px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: var(--bg-light);
    color: var(--text-dark);
}

.midi-search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-spinner {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Search Results */
.midi-search-results {
    max-height: 180px;
    overflow-y: auto;
    border-radius: 4px;
}

.search-result-item {
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-top: none;
    transition: background 0.15s ease;
}

.search-result-item:first-child {
    border-top: 1px solid var(--border);
    border-radius: 4px 4px 0 0;
}

.search-result-item:last-child {
    border-radius: 0 0 4px 4px;
}

.search-result-item:only-child {
    border-radius: 4px;
}

.search-result-item:hover {
    background: var(--bg-hover);
}

.search-result-item .result-title {
    font-size: 13px;
    color: var(--text-dark);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-item .result-source {
    font-size: 10px;
    color: var(--text-mid);
    background: var(--bg-mid);
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
}

.search-no-results,
.search-error,
.search-loading {
    padding: 12px;
    text-align: center;
    font-size: 12px;
    color: var(--text-mid);
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.search-error {
    color: var(--error);
}

.search-error a {
    color: var(--accent);
    text-decoration: underline;
}

/* Selected Song Display */
.midi-selected {
    background: var(--bg-light);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 12px;
}

.midi-selected .selected-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.midi-selected .selected-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dark);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.clear-selection-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-mid);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.clear-selection-btn:hover {
    color: var(--error);
}

/* Time Range Options */
.time-range-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
}

.time-range-options .form-group {
    margin: 0;
}

.time-range-options .form-group label {
    display: block;
    font-size: 11px;
    color: var(--text-mid);
    margin-bottom: 4px;
}

.time-range-options .form-group input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: var(--bg-mid);
    color: var(--text-dark);
}

.time-range-options .hint {
    display: block;
    font-size: 10px;
    color: var(--text-mid);
    margin-top: 2px;
}
