/**
 * logic2rtl - style.css
 * Engineering Dark & Light Theme matching rtl2schematic
 */

:root {
    --bg-main: #0b0f17;
    --bg-surface: #131b26;
    --bg-card: #1a2433;
    --bg-hover: #223044;
    --border-color: #26354a;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #00ff66;
    --accent-blue: #00bfff;
    --accent-cyan: #38bdf8;
    --danger: #ef4444;
    --warning: #f59e0b;
    --canvas-bg: #0d121a;
    --header-h: 40px;
    --toolbar-h: 42px;
    --sidebar-w: 240px;
    --inspector-w: 240px;
    --waveform-h: 240px;
    --status-h: 22px;
}

[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-card: #f1f5f9;
    --bg-hover: #e2e8f0;
    --border-color: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #059669;
    --accent-blue: #0284c7;
    --accent-cyan: #0284c7;
    --canvas-bg: #ffffff;
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    user-select: none;
}

/* App Layout Grid */
#app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* 1. Header Menu Bar */
header#app-header {
    height: var(--header-h);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    max-width: 100%;
    overflow: visible;
    position: relative;
    z-index: 1000;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    color: var(--accent);
    user-select: none;
}

.brand-icon {
    width: 22px;
    height: 22px;
    display: inline-block;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
}

.menu-bar {
    display: flex;
    gap: 4px;
}

.menu-item {
    position: relative;
}

.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
    user-select: none;
}

.menu-btn:hover {
    background: var(--bg-hover);
}

.menu-item.open > .menu-btn {
    background: var(--bg-hover);
    color: var(--accent-cyan);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.4);
    min-width: 200px;
    z-index: 1500;
    padding: 4px 0;
    user-select: none;
}

.menu-item.open > .dropdown-menu {
    display: block !important;
}

.dropdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    user-select: none;
}

.dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--accent-blue);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

.dropdown-submenu {
    position: relative;
}

.dropdown-submenu > .dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -4px;
    display: none;
    min-width: 130px;
    z-index: 1510;
}

.dropdown-submenu:hover > .dropdown-menu,
.dropdown-submenu.open > .dropdown-menu {
    display: block !important;
}

.dropdown-radio-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.dropdown-radio-item:hover {
    background: var(--bg-hover);
    color: var(--accent-cyan);
}

.dropdown-radio-item .radio-bullet {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 1px solid var(--text-muted);
    font-size: 8px;
}

.dropdown-radio-item.selected .radio-bullet {
    border-color: var(--accent-cyan);
    background: var(--accent-cyan);
    box-shadow: 0 0 4px var(--accent-cyan);
}

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

.icon-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.icon-btn:hover {
    background: var(--bg-hover);
}

/* 2. Main Toolbar */
#app-toolbar {
    height: var(--toolbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    gap: 10px;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-btn:hover {
    background: var(--bg-hover);
}

.tool-btn.active {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}

.tool-btn-primary {
    background: #1e3a5f;
    border-color: #2b5588;
    color: #60a5fa;
    font-weight: 600;
}

.tool-btn-primary:hover {
    background: #254877;
}

.tool-btn-accent {
    background: #064e3b;
    border-color: #059669;
    color: #34d399;
    font-weight: 600;
}

.tool-btn-accent:hover {
    background: #047857;
}

.tool-divider {
    width: 1px;
    height: 22px;
    background: var(--border-color);
    margin: 0 4px;
}

/* Breadcrumb Sheet Navigation */
#breadcrumb-container {
    display: flex;
    align-items: center;
    max-width: 35%;
    flex: 0 1 35%;
    overflow: hidden;
    gap: 4px;
    position: relative;
}

#breadcrumb-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
    scroll-behavior: smooth;
    flex: 1;
}

#breadcrumb-bar::-webkit-scrollbar {
    display: none;
}

.crumb {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
}

.crumb:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.crumb.active {
    color: var(--accent-cyan);
    font-weight: 600;
}

/* 3. Middle Content Area (Sidebar, Canvas, Inspector) */
#main-content {
    display: flex;
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Left Sidebar - Component Library */
#sidebar-left {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
}

#sidebar-left.collapsed {
    display: none !important;
}

