/* BMS Wiresheet Simulator - styles layered on top of style.css tokens */

html, body {
    height: 100%;
    overflow: hidden;
}

.bmssim {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ------------------------------------------------------------- top bar */
.bmssim-topbar {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: 0 var(--space-lg);
    height: 56px;
    flex: 0 0 56px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    z-index: 20;
}

.bmssim-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    white-space: nowrap;
}
.bmssim-back .logo-icon {
    width: 28px; height: 28px;
    border-radius: var(--radius-sm);
    background: var(--gradient-primary);
    color: #05050a;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.75rem;
}
.bmssim-back:hover { color: var(--primary); }

.bmssim-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    color: var(--text-primary);
    white-space: nowrap;
    margin: 0;
}
.bmssim-title small {
    display: block;
    font-family: 'Rajdhani', sans-serif;
    font-weight: 500;
    font-size: 0.68rem;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.bmssim-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    flex-wrap: nowrap;
}
.bmssim-toolbar .sep {
    width: 1px; height: 24px;
    background: var(--border);
    margin: 0 0.25rem;
}

.tbtn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: 'Rajdhani', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.tbtn:hover { border-color: var(--primary); color: var(--text-primary); }
.tbtn.is-active { background: var(--primary); border-color: var(--primary); color: #05050a; }
.tbtn.tbtn-primary { background: var(--gradient-primary); border-color: transparent; color: #05050a; }
.tbtn.tbtn-primary:hover { filter: brightness(1.1); color: #05050a; }
select.tbtn { cursor: pointer; }

/* ------------------------------------------------------------------ body */
.bmssim-body {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

/* --------------------------------------------------------------- palette */
.bmssim-palette {
    width: 270px;
    flex: 0 0 270px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.palette-search-wrap {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
}
.palette-search-wrap input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Rajdhani', sans-serif;
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
}
.palette-search-wrap input:focus { outline: none; border-color: var(--primary); }

.bmssim-palette-list {
    overflow-y: auto;
    padding: 0.5rem;
    flex: 1 1 auto;
}
.palette-group { margin-bottom: 0.25rem; }
.palette-group summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 0.5rem 0.4rem;
}
.palette-group summary::-webkit-details-marker { display: none; }
.palette-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.palette-list { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.15rem 0.15rem 0.6rem; }

.palette-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--cat-color, var(--primary));
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.6rem;
    cursor: grab;
    touch-action: none;
    user-select: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}
.palette-item:hover { background: var(--bg-card-hover); border-color: var(--cat-color, var(--primary)); }
.palette-item-title { font-weight: 600; font-size: 0.85rem; color: var(--text-primary); }
.palette-item-desc { font-size: 0.72rem; color: var(--text-muted); line-height: 1.35; margin-top: 0.15rem; }

.palette-ghost {
    position: fixed;
    z-index: 999;
    transform: translate(-50%, -50%);
    background: var(--primary);
    color: #05050a;
    font-family: 'Rajdhani', sans-serif;
    font-weight: 700;
    font-size: 0.8rem;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    pointer-events: none;
    box-shadow: var(--shadow-lg);
    opacity: 0.92;
}

/* ---------------------------------------------------------------- canvas */
.bmssim-canvas-wrap {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.bmssim-canvas-viewport {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    background-color: #07070d;
    background-image: radial-gradient(rgba(0, 212, 255, 0.14) 1px, transparent 1px);
    background-size: 24px 24px;
    cursor: grab;
}
.bmssim-canvas-viewport:active { cursor: grabbing; }
.bmssim-canvas-inner {
    position: absolute;
    top: 0; left: 0;
    width: 1px; height: 1px;
    transform-origin: 0 0;
}

.bmssim-wires {
    position: absolute;
    top: 0; left: 0;
    width: 6000px; height: 4000px;
    overflow: visible;
    pointer-events: none;
}
.wire {
    fill: none;
    stroke-width: 2.5;
    pointer-events: stroke;
    cursor: pointer;
}
.wire-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 16;
    pointer-events: stroke;
    cursor: pointer;
}
.wire-analog { stroke: var(--primary); filter: drop-shadow(0 0 2px rgba(0,212,255,0.5)); }
.wire-digital { stroke: #3a3a4a; }
.wire-digital.digital-on { stroke: var(--accent); filter: drop-shadow(0 0 3px rgba(255,0,110,0.6)); }
.wire-digital.digital-off { stroke: #3a3a4a; }
.wire-draft { stroke: var(--warning); stroke-dasharray: 6 4; }
.wire.is-selected { stroke-width: 4; stroke: #fff; filter: drop-shadow(0 0 4px #fff); }
.sim-running .wire-analog { stroke-dasharray: 3 5; animation: wireflow 900ms linear infinite; }
@keyframes wireflow { to { stroke-dashoffset: -16; } }

.bmssim-blocks {
    position: absolute;
    top: 0; left: 0;
    width: 6000px; height: 4000px;
    pointer-events: none;
}

/* ------------------------------------------------------------------ block */
.wsb {
    position: absolute;
    background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-elevated) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    user-select: none;
    touch-action: none;
    cursor: grab;
    pointer-events: auto;
}
.wsb:active { cursor: grabbing; }
.wsb.is-selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-glow), var(--shadow-lg); }
.wsb-jump-flash { animation: jumpFlash 900ms ease-out; }
@keyframes jumpFlash {
    0% { box-shadow: 0 0 0 6px rgba(0, 212, 255, 0.55), var(--shadow-lg); }
    100% { box-shadow: 0 0 0 2px var(--primary-glow), var(--shadow-lg); }
}
.wsb-head {
    height: 30px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.55rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.66rem;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border-left: 3px solid var(--cat-color, var(--primary));
    background: rgba(255,255,255,0.02);
    white-space: nowrap;
    overflow: hidden;
}
.wsb-title { overflow: hidden; text-overflow: ellipsis; }

.wsb-icon, .palette-icon {
    flex: 0 0 auto;
    width: 19px; height: 19px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 5px;
    background: color-mix(in srgb, var(--cat-color, var(--primary)) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--cat-color, var(--primary)) 55%, transparent);
    color: var(--cat-color, var(--primary));
    box-shadow: 0 0 6px color-mix(in srgb, var(--cat-color, var(--primary)) 35%, transparent);
}
.wsb-icon svg, .palette-icon svg { width: 13px; height: 13px; }
.wsb-icon .icon-fill, .palette-icon .icon-fill { fill: currentColor; stroke-width: 3; }
.wsb-icon-glyph, .palette-icon .wsb-icon-glyph {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.62rem;
    line-height: 1;
}
.palette-item-row { display: flex; align-items: center; gap: 0.5rem; }
.palette-icon { width: 22px; height: 22px; }
.palette-icon svg { width: 14px; height: 14px; }
.wsb-body { position: relative; }

