.cofactor-vis-wrapper {
    font-family: system-ui, sans-serif;
    max-width: 800px;
    margin: 0 auto 2rem auto;
    padding: 20px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid #e9ecef;
}

.cofactor-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
}

.cofactor-btn {
    padding: 8px 16px;
    font-size: 1em;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid #ccc;
    background: #fff;
    transition: all 0.2s;
}

.cofactor-btn.primary {
    background: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

.cofactor-btn.primary:hover {
    background: #0b5ed7;
}

.cofactor-btn:hover:not(.primary) {
    background: #f8f9fa;
}

.cofactor-btn.hidden {
    display: none;
}

.cofactor-status {
    text-align: center;
    font-weight: 500;
    color: #495057;
    padding: 10px;
    background: #e9ecef;
    border-radius: 6px;
    margin-bottom: 30px;
    min-height: 1.5em;
}

.matrix-layout {
    display: flex;
    justify-content: center;
    margin: 40px 0;
}

.matrix-wrapper {
    position: relative;
    padding: 5px 15px;
    border-left: 3px solid #212529;
    border-right: 3px solid #212529;
    border-radius: 12px;
}

.matrix-inner {
    position: relative;
    width: 200px;
    height: 200px;
}

.matrix-grid {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 10px;
    width: 100%;
    height: 100%;
}

.matrix-cell {
    position: relative;
    width: 100%;
    height: 100%;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    transition: all 0.3s;
}

.matrix-cell input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 1.4em;
    font-family: monospace;
    outline: none;
    color: #212529;
}

/* Hide number input spinners */
.matrix-cell input::-webkit-outer-spin-button,
.matrix-cell input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.matrix-cell input[type=number] {
    -moz-appearance: textfield;
}

.matrix-cell input:disabled {
    cursor: default;
}

.sign-ind {
    position: absolute;
    top: 3px;
    right: 6px;
    font-size: 0.85em;
    font-weight: bold;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sign-pos {
    color: #0d6efd;
}

.sign-neg {
    color: #dc3545;
}

.highlight-active {
    background: #fff3cd !important;
    border-color: #ffecb5 !important;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.4);
    z-index: 2;
}

.highlight-minor {
    background: #e2e3e5 !important;
    border-color: #adb5bd !important;
}

.svg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
}

.sel-btn {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #0d6efd;
    background: #fff;
    color: #0d6efd;
    font-weight: bold;
    font-size: 1.2em;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.sel-btn:hover {
    background: #0d6efd;
    color: white;
    transform: scale(1.1);
}

.formula-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
    min-height: 80px;
    font-family: monospace;
    font-size: 1.15em;
    color: #212529;
}

.formula-term {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.inline-matrix {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 10px;
    border-left: 2px solid #212529;
    border-right: 2px solid #212529;
    padding: 2px 6px;
    text-align: center;
    font-size: 0.9em;
    background: #f8f9fa;
}

.formula-final {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px dashed #ced4da;
    font-size: 1.2em;
    text-align: center;
    width: 100%;
}