/* =========================================================================
   editor.css — SVG Editor styles
   Loaded ONLY by b-spline-gen pages (b-spline-gen/html/index.html and
   b-spline-gen/html/bspline_gen_palette.html). The SVG editor modal lives
   inside those pages and uses these tool/handle/keyboard styles plus
   responsive overrides for narrow viewports.
   ========================================================================= */

/* IMPORTANT — bundled symbol-font @font-face rules are NOT defined here.
   They are injected at runtime by editor-fonts.js (injectFontFaceRules)
   so that the family→file mapping has a single source of truth shared
   with the opentype.js stamp pipeline in editor-geometry.js. Do not add
   static @font-face declarations for Symbol / Wingdings / Webdings /
   Segoe UI Symbol / Segoe MDL2 Assets / Segoe Fluent Icons / Segoe UI
   Emoji here — that's exactly the duplication we removed.
   If symbol glyphs render as plain Latin on iOS again, the Symbol
   Keyboard's runtime self-test will display a warning banner pointing
   at editor-fonts.js. Start there. */

/* Symbol Keyboard runtime warning banner (shown by populateSymbolKeyboard
   via setKeyboardFontWarning when verifyFontLoaded() fails). */
.editor-symbol-keyboard-warning {
    flex-shrink: 0;
    padding: 6px 10px;
    background: #fff3cd;
    color: #856404;
    border-bottom: 1px solid #ffeeba;
    font-size: 11px;
    line-height: 1.3;
    font-weight: 500;
}

#svgEditorModal {
    z-index: 2000;
}

/* Native CAD Overhaul Modal Overlay */
.cad-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.4);
    align-items: center;
    justify-content: center;
    z-index: 9999 !important;
}

.cad-modal-window.overhauled {
    box-shadow: none !important;
    border: none !important;
    background: #fdfdfd !important;
    border-radius: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Tool Buttons */
.tool-btn {
    width: 34px;
    height: 34px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    background: transparent;
    border: 1px solid transparent;
    padding: 0;
    outline: none;
}

.tool-btn:hover {
    background: #eee;
    color: #333;
}

.tool-btn.active {
    background: var(--cad-accent) !important;
    color: white !important;
    border-color: var(--cad-accent) !important;
}

#toolSelect .material-symbols-outlined {
    font-variation-settings: 'FILL' 1; /* Solid Black Cursor */
}

#toolNode .material-symbols-outlined {
    font-variation-settings: 'FILL' 0; /* Outline White Cursor */
}

.tool-btn .material-symbols-outlined {
    font-size: 20px;
}

/* Top View Canvas Scaling */
#svgEditorTopView {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    pointer-events: none;
    opacity: 0.85;
}

/* SVG Drawing Area */
#editorCanvasContainer {
    transition: padding-bottom 0.1s ease-out;
}

#editorSVGContainer {
    cursor: crosshair;
}

#editorSVGContainer.mode-select { cursor: default; }
#editorSVGContainer.mode-node { cursor: default; }

/* Handle/Node Styles */
.svg-handle {
    fill: #fff;
    stroke: var(--cad-accent);
    stroke-width: 0.5px;
}

.svg-handle:hover {
    fill: var(--cad-accent);
    stroke: #fff;
}

/* 2-STATE RESPONSIVE: NARROW MODE */
@media (max-width: 720px) {
    .cad-modal-window.overhauled {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }

    .cad-modal-body {
        flex-direction: column !important;
    }

    .editor-sidebar {
        width: 100% !important;
        height: auto !important;
        flex-direction: row !important;
        padding: 6px 12px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--cad-border-standard) !important;
        justify-content: flex-start !important;
        overflow-x: auto !important;
        gap: 8px !important;
        white-space: nowrap !important;
    }

    .tool-divider {
        width: 1px !important;
        height: 20px !important;
        margin: 0 4px !important;
    }

    /* Properties Bar Stacking */
    .editor-toolbar-top {
        overflow-x: auto;
        padding: 0 8px !important;
        gap: 16px !important;
    }

    .editor-toolbar-top > div {
        flex-shrink: 0 !important;
    }
}

.tool-btn.active {
    background: #e5f3ff !important;
    color: #1a1a1a !important;
    border: 1px solid var(--cad-accent) !important;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.12) !important;
}