.wsb-port {
    position: absolute;
    height: 22px;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.68rem;
    font-family: 'Rajdhani', sans-serif;
    max-width: calc(100% - 16px);
}
.wsb-port-in { left: 8px; }
.wsb-port-out { right: 8px; }
.wsb-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid #07070d;
    flex: 0 0 auto;
    cursor: crosshair;
}
.wsb-port-in .wsb-dot { margin-left: -14px; }
.wsb-port-out .wsb-dot { margin-right: -14px; }
.wsb-dot-analog { background: var(--primary); }
.wsb-dot-digital { background: #5a5a6a; }

.wsb-port-in.wire-target-ok .wsb-dot {
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(0, 245, 160, 0.28);
    animation: targetPulse 900ms ease-in-out infinite;
}
.wsb-port-in.wire-target-bad { opacity: 0.3; }
.wsb-port-in.wire-reject-flash .wsb-dot { background: var(--error) !important; box-shadow: 0 0 0 4px rgba(255, 71, 87, 0.4); }
@keyframes targetPulse { 50% { box-shadow: 0 0 0 7px rgba(0, 245, 160, 0.12); } }
.wsb-plabel { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.wsb-pval {
    font-family: 'Space Mono', monospace;
    color: var(--text-primary);
    font-size: 0.64rem;
    white-space: nowrap;
    flex: 0 0 auto;
}

.wsb-widget {
    position: absolute;
    left: 8px; right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wsb-slider-row { display: flex; align-items: center; gap: 0.5rem; width: 100%; }
.wsb-slider-row input[type="range"] { flex: 1 1 auto; accent-color: var(--primary); }
.wsb-slider-readout {
    font-family: 'Space Mono', monospace;
    font-size: 0.72rem;
    color: var(--primary);
    min-width: 2.6em;
    text-align: right;
}

.wsb-switch-btn {
    width: 100%;
    padding: 0.35rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    cursor: pointer;
}
.wsb-switch-btn.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }

.wsb-lamp {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #2a2a3a;
    border: 2px solid #444;
    box-shadow: inset 0 0 6px rgba(0,0,0,0.6);
    margin-right: 0.5rem;
}
.wsb-lamp.is-on { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 10px var(--accent), 0 0 18px rgba(255,0,110,0.6); }
.wsb-lamp-label { font-size: 0.68rem; color: var(--text-secondary); font-family: 'Rajdhani', sans-serif; }

.wsb-gauge-track {
    width: 100%; height: 10px;
    background: var(--bg-input);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.wsb-gauge-fill { height: 100%; width: 0%; background: var(--gradient-primary); transition: width 150ms linear; }
.wsb-widget-gauge { flex-direction: column; align-items: stretch; gap: 0.25rem; }
.wsb-gauge-readout { font-family: 'Space Mono', monospace; font-size: 0.72rem; color: var(--text-primary); text-align: center; }

.wsb-trend-canvas { width: 100%; height: 100%; }

.props-matrix-editor {
    margin-bottom: 1.2rem;
    padding-top: 0.8rem;
    border-top: 1px solid var(--border);
}
.combo-editor-row { display: flex; align-items: center; gap: 5px; margin-bottom: 6px; }
.combo-editor-cell {
    width: 34px; height: 28px;
    flex: 0 0 auto;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-muted);
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    transition: all var(--transition-fast);
}
.combo-editor-cell:hover { border-color: var(--text-secondary); }
.combo-editor-cell.state-and { background: rgba(0, 212, 255, 0.18); border-color: var(--primary); color: var(--primary); }
.combo-editor-cell.state-not { background: rgba(255, 0, 110, 0.18); border-color: var(--accent); color: var(--accent); }
.combo-editor-result {
    width: 12px; height: 12px;
    border-radius: 50%;
    margin-left: auto;
    background: #3a3a4a;
    flex: 0 0 auto;
    transition: background 150ms, box-shadow 150ms;
}
.combo-editor-result.is-true { background: var(--success); box-shadow: 0 0 7px var(--success); }
.combo-editor-or {
    text-align: center;
    font-size: 0.68rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin: -2px 0 4px;
}

/* ------------------------------------------------------------ status bar */
.bmssim-status {
    flex: 0 0 26px;
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
}
.bmssim-copyright { margin-left: auto; opacity: 0.55; white-space: nowrap; }

/* ------------------------------------------------------------- properties */
.bmssim-props {
    width: 300px;
    flex: 0 0 300px;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: var(--space-md);
}
.props-empty h3 { font-size: 0.95rem; margin-bottom: 0.6rem; }
.props-empty p { font-size: 0.82rem; margin-bottom: 0.8rem; }
.props-legend { list-style: none; margin-bottom: 0.8rem; }
.props-legend li { display: flex; align-items: center; gap: 0.5rem; font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 0.4rem; }
.legend-dot { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.legend-analog { background: var(--primary); }
.legend-digital { background: var(--accent); }
.props-hint { font-size: 0.76rem !important; color: var(--text-muted) !important; }

.props-box h3 {
    font-size: 0.95rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary);
    margin-bottom: 0.5rem;
}
.props-desc { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }
.props-form { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.2rem; }
.props-row { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8rem; color: var(--text-secondary); }
.props-row-label { font-weight: 600; color: var(--text-primary); }
.props-row-hint {
    display: inline-block;
    margin-left: 0.35rem;
    color: var(--primary);
    cursor: help;
    font-size: 0.85em;
}
.props-row input[type="number"], .props-row input[type="text"], .props-row select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.4rem 0.5rem;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.85rem;
}
.props-row input:focus, .props-row select:focus { outline: none; border-color: var(--primary); }
.props-range-wrap { display: flex; align-items: center; gap: 0.5rem; }
.props-range-wrap input[type="range"] { flex: 1 1 auto; accent-color: var(--primary); }
.props-range-readout { font-family: 'Space Mono', monospace; font-size: 0.75rem; color: var(--primary); min-width: 3em; text-align: right; }

.props-connections {
    margin-bottom: 1.2rem;
    padding-top: 0.8rem;
    border-top: 1px solid var(--border);
}
.props-subhead {
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
}
.conn-row {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.15rem;
}
.conn-unlink {
    display: inline-grid;
    place-items: center;
    width: 1.2rem;
    height: 1.2rem;
    margin-left: 0.35rem;
    padding: 0;
    border: 1px solid rgba(255, 71, 87, 0.55);
    border-radius: 50%;
    background: rgba(255, 71, 87, 0.1);
    color: #ff7b88;
    font: 700 0.9rem/1 Arial, sans-serif;
    cursor: pointer;
    vertical-align: middle;
}
.conn-unlink:hover,
.conn-unlink:focus-visible {
    color: #fff;
    background: #ff4757;
    border-color: #ff4757;
    outline: none;
}
.conn-port-label { color: var(--text-primary); font-weight: 600; margin-right: 0.15rem; }
.conn-none { color: var(--text-muted); font-style: italic; }
.jump-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font-family: 'Rajdhani', sans-serif;
    font-weight: 600;
    font-size: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.jump-link:hover { color: var(--text-primary); }
.jump-link-missing { color: var(--text-muted); text-decoration: none; cursor: default; }
.wire-endpoints { font-size: 0.9rem; margin-bottom: 1rem; }

.btn-danger {
    width: 100%;
    padding: 0.5rem;
    background: rgba(255, 71, 87, 0.12);
    border: 1px solid var(--error);
    color: var(--error);
    border-radius: var(--radius-sm);
    font-family: 'Rajdhani', sans-serif;
    font-weight: 600;
    cursor: pointer;
}
.btn-danger:hover { background: var(--error); color: #fff; }

/* -------------------------------------------------------------------- modal */
.bmssim-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(5,5,10,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: var(--space-lg);
}
.bmssim-modal-backdrop[hidden] { display: none; }
.bmssim-modal {
    max-width: 640px;
    width: 100%;
    max-height: 82vh;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow-lg);
}
.bmssim-modal h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.bmssim-modal h4 { font-size: 0.9rem; color: var(--primary); margin: 1.1rem 0 0.4rem; }
.bmssim-modal p, .bmssim-modal li { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }
.bmssim-modal ul { padding-left: 1.2rem; margin-bottom: 0.5rem; }
.bmssim-modal-close {
    margin-top: 1.4rem;
    background: var(--gradient-primary);
    border: none;
    color: #05050a;
    font-weight: 700;
    padding: 0.55rem 1.2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 980px) {
    .bmssim-palette { width: 210px; flex-basis: 210px; }
    .bmssim-props { width: 250px; flex-basis: 250px; }
    .bmssim-toolbar .tbtn span.tbtn-label { display: none; }
}