/* Sidebar Splitter Handle (Logic.ly Style) */
.sidebar-splitter-handle {
    width: 14px;
    min-width: 14px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 15;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-splitter-handle:hover {
    background: var(--bg-hover);
    color: var(--accent-cyan);
}
.sidebar-splitter-handle span {
    font-size: 9px;
    font-weight: bold;
    color: var(--text-secondary);
}

.sidebar-title {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-category {
    border-bottom: 1px solid var(--border-color);
}

.category-header {
    padding: 9px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border-left: 3px solid transparent;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.category-header:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

.category-folder-icon {
    font-size: 13px;
    display: inline-block;
    line-height: 1;
}

.category-toggle-icon {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s ease, color 0.15s ease;
}

.sidebar-category:not(.collapsed) .category-header {
    color: var(--accent-cyan);
    background: var(--bg-card);
    border-left: 3px solid var(--accent-cyan);
}

.sidebar-category:not(.collapsed) .category-toggle-icon {
    color: var(--accent-cyan);
}

.sidebar-category.collapsed .component-list {
    display: none;
}

.sidebar-category:not(.collapsed) .component-list {
    display: flex;
    flex-direction: column;
    padding: 4px 0 6px 0;
    background: rgba(11, 15, 23, 0.4);
}

.empty-category-hint {
    padding: 8px 16px;
    font-size: 11px;
    font-style: italic;
    color: var(--text-muted);
    user-select: none;
}

.component-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: grab;
    border-radius: 4px;
    margin: 1px 6px;
}

.component-item:hover {
    background: var(--bg-hover);
    color: var(--accent-cyan);
}

.component-item.active {
    background: var(--bg-hover);
    color: var(--accent);
    font-weight: 600;
}

/* Canvas Viewport */
#canvas-container {
    flex: 1;
    position: relative;
    background: var(--canvas-bg);
    overflow: hidden;
}

#schematic-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* Right Sidebar - Properties Inspector */
#sidebar-right {
    width: var(--inspector-w);
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
}

.prop-row {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.prop-label {
    font-size: 11px;
    color: var(--text-muted);
}

.prop-input {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    outline: none;
}

.prop-input:focus {
    border-color: var(--accent-blue);
}

/* 4. Bottom Drawer - Waveform Viewer */
#waveform-drawer {
    height: var(--waveform-h, 240px);
    min-height: 200px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 20;
    transition: height 0.2s ease;
}

#waveform-drawer:not(.collapsed) {
    height: var(--waveform-h, 240px) !important;
    min-height: 200px !important;
    max-height: 60vh;
}

#waveform-drawer.collapsed {
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    flex-shrink: 0 !important;
}

#waveform-drawer.collapsed #waveform-header-tools,
#waveform-drawer.collapsed #waveform-canvas-container {
    display: none !important;
}

#waveform-header {
    height: 28px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
}

.waveform-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-cyan);
    display: flex;
    align-items: center;
    gap: 6px;
}

.waveform-collapse-indicator {
    display: inline-block;
    font-size: 9px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
    margin-left: 4px;
}

#waveform-drawer.collapsed .waveform-collapse-indicator {
    transform: rotate(0deg);
}

#waveform-drawer:not(.collapsed) .waveform-collapse-indicator {
    transform: rotate(180deg);
}

.waveform-tools-row {
    display: flex;
    gap: 6px;
    align-items: center;
    height: 100%;
}

.waveform-btn-group {
    display: inline-flex;
    gap: 2px;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 1px 3px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    height: 22px;
    box-sizing: border-box;
}

.waveform-tools-row .icon-btn {
    height: 22px !important;
    min-height: 22px !important;
    max-height: 22px !important;
    line-height: 20px !important;
    padding: 0 7px !important;
    font-size: 11px !important;
    white-space: nowrap !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 4px !important;
    border: 1px solid var(--border-color) !important;
    background: rgba(255, 255, 255, 0.05) !important;
    color: var(--text-main) !important;
    box-sizing: border-box !important;
    vertical-align: middle !important;
    cursor: pointer !important;
    transition: background 0.15s, border-color 0.15s;
}

.waveform-btn-group .icon-btn {
    border: none !important;
    background: transparent !important;
    padding: 0 5px !important;
    height: 18px !important;
    min-height: 18px !important;
    max-height: 18px !important;
    line-height: 18px !important;
}

