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

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* JS warning bar — visible by default, hidden by JS on load */
.js-warning {
    background: #e94560;
    color: #fff;
    text-align: center;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.4;
    z-index: 500;
    flex-shrink: 0;
}

.js-warning.hidden { display: none; }

header {
    background: #16213e;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid #0f3460;
    flex-shrink: 0;
}

header h1 { font-size: 1.3rem; color: #e94560; flex-shrink: 0; }

.footer-links {
    margin-top: 8px;
    text-align: center;
}

.footer-github {
    color: #aaa;
    text-decoration: none;
    font-size: 0.7rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s;
}

.footer-github:hover { color: #555; }

.project-name {
    font-size: 0.95rem;
    color: #aaa;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 3px;
    border: 1px solid transparent;
    margin-left: 8px;
}

.project-name:hover { border-color: #0f3460; color: #e0e0e0; }

.project-name-input {
    font-size: 0.95rem;
    padding: 2px 8px;
    border: 1px solid #e94560;
    border-radius: 3px;
    background: #1a1a2e;
    color: #e0e0e0;
    margin-left: 8px;
    width: 200px;
}

.header-actions { display: flex; gap: 8px; align-items: center; }

.header-actions button, .header-actions select {
    padding: 6px 14px;
    border: 1px solid #0f3460;
    background: #16213e;
    color: #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.header-actions button:hover { background: #0f3460; }

/* Header dropdowns */
.header-dropdown {
    position: relative;
}

.header-dropdown-btn {
    padding: 6px 14px;
    border: 1px solid #0f3460;
    background: #16213e;
    color: #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.header-dropdown-btn:hover { background: #0f3460; }

.header-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 6px;
    min-width: 180px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 50;
    padding: 4px 0;
}

.header-dropdown:hover .header-dropdown-content,
.header-dropdown.open .header-dropdown-content {
    display: block;
}

.header-dropdown-content button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: #e0e0e0;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 0;
}

.header-dropdown-content button:hover {
    background: #0f3460;
}

.lang-switcher {
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: 700;
}
.header-actions label { font-size: 0.8rem; color: #aaa; }

.app { display: flex; flex: 1; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: 220px;
    background: #16213e;
    border-right: 2px solid #0f3460;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar h2 {
    font-size: 0.95rem;
    color: #e94560;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar h3 { font-size: 0.8rem; color: #888; margin-top: 8px; margin-bottom: 2px; }

.sidebar-cat {
    border: 1px solid #0f3460;
    border-radius: 6px;
}

.sidebar-cat summary {
    font-size: 0.8rem;
    color: #aaa;
    font-weight: 600;
    padding: 6px 10px;
    cursor: pointer;
    background: #121e35;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 6px;
}

.sidebar-cat[open] summary {
    border-radius: 6px 6px 0 0;
}

.sidebar-cat summary::before {
    content: '\25B6';
    font-size: 0.55rem;
    transition: transform 0.2s;
}

.sidebar-cat[open] summary::before {
    transform: rotate(90deg);
}

.sidebar-cat summary:hover { color: #e94560; }

.sidebar-cat > .component-item {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
}

.sidebar-cat > .component-item:last-of-type {
    border-radius: 0 0 6px 6px;
}

.component-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: #1a1a2e;
    border: 1px solid #0f3460;
    border-radius: 6px;
    cursor: grab;
    user-select: none;
    transition: border-color 0.2s, transform 0.1s;
}

.component-item:hover { border-color: #e94560; transform: translateX(2px); }
.component-item:active { cursor: grabbing; }

.component-icon {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.7rem;
    flex-shrink: 0;
    color: #fff;
}

.component-info { display: flex; flex-direction: column; }
.component-info .name { font-size: 0.8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.component-info .size { font-size: 0.7rem; color: #888; }

/* Main panel area */
.main {
    flex: 1;
    padding: 24px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.panel {
    background: #e8e8e0;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
    position: relative;
    width: 100%;
}

.panel-title {
    text-align: center;
    color: #333;
    font-size: 0.85rem;
    margin-bottom: 12px;
    font-weight: 600;
}

/* Kasten (Panel) wrapper */
.kasten-wrap {
    background: #e0e0d8;
    border: 2px solid #b0b0a0;
    border-radius: 6px;
    margin-bottom: 16px;
    overflow: visible;
}

.kasten-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: #555;
    border-radius: 4px 4px 0 0;
    color: #fff;
}

.kasten-name {
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
}

.kasten-name-input {
    font-size: 0.8rem;
    padding: 2px 6px;
    border: 1px solid #e94560;
    border-radius: 3px;
    background: #fff;
    color: #333;
    width: 140px;
}

.kasten-info {
    font-size: 0.65rem;
    color: #bbb;
    margin-left: 4px;
}

.kasten-actions {
    margin-left: auto;
    display: flex;
    gap: 4px;
}

.kasten-btn {
    padding: 2px 8px;
    border: 1px solid rgba(255,255,255,0.3);
    background: transparent;
    color: #fff;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
}

.kasten-btn:hover { background: rgba(255,255,255,0.15); }
.kasten-btn-danger:hover { background: #e94560; }

.kasten-body {
    padding: 10px;
}

.add-panel-btn {
    display: block;
    width: 100%;
    padding: 10px;
    border: 2px dashed #bbb;
    background: transparent;
    color: #888;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 16px;
    transition: border-color 0.2s, color 0.2s;
}

.add-panel-btn:hover {
    border-color: #e94560;
    color: #e94560;
}

/* Abgänge (Verbraucher) */
.abgaenge-bar {
    background: #c8c8be;
    border: 2px solid #aaa;
    border-radius: 4px;
    padding: 8px 12px;
    margin-top: 4px;
}

.abgaenge-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.abgaenge-title {
    font-size: 0.7rem;
    color: #555;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.abgang-add-btn {
    padding: 3px 10px;
    border: 1px solid #999;
    background: #ddd;
    color: #333;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
}

.abgang-add-btn:hover { background: #ccc; }

.abgaenge-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.abgang-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 8px 4px;
    background: #d8d8d0;
    border: 1px solid #bbb;
    border-radius: 4px;
    position: relative;
    min-width: 70px;
}

.abgang-item:hover { border-color: #888; }

.abgang-strich {
    width: 4px;
    height: 16px;
    border-radius: 2px;
}

.abgang-adern {
    display: flex;
    gap: 3px;
    justify-content: center;
}

.abgang-ader {
    width: 18px;
    height: 22px;
    border: 2px solid;
    border-radius: 2px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: crosshair;
    transition: background 0.15s;
    position: relative;
}

.abgang-ader:hover, .abgang-ader.active {
    background: #e94560;
}

.abgang-ader:hover .abgang-ader-label { color: #fff !important; }

.abgang-ader-label {
    font-size: 0.4rem;
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
}

.abgang-label-text {
    font-size: 0.65rem;
    font-weight: 600;
    color: #333;
    text-align: center;
    cursor: pointer;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.abgang-detail {
    font-size: 0.55rem;
    color: #777;
    cursor: pointer;
}

.abgang-edit-input {
    width: auto;
    min-width: 80px;
    max-width: 140px;
    padding: 2px 4px;
    font-size: 0.65rem;
    border: 1px solid #e94560;
    border-radius: 2px;
    text-align: center;
    background: #fff;
    color: #333;
}

select.abgang-edit-input {
    min-width: 110px;
    cursor: pointer;
}

.abgang-del {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: none;
    background: #e94560;
    color: #fff;
    font-size: 0.7rem;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.abgang-item:hover .abgang-del { display: flex; }

/* Hauptanschlussklemme (HAK) */
.hak-bar {
    display: flex;
    align-items: stretch;
    background: #b8b8ae;
    border: 2px solid #999;
    border-radius: 4px;
    margin-bottom: 16px;
    min-height: 50px;
    position: relative;
}

.hak-klemmen {
    display: flex;
    flex: 1;
    justify-content: center;
    gap: 8px;
    padding: 6px 12px;
    align-items: stretch;
}

.hak-klemme {
    flex: 1;
    max-width: 120px;
    min-height: 38px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 2px solid rgba(0,0,0,0.2);
}

.hak-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.hak-klemme .terminal.bottom {
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
}

.din-row {
    display: flex;
    align-items: stretch;
    background: #d0d0c8;
    border: 2px solid #b0b0a0;
    border-radius: 4px;
    margin-bottom: 20px;
    min-height: 90px;
    position: relative;
}

.row-label {
    writing-mode: vertical-lr;
    text-orientation: mixed;
    transform: rotate(180deg);
    background: #555;
    color: #fff;
    padding: 4px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px 0 0 2px;
    min-width: 24px;
}

.row-slots {
    display: flex;
    flex: 1;
    position: relative;
    min-height: 90px;
}

.slot {
    width: var(--slot-width, 40px);
    min-height: 90px;
    border-right: 1px dashed #bbb;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.slot.drag-over { background: rgba(233, 69, 96, 0.15); }
.slot.occupied { border-right-color: transparent; }
.slot-number { position: absolute; bottom: 2px; font-size: 0.55rem; color: #999; }

/* Placed components */
.placed-component {
    position: absolute;
    top: 4px;
    bottom: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    border: 2px solid;
    cursor: grab;
    z-index: 2;
    transition: box-shadow 0.15s;
    user-select: none;
}

.placed-component:hover { box-shadow: 0 0 8px rgba(233, 69, 96, 0.5); }
.placed-component.selected { box-shadow: 0 0 0 2px #e94560, 0 0 12px rgba(233, 69, 96, 0.4); }
.placed-component.dragging { opacity: 0.4; }

.placed-component .comp-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: #fff;
    text-align: center;
    line-height: 1.1;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    padding: 0 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.placed-component .comp-symbol {
    font-size: 1.1rem;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.placed-component .comp-rating {
    font-size: 0.55rem;
    color: rgba(255,255,255,0.85);
}

/* Wire terminals — multi-pole layout */
.terminals-row {
    display: flex;
    justify-content: center;
    gap: 3px;
    position: absolute;
    left: 0;
    right: 0;
    z-index: 5;
}

.terminals-row.top-row { top: -10px; }
.terminals-row.bottom-row { bottom: -10px; }

.terminal-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.terminal-group.bottom {
    flex-direction: column-reverse;
}

.terminal-pole-label {
    font-size: 0.45rem;
    color: rgba(255,255,255,0.85);
    font-weight: 700;
    text-shadow: 0 0 3px rgba(0,0,0,0.8);
    line-height: 1;
}

.terminal {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #333;
    border: 2px solid #666;
    cursor: crosshair;
    z-index: 5;
    transition: background 0.15s, transform 0.15s;
    flex-shrink: 0;
}

.terminal:hover, .terminal.active {
    background: #e94560;
    border-color: #e94560;
    transform: scale(1.4);
}

/* HAK terminals keep absolute positioning */
.hak-klemme .terminal.bottom {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
}

.hak-klemme .terminal.bottom:hover,
.hak-klemme .terminal.bottom.active {
    transform: translateX(-50%) scale(1.4);
}

/* Klemmenblock Ausgangs-Grid */
.klemme-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
    padding: 2px;
    margin-top: 2px;
}

.klemme-port {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    background: rgba(255,255,255,0.25);
    border: 1px solid rgba(255,255,255,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: crosshair;
    transition: background 0.15s, border-color 0.15s;
    position: relative;
}

.klemme-port:hover, .klemme-port.active {
    background: #e94560;
    border-color: #e94560;
}

.klemme-port-num {
    font-size: 0.4rem;
    color: rgba(255,255,255,0.9);
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

/* Klemmschienen (PE/N im Gehäuse) */
.schienen-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.schiene-bar {
    display: flex;
    align-items: center;
    border: 2px solid;
    border-radius: 4px;
    background: #e8e8e0;
    padding: 3px;
    gap: 4px;
}

.schiene-label {
    color: #fff;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 3px 6px;
    border-radius: 2px;
    flex-shrink: 0;
    min-width: 26px;
    text-align: center;
}

.schiene-ports {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    align-items: center;
}

.schiene-port {
    width: 18px;
    height: 18px;
    border: 2px solid;
    border-radius: 2px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.45rem;
    font-weight: 700;
    color: #555;
    cursor: crosshair;
    transition: background 0.15s;
    user-select: none;
}

.schiene-port:hover, .schiene-port.active {
    background: #e94560;
    color: #fff;
    border-color: #e94560;
}

.schiene-port-in {
    font-weight: 800;
    font-size: 0.5rem;
    color: #333;
}

.schiene-sep {
    width: 1px;
    height: 14px;
    background: #ccc;
    margin: 0 2px;
}

/* Floating toolbar */
.floating-toolbar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 190;
}

.fab {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid #0f3460;
    background: #16213e;
    color: #e0e0e0;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    transition: background 0.2s, border-color 0.2s;
}

.fab:hover { background: #0f3460; }
.fab.active { background: #e94560; border-color: #e94560; }
.fab-text { font-size: 0.85rem; font-weight: 800; }

/* Wire markers */
.wire-marker {
    position: absolute;
    top: -3px;
    right: -8px;
    min-width: 13px;
    height: 13px;
    border-radius: 7px;
    font-size: 0.4rem;
    font-weight: 800;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: auto;
    cursor: help;
    border: 1.5px solid rgba(255,255,255,0.7);
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    padding: 0 2px;
    line-height: 1;
}

.klemme-port .wire-marker {
    top: -5px;
    right: -5px;
    min-width: 11px;
    height: 11px;
    font-size: 0.35rem;
}

/* Wires SVG overlay */
.wires-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 3;
}

.wire { stroke-width: 2.5; fill: none; pointer-events: stroke; cursor: pointer; }
.wire:hover { stroke-width: 4; }

.wire-label {
    font-size: 12px;
    font-weight: 700;
    pointer-events: none;
    opacity: 1;
    paint-order: stroke;
    stroke: #e8e8e0;
    stroke-width: 4px;
}

/* Properties panel */
.properties {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    width: 260px;
    background: #16213e;
    border-left: 2px solid #0f3460;
    padding: 16px;
    transform: translateX(100%);
    transition: transform 0.25s;
    z-index: 100;
    overflow-y: auto;
}

.properties.open { transform: translateX(0); }
.properties h3 { color: #e94560; margin-bottom: 12px; font-size: 0.95rem; }
.properties label { display: block; font-size: 0.8rem; color: #aaa; margin-top: 8px; margin-bottom: 2px; }

.properties input, .properties select {
    width: 100%;
    padding: 6px 8px;
    background: #1a1a2e;
    border: 1px solid #0f3460;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 0.85rem;
}

.properties .btn-row { display: flex; gap: 8px; margin-top: 16px; }

.properties button {
    flex: 1; padding: 8px; border: none; border-radius: 4px;
    cursor: pointer; font-size: 0.8rem; font-weight: 600;
}

.btn-save { background: #0f3460; color: #fff; }
.btn-save:hover { background: #1a4a8a; }
.btn-delete { background: #e94560; color: #fff; }
.btn-delete:hover { background: #c0354d; }
.btn-close-props { background: #333; color: #fff; }
.btn-close-props:hover { background: #555; }

/* Toast */
.toast {
    position: fixed;
    bottom: 20px; left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #0f3460;
    color: #fff;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: transform 0.3s;
    z-index: 200;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Wiring mode indicator */
.wiring-indicator {
    position: fixed;
    top: 60px; left: 50%;
    transform: translateX(-50%);
    background: #e94560;
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 200;
    display: none;
    box-shadow: 0 2px 12px rgba(233,69,96,0.4);
}
.wiring-indicator.show { display: block; }

/* Color legend */
.wire-colors { display: flex; gap: 12px; margin-top: 12px; justify-content: center; }
.wire-color-item { display: flex; align-items: center; gap: 4px; font-size: 0.7rem; color: #666; }
.wire-color-swatch { width: 20px; height: 4px; border-radius: 2px; }

/* Context menu */
.context-menu {
    position: fixed;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 6px;
    padding: 4px 0;
    z-index: 300;
    display: none;
    min-width: 180px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.context-menu-item { padding: 8px 16px; font-size: 0.8rem; cursor: pointer; color: #e0e0e0; }
.context-menu-item:hover { background: #0f3460; }
.context-menu-item.danger { color: #e94560; }

/* Instructions */
.instructions {
    margin-top: 16px; text-align: center;
    color: #666; font-size: 0.75rem; line-height: 1.6;
}
.instructions kbd {
    background: #ddd; padding: 1px 5px; border-radius: 3px;
    font-size: 0.7rem; border: 1px solid #ccc;
}

/* Settings modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 400;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 8px;
    padding: 24px;
    min-width: 340px;
    max-width: 90vw;
}

.modal h3 { color: #e94560; margin-bottom: 16px; }
.modal label { display: block; font-size: 0.85rem; color: #aaa; margin-top: 10px; margin-bottom: 4px; }

.modal input, .modal select {
    width: 100%;
    padding: 8px;
    background: #1a1a2e;
    border: 1px solid #0f3460;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 0.9rem;
}

.modal .btn-row { display: flex; gap: 8px; margin-top: 20px; }
.modal button {
    flex: 1; padding: 10px; border: none; border-radius: 4px;
    cursor: pointer; font-size: 0.85rem; font-weight: 600;
}

/* ─── Mobile menu button (hidden on desktop) ─── */
.mobile-menu-btn {
    display: none;
    background: transparent;
    border: 1px solid #0f3460;
    color: #e0e0e0;
    font-size: 1.4rem;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
}

.mobile-menu-btn:hover { background: #0f3460; }

/* Sidebar overlay (mobile only) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
}

.sidebar-overlay.open { display: block; }

/* Sidebar toggle FAB (hidden on desktop) */
.fab-sidebar { display: none; }

/* Tap-to-place indicator */
.tap-indicator {
    position: fixed;
    bottom: 80px; left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #0f3460;
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 200;
    transition: transform 0.3s;
    white-space: nowrap;
    pointer-events: none;
}

.tap-indicator.show {
    transform: translateX(-50%) translateY(0);
}

/* Component selected for tap-to-place */
.component-item.tap-selected {
    border-color: #e94560;
    background: #2a1a3e;
    box-shadow: 0 0 8px rgba(233, 69, 96, 0.4);
}

/* View mode toggle FAB (hidden on desktop) */
.fab-view-toggle { display: none; }

/* ─── List view for mobile DIN rows ─── */
.row-list-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 4px;
    padding: 6px;
}

.list-component-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: #f5f5f0;
    border: 1px solid #ccc;
    border-radius: 6px;
    cursor: pointer;
    transition: box-shadow 0.15s;
}

.list-component-item:hover {
    box-shadow: 0 0 6px rgba(233, 69, 96, 0.4);
}

.list-component-item.selected {
    box-shadow: 0 0 0 2px #e94560;
}

.list-comp-swatch {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.list-comp-info {
    flex: 1;
    min-width: 0;
}

.list-comp-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-comp-detail {
    font-size: 0.65rem;
    color: #888;
}

.list-comp-meta {
    text-align: right;
    flex-shrink: 0;
}

.list-comp-slot {
    font-size: 0.6rem;
    color: #999;
    white-space: nowrap;
}

.list-comp-wires {
    font-size: 0.55rem;
    color: #2980b9;
    font-weight: 600;
}

.row-list-empty {
    padding: 14px;
    text-align: center;
    color: #999;
    font-size: 0.75rem;
    font-style: italic;
}

.row-list-add {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border: 1px dashed #bbb;
    border-radius: 6px;
    color: #888;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    transition: border-color 0.2s, color 0.2s;
}

.row-list-add:hover {
    border-color: #e94560;
    color: #e94560;
}

/* ─── Responsive: Tablets (<=900px) ─── */
@media (max-width: 900px) {
    header { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
    header h1 { font-size: 1.1rem; }
    .project-name { font-size: 0.85rem; }

    .sidebar { width: 190px; padding: 10px; }
    .main { padding: 12px; }
    .panel { padding: 12px; }
}

/* ─── Responsive: Mobile (<=768px) ─── */
@media (max-width: 768px) {
    /* Header: compact layout */
    header {
        padding: 8px 12px;
        flex-wrap: nowrap;
        gap: 8px;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    header h1 { font-size: 1rem; }
    .project-name { display: none; }

    /* Hide desktop actions, show mobile menu button */
    .header-actions { display: none; }
    .header-actions.mobile-open {
        display: flex;
        flex-wrap: wrap;
        position: fixed;
        top: 46px;
        left: 0; right: 0;
        background: #16213e;
        border-bottom: 2px solid #0f3460;
        padding: 10px;
        gap: 6px;
        z-index: 99;
        box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    }

    .header-actions.mobile-open button,
    .header-actions.mobile-open select {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 0.78rem;
        padding: 8px 10px;
    }

    /* Flatten dropdowns in mobile menu */
    .header-actions.mobile-open .header-dropdown {
        display: contents;
    }

    .header-actions.mobile-open .header-dropdown-btn { display: none; }

    .header-actions.mobile-open .header-dropdown-content {
        display: contents;
    }

    .header-actions.mobile-open .header-dropdown-content button {
        flex: 1 1 auto;
        text-align: center;
        border: 1px solid #0f3460;
        border-radius: 4px;
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    .mobile-menu-btn { display: block; margin-left: auto; }

    /* Sidebar: off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 250px;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        padding-top: 54px;
        padding-bottom: 24px;
        background: #16213e;
        box-shadow: 4px 0 20px rgba(0,0,0,0.6);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Show sidebar toggle FAB */
    .fab-sidebar { display: flex; }
    .fab-view-toggle { display: flex; }

    /* Main area: full width, allow horizontal scroll for wide panels */
    .main {
        padding: 10px 6px;
        align-items: stretch;
    }

    .panel {
        padding: 10px;
    }

    /* Kasten body scrolls horizontally, header stays full-width */
    .kasten-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .kasten-body .din-row:has(.row-slots) { min-width: max-content; }
    .kasten-body .row-slots { min-width: max-content; }
    .kasten-body .din-row:has(.row-list-view) { min-width: 0; }

    /* HAK also scrollable */
    .hak-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Narrower slots on mobile */
    .slot { min-height: 80px; }
    .placed-component .comp-label { font-size: 0.5rem; }
    .placed-component .comp-symbol { font-size: 0.9rem; }
    .placed-component .comp-rating { font-size: 0.5rem; }

    /* Properties panel full width on mobile */
    .properties { width: 100%; }

    /* Floating toolbar */
    .floating-toolbar { bottom: 14px; right: 14px; }
    .fab { width: 40px; height: 40px; font-size: 1rem; }

    /* Wiring indicator smaller */
    .wiring-indicator {
        font-size: 0.72rem;
        padding: 6px 14px;
        top: 52px;
        max-width: 90vw;
        text-align: center;
    }

    /* Toast above floating toolbar */
    .toast { bottom: 70px; font-size: 0.8rem; max-width: 85vw; }

    /* Modal full width */
    .modal { min-width: auto; width: 92vw; }

    /* Abgaenge wrap nicely */
    .abgaenge-list { gap: 6px; }
    .abgang-item { min-width: 60px; padding: 8px 6px 4px; }
    .abgang-label-text { font-size: 0.6rem; max-width: 65px; }

    /* Kasten header */
    .kasten-header { padding: 5px 8px; flex-wrap: wrap; }
    .kasten-name { font-size: 0.75rem; }
    .kasten-info { font-size: 0.6rem; }

    /* Instructions */
    .instructions { font-size: 0.68rem; }
}

/* ─── Responsive: Small phones (<=480px) ─── */
@media (max-width: 480px) {
    header h1 { font-size: 0.9rem; }

    .sidebar { width: 220px; }

    .main { padding: 6px 4px; }
    .panel { padding: 8px; }

    .slot { min-height: 70px; }
    .placed-component .comp-label { font-size: 0.45rem; }
    .placed-component .comp-symbol { font-size: 0.8rem; }

    .row-label { padding: 2px 4px; font-size: 0.6rem; min-width: 20px; }

    .fab { width: 36px; height: 36px; font-size: 0.9rem; }
    .floating-toolbar { bottom: 10px; right: 10px; gap: 6px; }

    .properties { padding: 12px; }
    .properties h3 { font-size: 0.85rem; }
}