/* Ensure SVG icons stay dark and become bold when active */
.tool-btn.active svg {
    stroke: #1a1a1a !important;
    stroke-width: 2.5px !important;
}

/* Property Groups Visibility - Unified Model */
.property-group.hidden {
    display: none !important;
}

/* Status Item (Snap) Active Style */
.status-item.active {
    color: var(--cad-accent) !important;
    text-shadow: 0 0 4px rgba(6, 150, 215, 0.3);
}

.status-item:hover {
    color: #333 !important;
}

/* Restore Glyph hover style */
#editorSymbolKeyboardGrid div:hover,
.symbol-key:hover {
    background: var(--cad-accent-hover) !important;
    color: white !important;
}

.symbol-key {
    background: white;
    border: 1px solid #eee;
    border-radius: 4px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.1s ease;
    margin: 1px;
    /* System fallbacks for special symbols as suggested by user */
    font-family: "Segoe UI Symbol", "Apple Color Emoji", "Noto Sans Symbols", "Segoe UI", Tahoma, sans-serif;
}

.symbol-key:active {
    background: var(--cad-accent) !important;
    transform: translateY(1px);
}

/* Stepper styles */
.stepper-container input::-webkit-outer-spin-button,
.stepper-container input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* =========================================================================
   ===== Mobile ===== (editor-specific narrow viewport overrides,
   originally editor-mobile.css)
   ========================================================================= */
@media (max-width: 720px) {
    #svgEditorModal .modal-window>div:nth-child(2) {
        flex-direction: column;
    }

    #editorCanvasContainer {
        padding-inline: var(--mobile-dynamic-padding, 0px);
        transition: padding 0.05s linear;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        height: 100%;
        overflow: hidden;
    }

    #editorSVGContainer {
        width: auto !important;
        max-width: 100%;
        margin: 0 auto;
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        min-width: 0 !important;
    }

    .editor-symbol-keyboard {
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        width: 100vw !important;
        max-width: 100vw !important;
        margin-inline: calc(var(--mobile-dynamic-padding, 0px) * -1);
        flex-shrink: 0;
        box-shadow: none;
        border-top: 1px solid var(--border);
        border-left: none;
        border-right: none;
        border-radius: 0;
        touch-action: none;
        z-index: 100;
    }

    .editor-sidebar {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: 8px 8px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        background: var(--surface);
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
    }

    .editor-sidebar .tool-btn {
        width: 38px;
        height: 38px;
        flex: 0 0 auto;
        padding: 6px;
    }

    .editor-toolbar-top {
        padding: 8px 10px;
        gap: 8px;
    }
}

@media (max-width: 700px) {
    #svgEditorHeader {
        flex-direction: row;
        align-items: center !important;
        justify-content: space-between;
        padding: 12px 10px;
        gap: 12px;
        width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    #svgEditorHeader h3 {
        margin: 0;
    }

    #svgEditorHeader>div {
        width: auto;
        margin-left: 0 !important;
        justify-content: space-between;
        min-width: 0;
        flex: 0 0 auto;
        display: flex;
        align-items: center;
    }

    .editor-toolbar-top {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 10px 10px 10px 8px;
        height: auto;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        align-items: center;
        white-space: nowrap;
    }

    .editor-toolbar-top > * {
        flex: 0 0 auto;
        scroll-snap-align: start;
        min-width: 0;
    }

    /* Prevent the layout spacer from forcing a second row on mobile */
    .editor-toolbar-top > div[style*="flex:1"] {
        flex: 0 0 auto !important;
        width: auto !important;
    }

    #svgEditorHeader > div:last-child {
        gap: 4px;
    }

    #svgEditorHeader > div:last-child > button {
        min-width: 0 !important;
        width: auto !important;
        padding: 4px 8px !important;
        height: 30px !important;
        font-size: 11px !important;
        line-height: 1 !important;
    }

    #svgEditorHeader > div:last-child > button.btn-primary.btn-xs {
        padding: 4px 10px !important;
    }

    #svgEditorHeader > div:last-child > button,
    #svgEditorHeader > div:last-child > button.btn-secondary,
    #svgEditorHeader > div:last-child > button.btn-primary {
        flex: 0 0 auto !important;
    }

    #editorStrokeGroup,
    #editorFontGroup {
        width: auto;
        justify-content: flex-start;
    }

    #editorStrokeWidthSlider {
        flex: 1;
        margin-right: 12px;
    }

    .editor-sidebar {
        width: 56px;
        min-width: 56px;
        padding: 10px 6px;
    }

    .tool-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 40px;
        width: 40px;
        height: 40px;
        padding: 6px;
        border-radius: 10px;
    }
}