.waveform-btn-group .icon-btn:hover {
    background: rgba(255, 255, 255, 0.15) !important;
}

.waveform-tools-row .icon-btn:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: var(--accent-cyan) !important;
}

#waveform-canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#waveform-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Full View Simulation Waveforms */
#app-container.full-waveform-view #main-content {
    display: none !important;
}

#app-container.full-waveform-view #waveform-drawer {
    flex: 1 1 auto !important;
    height: calc(100vh - var(--header-h) - var(--toolbar-h) - var(--status-h)) !important;
    max-height: none !important;
    min-height: 0 !important;
    transition: none !important;
}

#app-container.full-waveform-view #waveform-drawer.collapsed {
    height: 28px !important;
    flex: 0 0 28px !important;
}

/* Status Bar */
#status-bar {
    height: 22px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    font-size: 11px;
    color: var(--text-muted);
}

/* Modal Dialogs */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(3px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

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

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 90%;
    max-width: 550px;
    box-shadow: 0 16px 32px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-card,
.modal-body {
    user-select: text;
    -webkit-user-select: text;
}

/* Form Layouts & Strict Label/Input Baseline Alignment */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.form-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-grid-3col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

@media (max-width: 600px) {
    .form-grid-3col {
        grid-template-columns: 1fr;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.form-group label,
.form-label-aligned {
    min-height: 28px;
    display: flex;
    align-items: flex-end;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.25;
    margin-bottom: 5px;
    box-sizing: border-box;
}

.form-group > input,
.form-group > select,
.form-group > textarea {
    width: 100%;
    box-sizing: border-box;
}

.code-preview {
    background: #080c14;
    border: 1px solid var(--border-color);
    color: #a7f3d0;
    font-family: 'Fira Code', 'JetBrains Mono', Consolas, Monaco, monospace;
    font-size: 11.5px;
    line-height: 1.5;
    padding: 12px;
    border-radius: 6px;
    height: 260px;
    overflow: auto;
    white-space: pre;
    user-select: text !important;
    -webkit-user-select: text !important;
    cursor: text;
}

.code-preview::selection,
.code-preview *::selection {
    background: #2563eb !important;
    color: #ffffff !important;
}


/* Drag-and-Drop Enhancements */
.component-item {
    cursor: grab;
    user-select: none;
    -webkit-user-drag: element;
}

.component-item:active {
    cursor: grabbing;
}

.component-item.dragging {
    opacity: 0.45;
    background: var(--accent-blue);
    color: #ffffff;
}

#canvas-container.drag-over {
    outline: 2px dashed var(--accent-cyan);
    outline-offset: -4px;
}

/* Public Circuits Library Modal */
.modal-card-lg {
    max-width: 880px;
    width: 95%;
}

.circuit-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.circuit-search-bar input {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease;
}

.circuit-search-bar input:focus {
    border-color: var(--accent-cyan);
}

.public-circuits-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 4px;
}

.public-circuit-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.public-circuit-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-cyan);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-desc {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
    flex: 1;
    min-height: 32px;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: var(--text-muted);
}

.meta-tag {
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.card-actions .tool-btn,
.card-actions .icon-btn {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
}

/* Responsive Mobile & Touch Optimizations */
@media (max-width: 960px) {
    html, body {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
    }

    #app-container {
        min-width: 1024px;
        width: max-content;
        height: 100vh;
    }

    .menu-bar {
        display: flex !important;
    }

    #sidebar-left {
        width: 220px;
    }

    #sidebar-right {
        display: flex !important;
    }
}

/* History Actions in Header */
.history-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
}

.history-actions .icon-btn {
    padding: 3px 8px;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    border-radius: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.history-actions .icon-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

/* Custom Context Menu */
#canvas-context-menu,
#waveform-signal-context-menu {
    position: fixed;
    z-index: 1000;
    display: none;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    min-width: 180px;
    padding: 4px 0;
    user-select: none;
}

#canvas-context-menu.open,
#waveform-signal-context-menu.open {
    display: block;
}

.context-menu-item {
    padding: 7px 14px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.12s ease;
}

.context-menu-item:hover {
    background: var(--bg-hover);
    color: var(--accent-cyan);
}