/* =========================================================================
   Layers Panel (right sidebar inside .cad-modal-body of the SVG editor)
   Sibling of .editor-sidebar (left) and #editorCanvasContainer.
   Replaces the legacy LYR <select> dropdown — supports unlimited layers,
   add/remove/rename, visibility toggle, drag-to-reorder. The data model
   lives in editor/layers.js (editor._layers array).
   ========================================================================= */
.editor-layers-panel {
    width: 220px;
    flex-shrink: 0;
    background: #fdfdfd;
    border-left: 1px solid var(--cad-border-standard);
    display: flex;
    flex-direction: column;
    z-index: 10;
    min-height: 0;
}

.editor-layers-panel .layers-header {
    height: 32px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f3f3f3;
    border-bottom: 1px solid var(--cad-border-standard);
    font-size: 10px;
    font-weight: 700;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex-shrink: 0;
}

.editor-layers-panel .layers-add-btn {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--cad-accent, #1e6fea);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.editor-layers-panel .layers-add-btn:hover { background: #e7eefe; }

.editor-layers-panel .layers-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
}

.editor-layers-panel .layers-empty {
    color: #999;
    font-size: 11px;
    padding: 18px 12px;
    text-align: center;
    line-height: 1.4;
}

.editor-layers-panel .layer-row {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 28px;
    padding: 0 4px 0 2px;
    border-radius: 3px;
    cursor: pointer;
    user-select: none;
    font-size: 11px;
    color: #333;
}
.editor-layers-panel .layer-row:hover { background: #f3f3f3; }
.editor-layers-panel .layer-row.active {
    background: #e0ecff;
    outline: 1px solid #b6d0f5;
}
.editor-layers-panel .layer-row.dragging { opacity: 0.4; }
.editor-layers-panel .layer-row.drop-before { box-shadow: inset 0 2px 0 var(--cad-accent, #1e6fea); }
.editor-layers-panel .layer-row.drop-after  { box-shadow: inset 0 -2px 0 var(--cad-accent, #1e6fea); }

.editor-layers-panel .layer-handle {
    width: 14px;
    flex-shrink: 0;
    text-align: center;
    color: #bbb;
    font-size: 12px;
    cursor: grab;
    line-height: 1;
}
.editor-layers-panel .layer-handle:active { cursor: grabbing; }

.editor-layers-panel .layer-visibility {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #555;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}
.editor-layers-panel .layer-visibility:hover { background: #e6e6e6; }
.editor-layers-panel .layer-visibility.is-hidden { color: #c8c8c8; }
.editor-layers-panel .layer-visibility svg { width: 14px; height: 14px; }

.editor-layers-panel .layer-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 2px;
}

.editor-layers-panel .layer-name-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--cad-accent, #1e6fea);
    border-radius: 2px;
    font-size: 11px;
    padding: 2px 4px;
    outline: none;
    font-family: inherit;
}

.editor-layers-panel .layer-delete {
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #d32f2f;
    font-size: 13px;
    line-height: 1;
    border-radius: 3px;
    visibility: hidden;
    padding: 0;
    flex-shrink: 0;
}
.editor-layers-panel .layer-row:hover .layer-delete { visibility: visible; }
.editor-layers-panel .layer-delete:hover { background: #fde7e7; }

/* When a layer is hidden, dim and hide its SVG elements in the editor view.
   The expand-time geometry filter (task 4) makes sure hidden layers are
   also excluded from the stamp output. */
#editorSVGContainer .layer-hidden { display: none; }

/* Elements on non-active layers are dimmed and non-interactive so the user
   can clearly see which layer is currently editable. The class is applied
   by applyLayerState() in editor/layers.js. */
#editorSVGContainer .inactive-layer {
    opacity: 0.4;
    pointer-events: none;
}

/* Mobile: narrower panel; on very narrow viewports the panel hides behind
   a toggle. For now keep it visible but slimmer. */
@media (max-width: 700px) {
    .editor-layers-panel { width: 170px; }
}