.context-menu-item .shortcut {
    font-size: 10px;
    color: var(--text-muted);
}

.context-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Port Hover Tooltip */
#canvas-port-tooltip {
    position: fixed;
    z-index: 9000;
    pointer-events: none;
    background: rgba(19, 27, 38, 0.95);
    border: 1px solid var(--accent-cyan);
    border-radius: 6px;
    padding: 8px 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    max-width: 280px;
}

/* Tabbed Modals: Simulation Logging & Circuit Analysis */
.tab-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
}

.modal-tab-content {
    display: none;
    padding: 12px 0;
}

.modal-tab-content.active {
    display: block;
}

/* K-Map Grid Styles */
.kmap-table {
    border-collapse: collapse;
    margin: 10px auto;
    font-family: monospace;
    font-size: 13px;
    position: relative;
}

.kmap-table th, .kmap-table td {
    border: 1px solid var(--border-color);
    padding: 10px 18px;
    text-align: center;
    position: relative;
}

.kmap-table th {
    background: var(--bg-surface);
    color: var(--accent-cyan);
    font-weight: 700;
}

.kmap-cell {
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: bold;
    min-width: 44px;
    height: 38px;
}

.kmap-cell.target-active {
    color: var(--accent);
}

/* Truth Table Styles */
.analysis-truth-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    font-family: monospace;
}

.analysis-truth-table th, .analysis-truth-table td {
    border: 1px solid var(--border-color);
    padding: 5px 8px;
    text-align: center;
}

.analysis-truth-table th {
    background: var(--bg-surface);
    color: var(--text-secondary);
    position: sticky;
    top: 0;
}

.analysis-truth-table td.clickable-cell {
    cursor: pointer;
    user-select: none;
    font-weight: bold;
}

.analysis-truth-table td.clickable-cell:hover {
    background: var(--bg-hover);
    color: var(--accent-cyan);
}

/* ModelSim Runtime Options & Message Severity Styles */
.modelsim-tab-nav {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 14px;
    padding: 0 4px;
}

.modelsim-tab-btn {
    padding: 6px 14px;
    font-size: 12px;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px 4px 0 0;
}

.modelsim-tab-btn.active {
    background: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--accent-cyan);
    font-weight: 600;
}

.modelsim-group-box {
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px 14px 14px 14px;
    margin-bottom: 14px;
    background: var(--bg-surface);
}

.modelsim-group-legend {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 0 6px;
    margin-left: -4px;
}

.severity-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    font-family: monospace;
    text-transform: uppercase;
}

.severity-badge.note { background: rgba(49, 130, 206, 0.2); color: #63b3ed; border: 1px solid #3182ce; }
.severity-badge.warning { background: rgba(214, 158, 46, 0.2); color: #ecc94b; border: 1px solid #d69e2e; }
.severity-badge.error { background: rgba(229, 62, 62, 0.2); color: #fc8181; border: 1px solid #e53e3e; }
.severity-badge.failure, .severity-badge.fatal { background: rgba(155, 44, 44, 0.3); color: #feb2b2; border: 1px solid #9b2c2c; }

.modelsim-message-row {
    font-size: 11px;
    font-family: monospace;
    padding: 5px 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.modelsim-message-row:hover {
    background: var(--bg-hover);
}

/* Analysis Side Action Buttons strictly aligned */
.analysis-side-btn {
    width: 100%;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    box-sizing: border-box;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.analysis-side-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

.analysis-side-btn.primary {
    background: rgba(37, 99, 235, 0.2);
    border-color: var(--accent-blue);
    color: var(--accent-cyan);
}

.analysis-side-btn.primary:hover {
    background: rgba(37, 99, 235, 0.35);
}

/* K-Map Overlay and Group Visualization */
.kmap-container-relative {
    position: relative;
    display: inline-block;
    margin: 12px auto;
}

.kmap-table {
    border-collapse: separate;
    border-spacing: 0;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-card);
}

.kmap-table th {
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    text-align: center;
}

.kmap-table td.kmap-cell {
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
    text-align: center;
    vertical-align: middle;
    font-family: monospace;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0;
    position: relative;
}

.kmap-svg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.analysis-terms-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 12px;
}



